How to convert PDF to PDF/A using free and open source library?
This is my code which convert word to pdf, I want to generate PDFA format pdf (A-4 standard is preferrable)
code:
@GetMapping(value = ["/generate-pdf"], produces = [MediaType.APPLICATION_PDF_VALUE])
fun generatePdf(): ResponseEntity<FileSystemResource> {
// Load the Word template
val initialFile = File("src/main/resources/template.docx")
val templateFile = FileInputStream(initialFile)
val document = XWPFDocument(templateFile)
// Modify the document as needed
val paragraphs: List<XWPFParagraph> = document.paragraphs
for (paragraph in paragraphs) {
val runs: List<XWPFRun> = paragraph.runs
for (run in runs) {
val text = run.getText(0)
if (text != null) {
val replacedText = text.replace("{{name}}", "John Doe").replace("{{product}}", "Sample Product")
run.setText(replacedText, 0)
}
}
}
val out: OutputStream = FileOutputStream("outputfile.pdf")
val options: PdfOptions? = null
PdfConverter.getInstance().convert(document, out, options)
val file = FileSystemResource("outputfile.pdf")
val responseHeaders = HttpHeaders()
responseHeaders.contentType = MediaType.APPLICATION_PDF
responseHeaders.contentLength = file.contentLength()
responseHeaders.add("Content-Disposition", "attachment; filename=outputfile.pdf")
// Load the converted PDF
val pdfFile = File("outputfile.pdf")
val pdfDocument = PDDocument.load(pdfFile)
return ResponseEntity.ok().headers(responseHeaders).body(file)
}```
How can i convert from PDF to PDF/A
I want free and open source library. Spire pdf i have seen. it adds some warning text on top.
Other IText and aspose are paid and come with some licence