Example usage for com.lowagie.text.pdf PdfName OUTPUTINTENTS

List of usage examples for com.lowagie.text.pdf PdfName OUTPUTINTENTS

Introduction

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

Prototype

PdfName OUTPUTINTENTS

To view the source code for com.lowagie.text.pdf PdfName OUTPUTINTENTS.

Click Source Link

Document

A name

Usage

From source file:com.dlya.facturews.DlyaPdfExporter2.java

License:Open Source License

/**
 *
 *//*from w w w .j  a  v a  2  s  . c om*/
protected void exportReportToStream(OutputStream os) throws JRException {
    //ByteArrayOutputStream baos = new ByteArrayOutputStream();

    document = new Document(new Rectangle(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()));

    imageTesterDocument = new Document(new Rectangle(10, //jasperPrint.getPageWidth(),
            10 //jasperPrint.getPageHeight()
    ));

    boolean closeDocuments = true;
    try {
        pdfWriter = PdfWriter.getInstance(document, os);
        pdfWriter.setCloseStream(false);

        if (pdfVersion != null) {
            pdfWriter.setPdfVersion(pdfVersion.charValue());
        }
        if (isCompressed) {
            pdfWriter.setFullCompression();
        }
        if (isEncrypted) {
            pdfWriter.setEncryption(is128BitKey, userPassword, ownerPassword, permissions);
        }

        if (printScaling != null) {
            if (JRPdfExporterParameter.PRINT_SCALING_DEFAULT.equals(printScaling)) {
                //pdfWriter.addViewerPreference(PdfName.PRINTSCALING, PdfName.APPDEFAULT);
            } else if (JRPdfExporterParameter.PRINT_SCALING_NONE.equals(printScaling)) {
                //pdfWriter.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
            }
        }

        // Add meta-data parameters to generated PDF document
        // mtclough@users.sourceforge.net 2005-12-05
        String title = (String) parameters.get(JRPdfExporterParameter.METADATA_TITLE);
        if (title != null) {
            document.addTitle(title);
        }
        String author = (String) parameters.get(JRPdfExporterParameter.METADATA_AUTHOR);
        if (author != null) {
            document.addAuthor(author);
        }
        String subject = (String) parameters.get(JRPdfExporterParameter.METADATA_SUBJECT);
        if (subject != null) {
            document.addSubject(subject);
        }
        String keywords = (String) parameters.get(JRPdfExporterParameter.METADATA_KEYWORDS);
        if (keywords != null) {
            document.addKeywords(keywords);
        }
        String creator = (String) parameters.get(JRPdfExporterParameter.METADATA_CREATOR);
        if (creator != null) {
            document.addCreator(creator);
        } else {
            document.addCreator("JasperReports (" + jasperPrint.getName() + ")");
        }

        // BEGIN: PDF/A support
        String pdfaConformance = getStringParameter(JRPdfExporterParameter.PDFA_CONFORMANCE,
                JRPdfExporterParameter.PROPERTY_PDFA_CONFORMANCE);
        boolean gotPdfa = false;
        if (pdfaConformance != null
                && !JRPdfExporterParameter.PDFA_CONFORMANCE_NONE.equalsIgnoreCase(pdfaConformance)) {
            if (JRPdfExporterParameter.PDFA_CONFORMANCE_1A.equalsIgnoreCase(pdfaConformance)) {
                //pdfWriter.setPDFXConformance(PdfWriter.PDFA1A);
                gotPdfa = true;
            } else if (JRPdfExporterParameter.PDFA_CONFORMANCE_1B.equalsIgnoreCase(pdfaConformance)) {
                //pdfWriter.setPDFXConformance(PdfWriter.PDFA1B);
                gotPdfa = true;
            }
        }

        if (gotPdfa) {

            //pdfWriter.createXmpMetadata();
        } else {
            //pdfWriter.setRgbTransparencyBlending(true);
        }
        // END: PDF/A support

        document.open();

        // BEGIN: PDF/A support
        if (gotPdfa) {
            String iccProfilePath = getStringParameter(JRPdfExporterParameter.PDFA_ICC_PROFILE_PATH,
                    JRPdfExporterParameter.PROPERTY_PDFA_ICC_PROFILE_PATH);
            if (iccProfilePath != null) {
                PdfDictionary pdfDictionary = new PdfDictionary(PdfName.OUTPUTINTENT);
                pdfDictionary.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
                pdfDictionary.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
                //pdfDictionary.put(PdfName.S, PdfName.GTS_PDFA1);

                InputStream iccIs = RepositoryUtil.getInstance(jasperReportsContext)
                        .getInputStreamFromLocation(iccProfilePath);
                //PdfICCBased pdfICCBased = new PdfICCBased(ICC_Profile.getInstance(iccIs));
                //pdfICCBased.remove(PdfName.ALTERNATE);
                //pdfDictionary.put(PdfName.DESTOUTPUTPROFILE, pdfWriter.addToBody(pdfICCBased).getIndirectReference());

                pdfWriter.getExtraCatalog().put(PdfName.OUTPUTINTENTS, new PdfArray(pdfDictionary));
            } else {
                throw new JRPdfaIccProfileNotFoundException();
            }
        }
        // END: PDF/A support

        if (pdfJavaScript != null) {
            pdfWriter.addJavaScript(pdfJavaScript);
        }

        pdfContentByte = pdfWriter.getDirectContent();

        //tagHelper.init(pdfContentByte);

        initBookmarks();

        PdfWriter imageTesterPdfWriter = PdfWriter.getInstance(imageTesterDocument, new NullOutputStream() // discard the output
        );
        imageTesterDocument.open();
        imageTesterDocument.newPage();
        imageTesterPdfContentByte = imageTesterPdfWriter.getDirectContent();
        imageTesterPdfContentByte.setLiteral("\n");

        for (reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++) {
            setJasperPrint(jasperPrintList.get(reportIndex));
            loadedImagesMap = new HashMap<Renderable, com.lowagie.text.Image>();

            setPageSize(null);

            BorderOffset.setLegacy(JRPropertiesUtil.getInstance(jasperReportsContext)
                    .getBooleanProperty(jasperPrint, BorderOffset.PROPERTY_LEGACY_BORDER_OFFSET, false));

            boolean sizePageToContent = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
                    jasperPrint, JRPdfExporterParameter.PROPERTY_SIZE_PAGE_TO_CONTENT, false);

            List<JRPrintPage> pages = jasperPrint.getPages();
            if (pages != null && pages.size() > 0) {
                if (isModeBatch) {
                    document.newPage();

                    if (isCreatingBatchModeBookmarks) {
                        //add a new level to our outline for this report
                        addBookmark(0, jasperPrint.getName(), 0, 0);
                    }

                    startPageIndex = 0;
                    endPageIndex = pages.size() - 1;
                }

                for (int pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++) {
                    if (Thread.interrupted()) {
                        throw new JRException("Current thread interrupted.");
                    }

                    JRPrintPage page = pages.get(pageIndex);

                    if (sizePageToContent) {
                        setPageSize(page);
                    }

                    document.newPage();

                    pdfContentByte = pdfWriter.getDirectContent();

                    pdfContentByte.setLineCap(2);//PdfContentByte.LINE_CAP_PROJECTING_SQUARE since iText 1.02b

                    writePageAnchor(pageIndex);

                    /*   */
                    exportPage(page);
                }
            } else {
                document.newPage();
                pdfContentByte = pdfWriter.getDirectContent();
                pdfContentByte.setLiteral("\n");
            }
        }

        closeDocuments = false;
        document.close();
        imageTesterDocument.close();
    } catch (DocumentException e) {
        throw new JRException("PDF Document error : " + jasperPrint.getName(), e);
    } catch (IOException e) {
        throw new JRException("Error generating PDF report : " + jasperPrint.getName(), e);
    } finally {
        if (closeDocuments) //only on exception
        {
            try {
                document.close();
            } catch (Exception e) {
                // ignore, let the original exception propagate
            }

            try {
                imageTesterDocument.close();
            } catch (Exception e) {
                // ignore, let the original exception propagate
            }
        }
    }

    //return os.toByteArray();
}

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

License:Apache License

/**
 * Creates the pdf writer.//  ww w.  j  av a2 s .  c  o  m
 * 
 * @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;
}

From source file:net.sf.sze.service.impl.converter.PdfConverterImpl.java

License:GNU General Public License

/**
 * Put PDF-A-Infos to the document.//from w  ww  .  j  a  v  a 2  s  . co  m
 * @param writer the pdf-writer.
 * @throws IOException IOException.
 */
private void addPdfAInfosToDictonary(PdfWriter writer) throws IOException {
    PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
    outi.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
    outi.put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
    outi.put(PdfName.S, PdfName.GTS_PDFA1);

    ICC_Profile icc = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
    PdfICCBased ib = new PdfICCBased(icc);
    ib.remove(PdfName.ALTERNATE);
    outi.put(PdfName.DESTOUTPUTPROFILE, writer.addToBody(ib).getIndirectReference());
    writer.getExtraCatalog().put(PdfName.OUTPUTINTENTS, new PdfArray(outi));
}