Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java iText创建带有图像的PDF/A1a_Java_Itext_Pdfa - Fatal编程技术网

Java iText创建带有图像的PDF/A1a

Java iText创建带有图像的PDF/A1a,java,itext,pdfa,Java,Itext,Pdfa,我正在尝试使用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,但它不

我正在尝试使用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。我已经对此进行了测试,我发现您发现了一个bug。此错误现已修复。该修复程序将在下一个版本中发布。

谢谢,尽管在添加accessibleAttribute后我收到了相同的错误。Image logoImage=Image.getInstance(字节);logoImage.setAccessibleAttribute(PdfName.ALT,新的PdfString(“Logo”));文件。添加(logo图像);出于某种原因,我的建议适用于PDF/A-2A合规性,但不适用于PDF/A-1A合规性。这很奇怪。正在进行进一步调查。您发现了一个bug。此错误现已修复。当您使用iText 5.5.2时,假定您是付费客户。请联系您的销售客户经理以获得iText的固定版本。好的,如果bug得到修复,Bruno看起来是个好消息。期待固定版本!顺便说一句:修复此问题的版本是昨天发布的!