Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFsharp - overlay page from other PDF

Tags:

c#

pdfsharp

I'm generating PDF files using PDFsharp, and I need to overlay the PDF I'm generating with a specific page from another PDF.

I've created this method:

    private void ApplyOverlay(XGraphics graph, string overlaypdfPath, int pageNumberInOverlay, XRect coordinates)
    {
        var xPdf = XPdfForm.FromFile(overlaypdfPath);

        if(xPdf.PageCount < pageNumberInOverlay)
            throw new Exception("not enough pages");

        //Here i need to take from xPdf just the page number -> pageNumberInOverlay 

        graph.DrawImage(xPdfPageN, coordinates);
    }

I don’t know how to select only a specific page.

like image 734
DeNasti Avatar asked Dec 07 '25 12:12

DeNasti


1 Answers

You can append the page number to the name of the PDF file, separated with a hash sign ("#").

To get page 7 of "sample.pdf", use the filename "sample.pdf#6" (zero-based page numbers).

like image 166
I liked the old Stack Overflow Avatar answered Dec 09 '25 00:12

I liked the old Stack Overflow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!