本文整理匯總了Java中com.itextpdf.text.pdf.PdfWriter.setPDFXConformance方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfWriter.setPDFXConformance方法的具體用法?Java PdfWriter.setPDFXConformance怎麽用?Java PdfWriter.setPDFXConformance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfWriter
的用法示例。
在下文中一共展示了PdfWriter.setPDFXConformance方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: tiff2Pdf
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public void tiff2Pdf(File singleTifFile, File pdfFile) {
// based on tiff2pdf from itext toolbox 0.0.2
// (cfr.http://itexttoolbox.sourceforge.net/doku.php?id=download&DokuWiki=
// ecde1bfec0b8cca87dd8c6c042183992)
try {
RandomAccessFileOrArray ra = new RandomAccessFileOrArray(
singleTifFile.getAbsolutePath());
// RandomAccessFileOrArray ra = new
// RandomAccessFileOrArray(tempByteArray);
int comps = TiffImage.getNumberOfPages(ra);
Document document = new Document(PageSize.A4);
float width = PageSize.A4.getWidth();
float height = PageSize.A4.getHeight();
Image img = TiffImage.getTiffImage(ra, 1);
document.setPageSize(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream(pdfFile));
// pdf/a
// from
// http://www.opensubscriber.com/message/[email protected]
// .net/7593470.html
// check that it is really pdf/a:
// http://www.intarsys.de/produkte/pdf-a-live/pdf-a-check-1
// => 2 warnings
// Keine eindeutige ID gefunden
// Kein History-Eintrag vorhanden
writer.setPDFXConformance(PdfWriter.PDFA1B);
document.open();
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(Thread.currentThread()
.getContextClassLoader().getResourceAsStream(
"/srgb.profile"));
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));
PdfContentByte cb = writer.getDirectContent();
for (int c = 0; c < comps; ++c) {
img = TiffImage.getTiffImage(ra, c + 1);
if (img != null) {
document.setPageSize(PageSize.A4);
document.newPage();
img.setAbsolutePosition(0, 0);
img.scaleToFit(width, height);
cb.addImage(img);
logger.debug("Finished page " + (c + 1));
}
}
ra.close();
writer.createXmpMetadata();// pdfa
document.close();
} catch (Throwable e) {
// catch Throwable because we encountere a java.lang.InternalError
// cfr. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6503430
// probably better to move to later java version for poller
logger.error("Pdf not created", e);
}
}