In general, downloading the
PDF document will increase its size due to the instances stored for the actions
performed in the document. The same behavior occurs in Adobe Reader too.
However, to restrict this
file size change you can make use of the below code snippet. This highlighted
code will skip the changes made in the document on every save operation. This
code need to be handled on save operation.
Code Snippet:
|
byte[] byteArray;
byteArray
= await viewerInstance.GetDocumentAsync();
string
base64String = Convert.ToBase64String(byteArray);
PdfLoadedDocument
loadedDocument = new PdfLoadedDocument(byteArray);
Stream
stream = new MemoryStream();
string
base64string = Convert.ToBase64String((stream as MemoryStream).ToArray());
loadedDocument.EnableMemoryOptimization = true;
loadedDocument.FileStructure.IncrementalUpdate =
false;
loadedDocument.Save(stream);
loadedDocument.Close(true);
File.WriteAllBytes("D:\\task\\blazor-sample\\blazor-sample\\blazor-sample\\wwwroot\\Data\\output.pdf",
(stream as MemoryStream).ToArray());
|
By setting the incremental
update of the file structure to false, you can restrict the incremental
file size.
Kindly find the documentation
for restricting the incremental file size.
Documentation: https://help.syncfusion.com/file-formats/pdf/working-with-document#performing-incremental-update-for-pdf-document
Kindly try this and let us
know if you have any concerns.