Create a PDF/A2-a

@Davide_C

You can save directly as tagged PDF once you are done with adding the content in it. You do not need to save and then re-open to carry out the conversion.

Have you checked below documentation article(s) for the code samples? They contain guidelines on how to create a tagged PDF document from the scratch:

Hi, I have this code, very simple:


Calendar now = Calendar.getInstance();
now.setTimeZone(TimeZone.getTimeZone(“UTC”));

document = new com.aspose.pdf.Document();

document.getInfo().setTitle(“title”);
document.getInfo().setAuthor(“author”);
document.getInfo().setSubject(“subject”);
document.getInfo().setKeywords(“keywords”);
document.getInfo().setCreator(“creator”);
document.getInfo().setCreationDate(now.getTime());
document.getInfo().setModDate(now.getTime());
document.setDisplayDocTitle(true);

document.getTaggedContent().setTitle(“Documento PDF Esempio”);
document.getTaggedContent().setLanguage(“it-IT”);

Page page = document.getPages().add();

String text = “TESTO”;

TextFragment textFragment = new TextFragment(text);
com.aspose.pdf.Font font = FontRepository.findFont(“Arial”);
textFragment.setText(text);

page.getParagraphs().add(textFragment);

document.validate(“c:\butta\logtaggedpdf.xml”, PdfFormat.PDF_UA_1);

document.convert(“c:\butta\taggedpdf.xml”, PdfFormat.PDF_UA_1, ConvertErrorAction.Delete);

document.save(os);


can’t convert it to PDF_UA_1

this is the list of errors:

	<General>
		<Problem Severity="Error" Clause="7.1" ObjectID="" Page="1" Convertable="False" Code="7.1:1.1(14.8)">Text object not tagged</Problem>
		<Problem Severity="Need manual check" Clause="7.1" ObjectID="" Page="" Convertable="False" Code="7.1:5">Color contrast</Problem>
	</General>
	<Text>
		<Problem Severity="Need manual check" Clause="7.2" ObjectID="" Page="" Convertable="False" Code="7.2:1">Logical Reading Order</Problem>
	</Text>
	<Fonts>
		<Problem Severity="Warning" Clause="7.21.4.2" ObjectID="16" Page="1" Convertable="True" Code="7.21.4.2">CIDSet is missing or incomplete for font '16'</Problem>
	</Fonts>

how do I solve “Text object not tagged” ?

@Davide_C

Please apply following changes in the code snippet and see if it helps:

page.getParagraphs().add(textFragment);
document.processParagraphs();
document.convert(“c:\butta\taggedpdf.xml”, PdfFormat.PDF_UA_1, ConvertErrorAction.Delete);
document.save(os);

The above code should help you obtaining the tagged PDF as output. In case issue still persists, please share the generated output with us from your system along with the log file i.e. taggedpdf.xml. We will generate an investigation ticket in our issue tracking system and share the ID with you.

Hi, I applied the changes but it still does not generate the tagged pdf as I expected.
I attach the pdf file and the log xml

test2.pdf (84,5 KB)

taggedpdf.7z (816 Byte)

I await news on the resolution. Thanks.

@Davide_C

We are checking it and will get back to you shortly.

@Davide_C

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45040

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi, I don’t understand such a simple example needs a ticket in production. But has this procedure to create tagged PDFs ever been tested? Excuse me, but have you done the same test on your PC to see if it works? How many developers use this library that is also paid and no one has ever had this problem?

@Davide_C

The creation of tagged PDF from scratch is a functionality that is being worked on currently and we are fixing issues related to this feature in the API. The code sample that you are using is also tested in our environment and we also noticed that the output PDF was not tagged.

On the other hand, the documentation related to this feature is sadly not enhanced and we have been planning on updating the code sample in the official documentation of the API as well.

The ticket has been logged to investigate this behavior of the API internally and determine correct approach to achieve your requirements. We do understand your concerns and value them at the same time. These concerns have been recorded to escalate the ticket internally and as soon as we have some findings and resolve the ticket, we will share with you. We apologize for the inconvenience caused.

Hello,
I would like to point out that Accessibility in PDF production is becoming a very important issue for all public sector institutions as the European Accessibility Act comes into force in Europe in June 2025.
The European Accessibility Act will come into effect on 28 June 2025, and will mark a significant shift in the EU market. Failing to comply with the law could result in penalties including fines for European public-sector organisations.

Is Aspose ready to support us in this challenge?

@fabio.parise

Sure and yes, we have been working on it and we began this implementation since it was speculated to become a standard. The implementation and improvements to the feature is an on-going process that we tend to continue alongside fixing other reported issues in parallel.

Nevertheless, the ticket has been updated and loaded with all of the concerns your shared with us already. We will consider them for sure and as soon as we have some updates to share, we will inform you in this very thread. Please spare us some time.

We apologize for the inconvenience caused.

@Davide_C

The issue with autogenerated tags can be fixed with the feature added in the last release.

We added option in the class PdfFormatConversionOptions.setAutoTaggingSettings.

Here the code :

Calendar now = Calendar.getInstance();
now.setTimeZone(TimeZone.getTimeZone("UTC"));

Document document = new com.aspose.pdf.Document();

document.getInfo().setTitle("title");
document.getInfo().setAuthor("author");
document.getInfo().setSubject("subject");
document.getInfo().setKeywords("keywords");
document.getInfo().setCreator("creator");
document.getInfo().setCreationDate(now.getTime());
document.getInfo().setModDate(now.getTime());
document.setDisplayDocTitle(true);

document.getTaggedContent().setTitle("Documento PDF Esempio");
document.getTaggedContent().setLanguage("it-IT");

Page page = document.getPages().add();

String text = "TESTO";

