PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2005/2008/2010/2012/2013

PDF Overlay - Stitching PDF Pages Together in .NET

“I have two pdf documents - one contains my company's letterhead template and the other has letters addressed to our customers. I would like to know how I can use the letterhead in each of those letters?”
By V. Subhash

This article is based on an older PDFOne Java article. The Java article has been the most popular article so far and I guessed .NET users would also be interested in a similar solution.

PDFOne .NET supports page overlays or page stitching where pages are placed side by side, one over another, or set against specified offsets.

PDFOne .NET uses the following overloaded methods of the PDFDocument class to perform PDF overlays.

public void Stitch( 
   int stitchToPageNo,
   int stitchFromPageNo
);

public void Stitch( 
   int stitchToPageNo,
   int stitchFromPageNo,
   float offsetX,
   float offsetY,
   PDFMeasurementUnit unit
);

The first method takes the content of the page specified by stitchFromPageNo and places it over the page specified by stitchToPageNo. The second method does the same but supports offsets from the top-left corner.

For an illustration, we will use the user requirement quoted above. Here is the document that contains the letterhead.

And, here is the document that contains the letters.

Here is the code that provides solution. As Stitch() method to lift the contents a page in the same document, the two documents are merged to form a single document. Next, the second page is lifted and placed on the first page.

using System;
using System.Collections.Generic;
using System.Text;
using Gnostice.PDFOne;

namespace PDF_Overlay {
 class Program  {
  static void Main(string[] args) {
   // Load the document containing the letterhead
   PDFDocument doc = new PDFDocument();
   doc.Load("LetterHead.pdf");
   // Copy page from the other document containing the letter
   doc.AppendPagesFrom("Letters.pdf", "1");
   // Save merged document to file
   doc.Save("MergedDoc.pdf");
   // Free I/O resources
   doc.Close();

   // Load the merged document
   doc.Load("MergedDoc.pdf");
   // Overlay page 2 on page 1
   doc.Stitch(1, 2);
   // Delete the unwanted page 2
   doc.DeletePages("2");
   // Save overlaid document to file
   doc.Save("OverlaidDoc.pdf");
   // Free I/O resources
   doc.Close();
  }
 }
}

Ta da!

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.