PDFOne (for Java™)
Create, edit, view, print & enhance PDF documents and forms on Java™ platform
J2SE J2EE Windows Linux Mac (OS X)

Creating Alternative PDF Content For Screen and Print

Use watermark annotations to create different content for viewing screen and printing on paper.
By V. Subhash and L. Santhanam

In a previous article, we saw how to create PDF content that will be rendered only when the document is printed. In this article, we will see how to create a PDF with content with different content in the same location but only of which is rendered when the document is printed or viewed on screen.

The objective is to provide alternate content for screen and print. One of the ways to achieve is this is by using PDF watermark annotations. Typically, watermark annotations are not printed. However, there is a PDF annotation flag that can be set to make them printable. There is another PDF annotation flags that makes them not viewable on the screen. Using these two annotations, we can achieve our objective. Here is our code example.

Example Code

import java.io.IOException;

import com.gnostice.pdfone.PDFOne;
import com.gnostice.pdfone.PdfAnnot;
import com.gnostice.pdfone.PdfAppearanceStream;
import com.gnostice.pdfone.PdfDocument;
import com.gnostice.pdfone.PdfException;
import com.gnostice.pdfone.PdfImage;
import com.gnostice.pdfone.PdfMeasurement;
import com.gnostice.pdfone.PdfPage;
import com.gnostice.pdfone.PdfPageSize;
import com.gnostice.pdfone.PdfRect;
import com.gnostice.pdfone.PdfWatermarkAnnot;

public class Print_With_Alternative_Print_Logo {    
  public static void main(String[] args) throws IOException, PdfException {
    // Create a new PDF document and add a blank new page to it
    PdfDocument doc = new PdfDocument();    
    PdfPage pg = new PdfPage(PdfPageSize.A4);
    // Create "print-only" watermark content
    // with black-and-white logo
    PdfAppearanceStream ap1 = 
         new PdfAppearanceStream(new PdfRect(0, 0, 345, 113));
                  new PdfRect(0,0, 308, 127));
    // Creates a watermark annotation
    PdfWatermarkAnnot waterAnnot1 = new PdfWatermarkAnnot();
    waterAnnot1.setRect(new PdfRect(0,0, 308, 127));
    // Set watermark to appear in the same location on the page
    // both when viewed and when printed
    // Set "print" appearance for the watermark
    // Make watermark print-only
    waterAnnot1.setFlags(PdfAnnot.FLAG_NO_VIEW | PdfAnnot.FLAG_PRINT);

    // Create "screen-only" watermark content
    // with color logo
    PdfAppearanceStream ap2 = 
         new PdfAppearanceStream(new PdfRect(0, 0, 308, 127));
                  new PdfRect(0,0, 308, 127));
    // Creates another watermark annotation (for the screen)
    // in the the same location 
    PdfWatermarkAnnot waterAnnot2 = new PdfWatermarkAnnot();
    waterAnnot2.setRect(new PdfRect(0,0, 308, 127));    
    // Set "screen" appearance for the watermark
    // Add watermarks to the page 
    // Save the PDF document to file
    // Clean up

Note: PDF watermark annotations use appearance streams. These are bounded areas of PDF content that are not assigned any page but can be added to any annotation or form field as required.


Image with the color logo
Image with the b/w logo
PDF with alternate print and screen content (Check the preview)


Our Free Online Document-Processing Tools
Gnostice Apps

Gnostice Apps provides several PDF document-processing services over the Web. It enables you to merge, split, convert, secure and redact PDF documents - all for FREE. All you need to access these services is a HTML5-capable browser such as the latest version of Firefox/Seamonkey or IE 11.

Our Developer Tools
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.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.


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

XtremeDocumentStudio .NET

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

PDFOne (for Java™)

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

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

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

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).