Dukakus17
Dukakus17

Reputation: 1249

How can we add an external PDF to the current page with PDFsharp?

I get the stream of a PDF file and I am trying to add this to my current PDF.

        byte[] pdfBytes = interview.Application.CandidateResumeFile.File.FileBinary.ToArray();
        Stream pdfstream = new MemoryStream(imgBytes);

This gives me the stream of the PDF file that I want to add to my page.

        PdfDocument doc = new PdfDocument();
        doc.Info.Title = "Test PDFSharp";
        PdfPage page = doc.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);

        ////////content

        const string filename = "test.pdf";
        doc.Save(filename);
        Process.Start(filename);

Here is how my page is set up, and the page loads fine. I just want to add the PDF file to the page.

Upvotes: 0

Views: 2542

Answers (1)

PDFsharp comes with several samples that solve this task in different ways.

See Concatenate Documents:
http://pdfsharp.net/wiki/ConcatenateDocuments-sample.ashx

See Combine Documents:
http://pdfsharp.net/wiki/CombineDocuments-sample.ashx

Basically there are two options: draw an existing page onto a new page, allowing you to resize and scale it. Or add the page to the new document, creating an exact copy.

Upvotes: 1

Related Questions