Convert PDF to PDF/A formats in Node.js
Contents
[
Hide
]
Aspose.PDF for Node.js allows you to convert a PDF file to a PDF/A compliant PDF file.
Try to convert PDF to PDF/A online
Aspose.PDF for Node.js presents you online free application “PDF to PDF/A-1A”, where you may try to investigate the functionality and quality it works.
Convert PDF to PDF/A format
In case you want to convert PDF document, you can use AsposePdfConvertToPDFA function. Please check the following code snippet in order to convert in Node.js environment.
CommonJS:
- Call
require
and importasposepdfnodejs
module asAsposePdf
variable. - Specify the name of the PDF file that will be converted.
- Call
AsposePdf
as Promise and perform the operation for converting file. Receive the object if successful. - Call the function AsposePdfConvertToPDFA.
- Repair the PDF file. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultConvertToPDFA.pdf”. During the conversion process, validation is performed, and the validation results are saved as “ResultConvertToPDFALog.xml.” If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.
const AsposePdf = require('asposepdfnodejs');
const pdf_file = 'Aspose.pdf';
AsposePdf().then(AsposePdfModule => {
/*Convert a PDF-file to PDF/A(1A) and save the "ResultConvertToPDFA.pdf"*/
/*During conversion process, the validation is also performed, "ResultConvertToPDFA.xml"*/
const json = AsposePdfModule.AsposePdfConvertToPDFA(pdf_file, AsposePdfModule.PdfFormat.PDF_A_1A, "ResultConvertToPDFA.pdf", "ResultConvertToPDFALog.xml");
console.log("AsposePdfConvertToPDFA => %O", json.errorCode == 0 ? [json.fileNameResult, json.fileNameLogResult] : json.errorText);
});
ECMAScript/ES6:
- Import the
asposepdfnodejs
module. - Specify the name of the PDF file that will be converted.
- Initialize the AsposePdf module. Receive the object if successful.
- Call the function AsposePdfConvertToPDFA.
- Repair the PDF file. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultConvertToPDFA.pdf”. During the conversion process, validation is performed, and the validation results are saved as “ResultConvertToPDFALog.xml.” If the json.errorCode parameter is not 0 and, accordingly, an error appears in your file, the error information will be contained in ‘json.errorText’.
import AsposePdf from 'asposepdfnodejs';
const AsposePdfModule = await AsposePdf();
const pdf_file = 'Aspose.pdf';
/*Convert a PDF-file to PDF/A(1A) and save the "ResultConvertToPDFA.pdf"*/
/*During conversion process, the validation is also performed, "ResultConvertToPDFA.xml"*/
const json = AsposePdfModule.AsposePdfConvertToPDFA(pdf_file, AsposePdfModule.PdfFormat.PDF_A_1A, "ResultConvertToPDFA.pdf", "ResultConvertToPDFALog.xml");
console.log("AsposePdfConvertToPDFA => %O", json.errorCode == 0 ? [json.fileNameResult, json.fileNameLogResult] : json.errorText);