Example usage for com.lowagie.text.pdf PdfBoolean PdfBoolean

List of usage examples for com.lowagie.text.pdf PdfBoolean PdfBoolean

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfBoolean PdfBoolean.

Prototype


public PdfBoolean(String value) throws BadPdfFormatException 

Source Link

Document

Constructs a PdfBoolean-object.

Usage

From source file:de.unigoettingen.sub.commons.contentlib.pdflib.PDFManager.java

License:Apache License

/**
 * Creates the pdf writer./*from   w  w  w .j  a  va  2  s. com*/
 * 
 * @param out the out
 * @param writer the writer
 * @param pdfdoc the pdfdoc
 * 
 * @return the pdf writer
 * 
 * @throws PDFManagerException the PDF manager exception
 */
private PdfWriter createPDFWriter(OutputStream out, Document pdfdoc) throws PDFManagerException {
    PdfWriter writer = null;
    try {
        // open the pdfwriter using the outstream
        writer = PdfWriter.getInstance(pdfdoc, out);
        LOGGER.debug("PDFWriter intstantiated");

        // register Fonts
        int numoffonts = FontFactory.registerDirectories();

        LOGGER.debug(numoffonts + " fonts found and registered!");

        if ((pdfa) && (iccprofile != null)) {
            // we want to write PDFA, we have to set the PDFX conformance
            // before we open the writer
            writer.setPDFXConformance(PdfWriter.PDFA1B);
        }

        // open the pdf document to add pages and other content
        try {
            pdfdoc.open();
            LOGGER.debug("PDFDocument opened");
        } catch (Exception e) {
            throw new PDFManagerException("PdfWriter was opened, but the pdf document couldn't be opened", e);
        }

        if ((pdfa) && (iccprofile != null)) {

            // set the required PDFDictionary which
            // contains the appropriate ICC profile
            PdfDictionary pdfdict_out = new PdfDictionary(PdfName.OUTPUTINTENT);

            // set identifier for ICC profile
            pdfdict_out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGBIEC61966-2.1"));
            pdfdict_out.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
            pdfdict_out.put(PdfName.S, PdfName.GTS_PDFA1);

            // PdfICCBased ib = new PdfICCBased(iccprofile);
            // writer.setOutputIntents("Custom", "PDF/A sRGB", null, "PDF/A
            // sRGB ICC Profile, sRGB_IEC61966-2-1_withBPC.icc",
            // colorProfileData);

            // read icc profile
            // ICC_Profile icc = ICC_Profile.getInstance(new
            // FileInputStream("c:\\srgb.profile"));
            PdfICCBased ib = new PdfICCBased(iccprofile);
            ib.remove(PdfName.ALTERNATE);

            PdfIndirectObject pio = writer.addToBody(ib);
            pdfdict_out.put(PdfName.DESTOUTPUTPROFILE, pio.getIndirectReference());
            writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS, new PdfArray(pdfdict_out));

            // create MarkInfo elements
            // not sure this is necessary; maybe just needed for tagged PDFs
            // (PDF/A 1a)
            PdfDictionary markInfo = new PdfDictionary(PdfName.MARKINFO);
            markInfo.put(PdfName.MARKED, new PdfBoolean("false"));
            writer.getExtraCatalog().put(PdfName.MARKINFO, markInfo);

            // write XMP
            this.writeXMPMetadata(writer);
        }
    } catch (Exception e) {
        LOGGER.error("Can't open the PdfWriter object\n" + e.toString() + "\n" + e.getMessage());
        throw new PDFManagerException("Can't open the PdfWriter object", e);
    }
    return writer;
}