我正在尝试使用iText 5.5.2创建pdf / a 1a文档
我可以使用hello world创建一个简单的pdf / a,但是如果没有错误,我将无法在文档中添加图片:
com.itextpdf.text.pdf.PdfAConformanceException: Alt entry should specify alternate description for /Figure element.
下面是我的代码试用。我不知道如何为图像添加Alt入口图。我尝试了PdfDictionary,但是它不起作用。我不知道了。有人给我小费吗?
final float MARGIN_OF_ONE_CM = 28.8f;
final com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4
, MARGIN_OF_ONE_CM
, MARGIN_OF_ONE_CM
, MARGIN_OF_ONE_CM
, MARGIN_OF_ONE_CM);
ByteArrayOutputStream pdfAsStream = new ByteArrayOutputStream();
PdfAWriter writer = PdfAWriter.getInstance(document,
new FileOutputStream("D:\\tmp\\pdf\\test.pdf"), PdfAConformanceLevel.PDF_A_1A);
document.addAuthor("Author");
document.addSubject("Subject");
document.addLanguage("nl-nl");
document.addCreationDate();
document.addCreator("Creator");
document.addTitle("title");
writer.setPdfVersion(PdfName.VERSION);
writer.setTagged();
writer.createXmpMetadata();
document.open();
final String FONT = "./src/main/resources/fonts/arial.ttf";
Font font = FontFactory.getFont(FONT, BaseFont.CP1252, BaseFont.EMBEDDED);
final Paragraph element = new Paragraph("Hello World", font);
document.add(element);
final InputStream logo = this.getClass().getResourceAsStream("/logos/logo.jpg");
final byte[] bytes = IOUtils.toByteArray(logo);
Image logoImage = Image.getInstance(bytes);
document.add(logoImage);
final String colorProfile = "/color/sRGB Color Space Profile.icm";
final InputStream resourceAsStream = this.getClass().getResourceAsStream(colorProfile);
ICC_Profile icc = ICC_Profile.getInstance(resourceAsStream);
writer.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
document.close();
通常,您需要添加以下替代说明:
logoImage.setAccessibleAttribute(PdfName.ALT, new PdfString("Logo"));
这适用于PDF / A2-A和PDF / A3-A,但不适用于PDF / A1-A。我已经对此进行了测试,发现您发现了一个错误。该错误现已修复。该修复程序将在下一版本中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句