PDFOne (for Java)
Create, edit, view, print & enhance PDF documents and forms in Java SE/EE
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 Cloud-based document-processing
Gnostice StarDocs

Gnostice StarDocs is a scalable, fault-tolerant document-processing server solution, designed to be the central go-to place for all kinds of electronic document-processing work. StarDocs includes a web application (as seen at stardocs.gnostice.com) that frees your end-users from the need to have format-specific software to merge, split, redact, convert, edit, and sign documents - all they need is a network connection and a HTML5 browser. StarDocs provides a REST-based API that your developers can use to add document-processing functions to a variety of software applications. As the REST API is platform agnostic, your developers can write software on a wide variety of platforms - from desktop to mobile devices to Web services in any development language. To get them started quickly, StarDocs is supported by language-specific native SDK. StarDocs document server has load-balancing built-in and is designed to be scalable across enterprise Intranets and the Internet. StarDocs is available as packaged software for on-premise hosting and also as a subscription-based cloud service.

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 .NET Developer Tools
XtremeDocumentStudio .NET

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


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

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.

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