List of usage examples for com.itextpdf.text.pdf PdfWriter setPDFXConformance
public void setPDFXConformance(final int pdfx)
From source file:com.github.ossdevs.jhocr.converter.HocrToPdf.java
License:Open Source License
/** * @param pdfXConformance determines into which format the PDF-X will be converted. * @return true if the conversion was successful. *//*from w w w . ja v a2s .c om*/ private boolean convertToPDFX(int pdfXConformance) { boolean result = false; Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, getOutputStream()); writer.setPDFXConformance(pdfXConformance); document.open(); document.addHeader(KEY_JHOCR_INFO, KEY_JHOCR_INFO_VALUE); document.setMargins(0, 0, 0, 0); /** * TODO add documentation */ for (HocrDocumentItem item : getItems()) { HocrParser parser = new HocrParser(item.getHocrInputStream()); HocrDocument hocrDocument = parser.parse(); /** * TODO add documentation * TODO add multipage image support */ if (hocrDocument.getPages().size() > 1) { throw new UnsupportedOperationException( "Multipage tif are not yet implemented, please report: http://code.google.com/p/jhocr/issues/list"); } /** * TODO add documentation */ for (HocrPage hocrPage : hocrDocument.getPages()) { HocrPageProcessor pageProcessor = new HocrPageProcessor(hocrPage, item.getImageInputStream(), isUseImageDpi()); if (pageProcessor.isInitialized()) { pageProcessor.process(document, writer); } } } if (!outlines.isEmpty()) { writer.setOutlines(outlines); } /** * Closing the document body stream. */ document.close(); getOutputStream().close(); result = true; } catch (UnsupportedOperationException e) { document.close(); logger.error("This operation is not yet implemented.", e); result = false; } catch (DocumentException e) { document.close(); logger.error("exception while genrating the PDF.", e); result = false; } catch (IOException e) { document.close(); logger.error("FileSystem I/O Exception, please check the log and file system persmissions.", e); result = false; } return result; }
From source file:com.vectorprint.report.itext.style.stylers.DocumentSettings.java
License:Open Source License
/** * called as the last step from {@link #style(java.lang.Object, java.lang.Object) }, calls {@link #builtInFontHack() * } which is necessary when creating PDF/X-1a with iText. * * @param writer/*from w w w . j ava 2s . c o m*/ * @throws IOException * @throws DocumentException * @throws VectorPrintException */ protected void pdfA1A(PdfWriter writer) throws IOException, DocumentException, VectorPrintException { builtInFontHack(); writer.setPdfVersion(PdfWriter.PDF_VERSION_1_4); writer.setTagged(); writer.setPDFXConformance(PdfWriter.PDFX1A2001); }