3
votes

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.

1

1 Answers

3
votes

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).