PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Combinde multiple pdf pages and add text at top left
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2051
Page 1 of 1

Author:  frnk01 [ Tue Jun 12, 2012 1:21 pm ]
Post subject:  Combinde multiple pdf pages and add text at top left

Hi,

I want to create a combined pdf of multiple single pdf files. After merging these single pdf files I want to add some text at the top of first pdf page like a heading.

How can I do this?

This is how I merge the files:

Code:
      Console.WriteLine("Merging started.....");
      PdfDocument outputPDFDocument = new PdfDocument();
      foreach (string pdfFile in pdfFiles)
      {
         PdfDocument inputPDFDocument = PdfReader.Open(pdfFile, PdfDocumentOpenMode.Import);
         outputPDFDocument.Version = inputPDFDocument.Version;
         
         foreach (PdfPage page in inputPDFDocument.Pages)
         {
            outputPDFDocument.AddPage(page);
         }
      }
      outputPDFDocument.Save(outputFilePath);
      Console.WriteLine("Merging Completed");

Author:  Thomas Hoevel [ Wed Jun 13, 2012 9:22 am ]
Post subject:  Re: Combinde multiple pdf pages and add text at top left

Hi!

I'm not sure about the best way, but I know two ways that will surely work:

  1. Do it like the PDFsharp sample Two Pages on One does (only modified to One Page on One)
  2. After saving the file (as you do now), you can open it for modification and add the text to the pages (see the Watermarks sample that comes with PDFsharp)

Method 2 keeps the pages as they are. With method 1 you have to pay attention to different page sizes in the source files - but you also have the chance to scale all pages to a single format (e.g. DIN A4) which could be more user-friendly than a file with several different page formats.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/