title: PdfSharp, combine several pdf pages and put text on top of combined pdf
body: <p>I want to combine several single pdf pages to one pdf, and at the same time put a number on the top of the FIRST page. Somekind of a watermark, but aligned top, left.</p>
  
  <p>Anyone know how this can be solved?</p>
  
  <p>Right now I got the following code to merge the files:</p>
  
  <pre><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");
              addOverlay(outputPDFDocument);
  </code></pre>
  
  <p>EDIT:
  I made it work by opening the combined document after the save, and then adding text.</p>
  
  <pre><code>    public static void addOverlay(PdfDocument combined_pdf)
  {
      PdfDocument document = combined_pdf;
  
      // Select the first page
      PdfPage page = document.Pages[0];
  
      page.Orientation = PageOrientation.Portrait;
  
      XGraphics gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards);
  
      // Write on top of background with known colors
      gfx.DrawString("TEXT ON PDF PAGE", new XFont("Helvetica", 12, XFontStyle.Regular), XBrushes.White, 10, 0, XStringFormats.TopLeft);
  
      // Save the new modified document...
      document.Save("final_path");
  }
  </code></pre>