Generate PDF with annotations

Hi team,

How to generate annotated PDF document outside of WebViewer? I understand that this should be (or normally) accomplished by using PDFNet SDK (CMIIW) in a breeze, but they do not have the license for it. My first thought was invoking the ‘Download’ overlay menu by clicking it in background but it will trigger a file save dialog which is not suitable for this task’s requirement as it needs to be done in background. Our current PDFTron setup is using ‘states’, this is custom. There are 2 type of states: read (default) and edit. When user click a button in header menu to enter the edit mode, all the annotation tools will be available for them. When they exit the edit mode, we will fetch down the current doc’s annotations, and use getFileData to send the file’s binary data to backend (which is PHP). PHP will finally construct a new file using these byte data.

Is this approach acceptable? Or is there any way I can compose a full file instead of just a byte data (without using Full API) out from WebViewer, then send it (upload) to backend without writing a custom file creation function in PHP side? Would appreciate any feedback from others who probably have deal with this before. TIA!

Hi,

That approach should work and should be the easiest to do. You would have to call exportAnnotations for the annotation XFDF and then pass it to getFileData to get the document data with the XFDF merged into it. You can then submit the bytes to your backend to write to a file on the server. Your backend does not have to be in PHP but it just has to take the bytes and write to a location it can access. This is assuming you are looking to save the final document on the server.

If you are sending the document data and XFDF separately, then they will have to be merged on the server. In which case, you will have to use a PDFNet SDK to perform the merge.

Andy Huang

Software Developer
PDFTron Systems Inc.

Hi Andy,

Thanks for your response. Apparently we run into performance issues when using byte data on backend, so I turned to upload method instead (using File() in client side to generate the file from Uint8Array, then send that to my backend endpoint) – basically its a rip from WebViewer’s download helper, which works better.

Thank you again!