HTML to PDF converter for Java and .NET

HOME   FEATURES   PRODUCTS   DOWNLOADS   BUY NOW!   SUPPORT
<< back

PDF Overlay

 

PDF Overlay feature makes possible to combine content of two PDF documents.

Typical use cases: 

  • add a logo to all document pages
  • watermark document pages (and add a hyperlink to an origin site)
  • add headers / footers
  • underlay a background to all or selected document pages

Example:

// main document
PD4Document doc1 = new PD4Document(new URL("file:doc1.pdf"), null);

// a document to be used as an overlay
PD4Document doc2 = new PD4Document(new URL("file:doc2.pdf"), null);
			
// overlay request to place doc2 content over doc1 
// "1" limits to use only the first page of doc2 as an overlay content
// "2+" specifies to apply the overlay to the second and all subsequent pages
// "128" is opacity of overlay (doc2) content, which corresponds ~50%
doc1.overlay(doc2, "1", "2+", 128);

// writing the overlay result as a new PDF document 
FileOutputStream fos = new FileOutputStream("result.pdf");
doc1.write(fos);
There are PD4Document.overlay() and PD4Document.underlay() with similar signatures. The difference is that overlay() places doc2 content on the top of doc1, underlay() places doc2 under doc1 (can be seen as an adding of a page background).

The API methods allow to limit pages to be used for an overlay/underlay actions with scope parameters. 

Allowed scope syntax: "1" (only the first page), "3-5" (page range), "2+" (all pages except the first), "last", "even", "odd", "1+,skiplast", "5+,even", null (all pages).

An utility static boolean[] PD4Document.computeScope(String scope, int pageNum) method can be used to test your scope syntax. It returns an array of boolean flags correspond to document pages (true = match)

Allowed opacity range is 0-255. 0 = fully transparent, 255 = opaque. All negative values are interpretted as 255.

Copyright ©2004-24 zefer|org. All rights reserved. Bookmark and Share