Convert PDF/A to PDF format in Node.js
Contents
[
Hide
]
Convert PDF/A to PDF format
In case you want to convert PDF document, you can use AsposePdfAConvertToPDF 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 AsposePdfAConvertToPDF.
- Convert PDF file. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultConvertToPDF.pdf”. 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_PDFA_file = 'ResultConvertToPDFA.pdf';
AsposePdf().then(AsposePdfModule => {
/*Convert a PDF/A-file to PDF and save the "ResultConvertToPDF.pdf"*/
const json = AsposePdfModule.AsposePdfAConvertToPDF(pdf_PDFA_file, "ResultConvertToPDF.pdf");
console.log("AsposePdfAConvertToPDF => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
});
ECMAScript/ES6:
- Import the
asposepdfnodejs
module. - Specify the name of the PDF/A file that will be converted
- Initialize the AsposePdf module. Receive the object if successful.
- Call the function AsposePdfAConvertToPDF.
- Convert PDF file. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultConvertToPDF.pdf”. 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_PDFA_file = 'ResultConvertToPDFA.pdf';
/*Convert a PDF/A-file to PDF and save the "ResultConvertToPDF.pdf"*/
const json = AsposePdfModule.AsposePdfAConvertToPDF(pdf_PDFA_file, "ResultConvertToPDF.pdf");
console.log("AsposePdfAConvertToPDF => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);