Copy link to clipboard
Copied
I am currently working on a Learning Management System and I have to attach this Embed API to my application based on PHP Core, but instead of downloading the pdf I want it to be saved on my server and not on the client's computer, is there any way to do it?
Copy link to clipboard
Copied
Yes, that should be possible. Please refer to the public facing Embed APIs documentation for Save API here.
Copy link to clipboard
Copied
I've posted a functioning example on CodePen.
The functional part of the code is below. The content parameter is the PDF as a ByteArray. Convert the ByteArray into a Blob then add it to the FormData as you would any other file, then simply POST it to your server. The PHP side looks just like you uploaded a file.
To run the demo, go to the CodePen, add a comment, then Save the file. The file will get sent to my server and then zipped; this is just to make it clear that the normal save function was replaced. You'll see the UI change to a message that will let you download the zipped file. Open the zip and you should see your commented PDF.
adobeDCView.registerCallback(
AdobeDC.View.Enum.CallbackType.SAVE_API,
function (metaData, content, options) {
var uint8Array = new Uint8Array(content);
var blob = new Blob([uint8Array], { type: 'application/pdf' });
formData = new FormData();
var pdfFilename = urlToPDF.split("/").slice(-1)[0];
pdfFilename = pdfFilename.split(".")[0] + "-" + uuidv4() + ".pdf";
formData.append('pdfFile', blob, pdfFilename);
var zipFileName = pdfFilename.replace(".pdf", ".zip");
fetch("https://practicalpdf.com/code-pens/reflect/", {
method: 'POST',
body: formData,
})
.then(
function (response) {
if (response.status == 200) {
updateSaveUI(zipFileName);
}
}
)
return new Promise((resolve, reject) => {
resolve({
code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
data: {
metaData: { fileName: urlToPDF.split("/").slice(-1)[0] }
}
});
});
},
saveOptions
);
Copy link to clipboard
Copied
@Joel_Geraci Excellent example, you almost solved my problem. I am a teacher and I want to use this method to collect student work back to my server. However I need a little more help. This code did not work when I used my server URL and figured out I may need a PHP code or something like that. I have no idea about PHP and whatever I tried did not work...Can you please guide or point me in the right direction...Sorry, I might have uploaded some student worksheets to your server while trying 🙂
Copy link to clipboard
Copied
Hello Joel_Geraci,
I followed your instructions to create a preview of a pdf with the possibility of inserting annotations.
Everything works fine.
How I can save these annotations to the database.
Can you help me, please?
Thank you
Copy link to clipboard
Copied
Do you want to save just the annotations to a database or the entire new PDF with the annotations to a database?
Copy link to clipboard
Copied
Hello Joel_Geraci,
i need to save the entire new PDF with the annotations to a database. Is it possible?
Thanks