Product: PDFTron Web
Product Version: Latest
I’d also be willing to try just converting it back to a grayscale PDF if that’s easier.
Sample code taken directly from the example above (have not tried converting to G4 because the exportStream function does not even exist.
const doc = await PDFNet.PDFDoc.createFromURL(this.documentUrl);
console.log(‘PDFNet and PDF document initialized and locked’);
const pdfdraw: PDFNet.PDFDraw = await PDFNet.PDFDraw.create(92);
const itr = await doc.getPageIterator(1);
const currPage = await itr.current();
const pngBuffer = await pdfdraw.exportStream(currPage, ‘PNG’);
exportStream does not exist.
That web page does not contain all the code for the sample, its just a snippet. Please do the following.
- Download WebViewer
- Unzip in a folder hosted by your server
- Run the
From the folder above you can see all the code used.
I’ll download that sample today and see if it helps.
I looked at the PDFDraw sample and it wasn’t really helpful. We’re using an angular project so all of our code is in TS (as pasted above) so I’m still not sure how to get the export functions to be available.
Also, that example is still just splitting a multipage PDF up into multiple files and saving each one to disk. I need it to convert a multipage PDF to a multipage G4 tiff to a stream that I can upload to S3 - not have 1 file for each page and not saving to disk. Any suggestions?
We’re using an angular project so all of our code is in TS (as pasted above) so I’m still not sure how to get the export functions to be available.
This guide is the simplest one showing how to integrate our PDFNetJS SDK (with PDFDraw class) into any web site.
I need it to convert a multipage PDF to a multipage G4 tiff to a stream that I can upload to S3 - not have 1 file for each page and not saving to disk.
The PDFDraw.exportStream is a new API, so perhaps you are on an older version, in which case PDFDraw.exportBuffer is an option.
And yes, no disk access is required, the TIFF data will be in memory for you.
all of our code is in TS (as pasted above) so I’m still not sure how to get the export functions to be available.
We also have TypeScript APIs for the PDFDraw class. I think at this time there is no specific guide for accessing PDFDraw TypeScript API but the guide below will hopefully get you started.
I followed the link you gave me, cloned the repo, followed the instructions (ran NPM install) and then tried to run the sample and get the following error:
C:\Git\webviewer-typescript-sample\node_modules\parcel\src\builtins\css-loader.js: Invalid Version: undefined
at new SemVer (C:\Git\webviewer-typescript-sample\node_modules@babel\preset-env\node_modules\semver\semver.js:314:11)
at compare (C:\Git\webviewer-typescript-sample\node_modules@babel\preset-env\node_modules\semver\semver.js:647:10)
at lt (C:\Git\webviewer-typescript-sample\node_modules@babel\preset-env\node_modules\semver\semver.js:688:10)
at Object.default (C:\Git\webviewer-typescript-sample\node_modules@babel\helper-plugin-utils\lib\index.js:22:12)
at getEnvPlugins (C:\Git\webviewer-typescript-sample\node_modules\parcel\src\transforms\babel\env.js:62:34)
at getEnvConfig (C:\Git\webviewer-typescript-sample\node_modules\parcel\src\transforms\babel\env.js:12:25)
at async getBabelConfig (C:\Git\webviewer-typescript-sample\node_modules\parcel\src\transforms\babel\config.js:32:19)
at async babelTransform (C:\Git\webviewer-typescript-sample\node_modules\parcel\src\transforms\babel\transform.js:6:16)
at async JSAsset.pretransform (C:\Git\webviewer-typescript-sample\node_modules\parcel\src\assets\JSAsset.js:83:5)
Any idea why I’d be getting that from a fresh repo pull?
I was able to narrow down this issue to a dependency in that sample. It would seem the latest version of the “parcel” npm package has some issues. I will update the repo, but for a faster fix, you can update the package dependency yourself.
Change the red line above in the package.json to the green line and run
This should fix the error. Let me know if there are any issues.
PDFTron Systems, Inc.
Sorry it’s taken me a while to get back to you. That works for the sample app. Thanks.