We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Create the PDFA (1a/1b) compliant PDF document

I have the requirement where I know upfront whether to create PDF or PDFA(1a/1b) compliant document, so I want to create the PDF in that way. On aspose.pdf documentation I found the way to convert the existing document to PDFA but not the way to create one in first place.

@BALKRUSHNA015478

You can create a new PDFA compliant file with convert method. I request you to try following code and share your feedback.

Document doc = new Document();
doc.Pages.Add();
PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
doc.Convert(options);
doc.Save(dataDir + "Converted1a.pdf");

I tried to create the PDFA with above suggested approach, but the created PDF file is not conforming with the PDFA standards.

Here is the code I tried and generated PDF PDFA_test.pdf (23.9 KB) pdfa_validation.jpeg (67.6 KB)

private static void exportTable(String csvFilePath, int noOfColumns) throws IOException {
	BufferedReader br = new BufferedReader(new FileReader(csvFilePath));
	String line = "";
	
	//document.setBackground(java.awt.Color.RED);
	Page page =document.getPages().add();
	
	PageInfo pageInfo = page.getPageInfo();	
	MarginInfo marginInfo = new MarginInfo();
	marginInfo.setBottom( 70 );
	marginInfo.setTop( 15 );
	marginInfo.setLeft( 15 );
	marginInfo.setRight( 15 );
	pageInfo.setMargin( marginInfo );
	
	Table table = new Table();
	table.setColumnAdjustment(ColumnAdjustment.AutoFitToContent);
	table.setHorizontalAlignment(1);
	
	BorderInfo info = new BorderInfo( BorderSide.All, 1 );		
	info = new BorderInfo( BorderSide.All, Color.getBlack() );
	TextFragment textFragment;
	
	int count = 0;
	while((line=br.readLine()) != null ) {
		String[] rowValues = line.split(",");
		
		Row pdfRow = table.getRows().add();
		for (String rowVal : rowValues) {
			textFragment = new TextFragment(rowVal);
			Font font = FontRepository.openFont("E:\\ExportingFramework\\Font files\\OpenSans-Regular.ttf");
			textFragment.getTextState().setFont(font);
			textFragment.getTextState().setFont(font);
			
			Cell cell = new Cell();
			info = new BorderInfo( BorderSide.All, 1 );
			cell.setBorder( info );

			cell.getParagraphs().add(textFragment);
			pdfRow.getCells().add(cell);
		}
		count++;
		
		if(count >= 10)
			break;
	}
	
	page.getParagraphs().add( table );
	PdfFormatConversionOptions options = new PdfFormatConversionOptions(PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
	document.convert(options);
	document.save( "E:\\pdfs\\AsposeTests\\PDFA_test.pdf" );
	document.close();
	br.close();
}

@BALKRUSHNA015478

I have been able to reproduce the issue on our end. A ticket with ID PDFJAVA-40573 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.