Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Netsuite pdf.min.js support

kb9Jul 23 2024 — edited Jul 23 2024

Hi,

In NetSuite, I need to read a pdf in ScheduledScript and apply some business logic to the extracted PDF content.

I tried using pdf.min.js to read pdf but below sample code is returning “PDF library not loaded.”:

/**
* @NApiVersion 2.1
* @NScriptType ScheduledScript
*/
define(['N/file', 'N/log', 'N/runtime', 'SuiteScripts/pdf.min'], function (file, log, runtime, pdf) {
function execute(context) {
try {
if (pdf) {
log.debug('PDF Library Loaded', 'pdf.min.js is loaded and pdfjsLib is available.');
pdf.GlobalWorkerOptions.workerSrc = './pdf.worker.min.js';
var loadingTask = pdf.getDocument('SuiteScripts/test.pdf'); // Adjust path and method as needed
loadingTask.promise.then(function (pdfDoc) {
log.debug('PDF Loaded', 'PDF document loaded successfully.');
// Further processing of pdfDoc
}).catch(function (error) {
log.error('PDF Load Error', error.message);
});
} else {
log.error('Load Error', 'PDF library not loaded.');
}
} catch (error) {
log.error('Error', 'Failed to execute script: ' + error.message);
}
}
return {
execute: execute
};
});

Has anyone been able to extract pdf document content in ScheduledScript. Please share any sample code.

Thanks much!

Comments
Post Details
Added on Jul 23 2024
0 comments
197 views