Removing attachments from PDF in Node.js
Contents
[
Hide
]
You can delete attachments from a PDF file using Aspose.PDF for Node.js via C++. In case you want to delete attachments from a PDF, you can use AsposePdfDeleteAttachments function. Please check the following code snippet in order to delete attachments from a PDF file in Node.js environment.
CommonJS:
- Call
require
and importasposepdfnodejs
module asAsposePdf
variable. - Specify the name of the PDF file from which the attachments will be removed.
- Call
AsposePdf
as Promise and perform the operation for removing attachments. Receive the object if successful. - Call the function AsposePdfDeleteAttachments.
- Delete attachments. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPdfDeleteAttachments.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_file = 'Aspose.pdf';
AsposePdf().then(AsposePdfModule => {
/*Delete attachments from a PDF-file and save the "ResultPdfDeleteAttachments.pdf"*/
const json = AsposePdfModule.AsposePdfDeleteAttachments(pdf_file, "ResultPdfDeleteAttachments.pdf");
console.log("AsposePdfDeleteAttachments => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
});
ECMAScript/ES6:
- Import the
asposepdfnodejs
module. - Specify the name of the PDF file from which the attachments will be removed.
- Initialize the AsposePdf module. Receive the object if successful.
- Call the function AsposePdfDeleteAttachments.
- Delete attachments. Thus, if ‘json.errorCode’ is 0, the result of the operation is saved in “ResultPdfDeleteAttachments.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_file = 'Aspose.pdf';
/*Delete attachments from a PDF-file and save the "ResultPdfDeleteAttachments.pdf"*/
const json = AsposePdfModule.AsposePdfDeleteAttachments(pdf_file, "ResultPdfDeleteAttachments.pdf");
console.log("AsposePdfDeleteAttachments => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);