I'm using Syncfusion to fill a form in next js. after filling out the form and clicking on the custom save button I need to get the updated blob/file of the pdf (not to download). how do i get that?
Hi Nayan Prasad,
We have created a
simple example with a save button to obtain the blob URL from the edited PDF in
the PDF Viewer. Below, you will find the code snippet and the sample for your
reference.
Code Snippet:
|
const handleSave = async () => { pdfViewerRef.current.serverActionSettings.download = 'Download'; let data; let base64data; pdfViewerRef.current.saveAsBlob().then((value) => { data = value; var reader = new FileReader(); reader.readAsDataURL(data); reader.onload = () => { base64data = reader.result; const result = base64data.split(","); const byteCharacters = decodeBase64(result[1]); // Create an array of bytes const byteNumbers = new Array(byteCharacters.length); for (let i = 0; i < byteCharacters.length; i++) { byteNumbers[i] = byteCharacters.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers);
// Create a Blob object from the byte array const blob = new Blob([byteArray], { type: 'application/pdf' });
// Generate a Blob URL from the Blob object const blobUrl = URL.createObjectURL(blob); console.log(blobUrl); }; }); pdfViewerRef.current.serverActionSettings.download = 'Download'; }; |
Regards,
Sathiyaseelan K
hi,
Thanks for your response. This method of getting blob is working fine. But i encountered another issue after saving the file.
Basically, I'm trying to fill the pdf using syncfusion pdf viewer and save the update/filled pdf. But after i save the pdf some of the text fields from the original pdf file are gone. I'm attaching the corresponding code, and pdf files in the zip.
Hi Nayan Prasad,
We tested the issue
with the sample below, and the problem did not occur. The PDF saved using the
blog generated correctly with all form fields included. Please check if the
issue occurs with the sample provided. If not, modify your code accordingly. If
possible, please provide the sample and a demo video to replicate the
issue.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/get-blob-url399891765.zip
Demo: https://www.syncfusion.com/downloads/support/directtrac/general/ze/save_pdf_as_blob866819109.zip
Regards,
Sathiyaseelan K