TextFragment textFragment = new TextFragment(text);
com.aspose.pdf.Font font = FontRepository.findFont("Arial");
textFragment.setText(text);

page.getParagraphs().add(textFragment);
document.processParagraphs();

PdfFormat format = PdfFormat.PDF_UA_1;
PdfFormatConversionOptions options = new PdfFormatConversionOptions(
                dataDir+"taggedpdf"+version+".xml",format, ConvertErrorAction.Delete);
options.setAutoTaggingSettings(AutoTaggingSettings.getDefault());
document.convert(options);

document.save(dataDir+"outputAsposePDF"+version+"_tagged_PDF_UA_1.pdf");

45040.zip (87.2 KB)

Hi, now with the new version 25.5 the tagging of the simple example above works. Thanks.
On more complex files however, it is not possible to have the tagging, during the convert phase I have an error without a message, this is the stacktrace:

{“declaringClass”:“com.aspose.pdf.internal.l9h.lI”,“methodName”:“lI”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9h.ld”,“methodName”:“\u003cinit\u003e”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9h.lv”,“methodName”:“lj”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9k.l1t”,“methodName”:“le”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9k.l1t”,“methodName”:“lb”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9k.l1t”,“methodName”:“l3n”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9k.l1l”,“methodName”:“l5v”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.internal.l9k.l1t”,“methodName”:“lI”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.ADocument”,“methodName”:“lI”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.ADocument”,“methodName”:“convert”,“lineNumber”:-1},
{“declaringClass”:“com.aspose.pdf.Document”,“methodName”:“convert”,“lineNumber”:-1},

The log file set in the PdfFormatConversionOptions parameter remains empty.
How can I find out where the error occurs?

I have worked with other libraries where it was possible, from code, to insert tags when inserting texts and graphic elements into the PDF, is there a way to do it with Aspose without doing it from covert?

Thank you

@Davide_C

Would you kindly share the sample source file with us along with the code snippet so that we can test in our environment and address it accordingly?

Hi, I can attach the pdf to convert, the data inside it, for privacy, are invented.
The code used is composed of 2500 lines, it converts a jasperprint 1.3 into a pdf.
I repeat as a question, is it possible to insert the tags manually (always from code), as the pdf is built, without using the convert?
Test_x_Assistenza.pdf (113,7 KB)

@Davide_C

We apologize for the over-communication. Are you trying to work with existing document (tagged initially) and want to insert new tagged content from code inside it using Aspose.PDF for Java? For the sample file that you have shared, it was generated using JasperReports?

No, that pdf was created by Aspose.pdf, starting from scratch so with a
document = new com.aspose.pdf.Document();

For each object that is inserted in the Document I would need to insert the corresponding tagging.

FloatingBox with TextSegmentCollection for the text, etc

Thanks

@Davide_C

In that case, if possible - a list of the elements that you are adding to the PDF may be helpful in investigating the feasibility of the requirements that you have. Please try to compile a list of the elements like TextSegments, TextFragment, Table, etc. share with us so that we can log an investigation ticket and share the ID with you.

Hello below the code used to insert the various elements in the pdf, the code is not complete.
The initial part of the document creation is the same as the code already sent

// Add a new page to the main Aspose PDF document
currentAsposePage = document.getPages().add();
currentAsposePage.setPageSize(newPageSize.getWidth(), newPageSize.getHeight()); // Apply page size

        currentAsposePage.getPageInfo().getMargin().setLeft(0);
        currentAsposePage.getPageInfo().getMargin().setRight(0);
        currentAsposePage.getPageInfo().getMargin().setBottom(0);
        currentAsposePage.getPageInfo().getMargin().setTop(0);

        currentAposeGraph = new Graph(currentAsposePage.getPageInfo().getWidth(),
                                            currentAsposePage.getPageInfo().getHeight());

        currentAsposePage.getParagraphs().add(currentAposeGraph);

// add objects
// line
com.aspose.pdf.drawing.Line pdfLine = new com.aspose.pdf.drawing.Line();
pdfLine.getGraphInfo().setLineWidth(1);
pdfLine.getGraphInfo().setColor(toAsposeColor);
pdfLine.setPositionArray(new float[] { startX, startY, endX, endY });

        currentAposeGraph.getShapes().addItem(pdfLine);


        // rectangle
		com.aspose.pdf.drawing.Rectangle rect = new com.aspose.pdf.drawing.Rectangle(strokeBoxX, strokeBoxY, strokeBoxWidth, strokeBoxHeight);
        currentAposeGraph.getShapes().addItem(rect);


        // text
        FloatingBox floatingBox = new FloatingBox();
        floatingBox.setLeft(x);
        floatingBox.setTop(y);
        floatingBox.setWidth(width);
        floatingBox.setHeight(height);
        floatingBox.setNeedRepeating(false);			
		
        com.aspose.pdf.TextFragment fragmentColl = new com.aspose.pdf.TextFragment();
        TextSegmentCollection sc = fragmentColl.getSegments();
        if(lstTextSegment !=  null && lstTextSegment.size() > 0) {
                for (int i = 0; i < lstTextSegment.size(); i++) {
                            com.aspose.pdf.TextSegment segment = lstTextSegment.get(i);
                            sc.add(segment);

                }
                floatingBox.getParagraphs().add(fragmentColl);
        }
        currentAsposePage.getParagraphs().add(floatingBox);						

// end add objects

        PdfFormatConversionOptions options = new PdfFormatConversionOptions(
                "c:\\butta\\taggedpdf2.xml",PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
        options.setAutoTaggingSettings(AutoTaggingSettings.getDefault());
        document.convert(options);			// error to convert 
		
        document.save(os);	

Thanks

@Davide_C

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45130

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.