PDFlib Cookbook

cookbook

color/reverse_printing new

'Reverse printing' is the process of printing text or graphical elements by applying ink to the surrounding area and keeping the text unprinted.

Download Java Code  Switch to PHP Code  Show Output 

/*
 * Reverse printing
 *
 * "Reverse printing" is the process of printing text or graphical elements by 
 * applying ink to the surrounding area and keeping the text unprinted. When 
 * printing on paper the unmarked area remains in paper color, i.e. usually 
 * white. In flexographic printing (used for package printing on substrates 
 * other than paper) it may be required to apply an additional die color, e.g. 
 * when printing on translucent substrate.
 * The code in this topic draws a solid rectangle with 100% spot color and then 
 * places text with 0% spot color.
 * 
 * Required software: PDFlib/PDFlib+PDI/PPS 9
 * Required data: none
 *
 */
package com.pdflib.cookbook.pdflib.color;

import com.pdflib.pdflib;
import com.pdflib.PDFlibException;

public class reverse_printing {
    public static void main (String argv[])
    {
        /* This is where the data files are. Adjust as necessary. */
        String searchpath = "../input";
        String outfile = "reverse_printing.pdf";
        String title = "Reverse printing";

        pdflib p = null;
        int exitcode = 0;

        try {
            p = new pdflib();

            p.set_option("searchpath={" + searchpath + "}");

            /* This means we must check return values of load_font() etc. */
            p.set_option("errorpolicy=return");

            if (p.begin_document(outfile, "") == -1)
                throw new Exception("Error: " + p.get_errmsg());

            p.set_info("Creator", "PDFlib Cookbook");
            p.set_info("Title", title);
            
            /* Start the page */
            p.begin_page_ext(0, 0, "width=a4.height height=a4.width");

            /* Draw a background rectangle and fill it with 100% "PANTONE 463 C". */

            p.set_graphics_option("fillcolor={spotname {PANTONE 463 C} 1}");

            p.rect(0, 0, 842, 595);
            p.fill();

            /* Draw text with the same spot color, but a tint value of 0. Nothing 
             * will be painted because no ink is applied. Due to the colorized 
             * background area the text will be visible nevertheless.
             */
            
            p.fit_textline("Reverse Printing", 50, 50, 
                "fontname=NotoSerif-Bold encoding=unicode fontsize=40 " +
                "boxsize={742 495} fitmethod=meet position=center " +
                "fillcolor={spotname {PANTONE 463 C} 0}");
            
            p.end_page_ext("");

            p.end_document("");

        } catch (PDFlibException e) {
            System.err.println("PDFlib exception occurred:");
            System.err.println("[" + e.get_errnum() + "] " + e.get_apiname() +
                ": " + e.get_errmsg());
            exitcode = 1;
        } catch (Exception e) {
            System.err.println(e);
            exitcode = 1;
        } finally {
            if (p != null) {
                p.delete();
            }
            System.exit(exitcode);
        }
    }
        
}