PDFsharp - 来自其他 PDF 的叠加页面

PDFsharp - overlay page from other PDF

我正在使用 PDFsharp 生成 PDF 文件,我需要用另一个 PDF 的特定页面覆盖我正在生成的 PDF。

我创建了这个方法:

    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);
    }

我不知道如何 select 只显示特定页面。

您可以将页码附加到 PDF 文件的名称,用井号(“#”)分隔。

要获取 "sample.pdf" 的第 7 页,请使用文件名 "sample.pdf#6"(从零开始的页码)。