How do I create PDF/UA compatible PDFs in iTunes?

Asked 2 years ago, Updated 2 years ago, 135 views

The site created using iText 2.1.7 has several dynamically created PDFs.However, many users are rendering PDFs using screen readers such as JAWS because of their disabilities.The setTagged() method is used to tag PDFs, but some elements in PDFs are not ordered correctly.Some of them got even more messy after calling setTagged()!
When I read about PDF/UA, it seemed to help me solve the problem.However, I could not find a good sample code for how to create a PDF/UA document.Could you provide us with a sample code?

java pdf

2022-09-30 21:40

1 Answers

See the PdfUA sample code.Step by step describes what is required to comply with PDF/UA.In 2014, a similar sample code was presented from iTunes and JavaOne.See the iText Summit video tutorial.

public void manifoldPdf(String dest)throws IOException, XMPException{
 PdfDocument pdfDoc = new PdfDocument (new PdfWriter(dest, new WriterProperties().setPdfVersion(PdfVersion.PDF_1_7));
 Document document = new Document(pdfDoc, new PageSize(PageSize.A4).rotate());
 // TAGGED PDF
 // Make document tagged
 pdfDoc.setTagged();
 //===============
 // PDF/UA
 // Set document metadata

 pdfDoc.getCatalog().setViewerPreferences(newPdfViewerPreferences().setDisplayDocTitle(true));
 pdfDoc.getCatalog().setLang(new PdfString("en-US"));
 PdfDocumentInfo=pdfDoc.getDocumentInfo();
 info.setTitle("English pangram");
 //=====================

 Paragraph = new Paragraph();
 // PDF/UA
 // Embedded font
 PdfFontfont=PdfFontFactory.createFont(FONT, PdfEncodings.WINANSI, true);
 p.setFont(font);
 //==================
 Text c=new Text ("The quick brown");
 p.add(c);
 Image i = new Image (ImageDataFactory.create(FOX));
 // PDF/UA
 // Set alt text
 i.getAccessibilityProperties().setAlternateDescription("Fox");
 //==============
 p.add(i);
 p.add("jumps over the lazy");
 i=new Image(ImageDataFactory.create(DOG));
 *//PDF/UA
 // Set alt text
 i.getAccessibilityProperties().setAlternateDescription("Dog");
 //==================
 p.add(i);
 document.add(p);
 p=newParograph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n") .setFont(font).setFontSize(20);
 document.add(p);
 List list = new List();
 list.add((ListItem) new ListItem("quick").setFont(font).setFontSize(20));
 list.add((ListItem) new ListItem("brown").setFont(font).setFontSize(20));
 list.add((ListItem) new ListItem("fox").setFont(font).setFontSize(20));
 list.add((ListItem) new ListItem("jumps").setFont(font).setFontSize(20));
 list.add((ListItem) new ListItem("over").setFont(font).setFontSize(20));
 list.add(ListItem) new ListItem("the").setFont(font).setFontSize(20));
 list.add((ListItem) new ListItem("lazy").setFont(font).setFontSize(20));
 list.add(ListItem) new ListItem("dog").setFont(font).setFontSize(20));
 document.add(list);
 document.close();
}

setTagged documentation was used to create tagged documents, but that is not enough and document data must be set.The document title and the language used in the document must also be displayed.XMP metadata is required.

You must also include all fonts.If there is an image, an alternate text is required.The sample code replaces the words DOG and Fox with images.Use the getAccessibilityProperties().setAlternateDescription() method to "read" such images correctly.

Added a numbered list at the end of the sample code.The contributor said in another question that he could not read and speak the list using JAWS.Review the PDF file created with the sample code above, i.e., pdfua.pdf, and you'll find that JAWS can read the document in the order it was planned, along with the number and text.

The reason why it doesn't work is simple: it uses an earlier version of iText than the PDF/UA standard.Also, if your version uses the setTagged() method, you must create a tag structure at the lowest PDF level.The latest version of iTunes supports higher levels.If you want to do what you want, use the latest version of iTunes.


2022-09-30 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.