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 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 .NET Developer Tools
Gnostice Document Studio .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 Delphi/C++Builder developer tools
Gnostice Document Studio 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
Gnostice Document Studio 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

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

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