How to get the size of a PDF document (before save)

Hi

I am merging several PDF documents with PdfDocument.ImportPageRange. My merged document may not be larger than 10MB. How do I see the size of the doument without saving it.


1 Reply 1 reply marked as answer

SV Surya Venkatesan Syncfusion Team October 26, 2021 05:32 PM UTC

Hi Steen Thrane Jacobsen, 

Thank you for contacting Syncfusion support.  

As of now, we don’t have support to get the Pdf document file size before calling the save method. Because, file writing streams are start at the PdfDocument.save(). So, We recommend the below steps to find the PDF file size before make it to PDF document, 
//Initialize the memory stream. 
 MemoryStream stream = new MemoryStream(); 
//Save the document 
document.Save(stream); 
//Get File size in Kb. 
float fileSize = (stream.ToArray().Length) / 1024f; 
//Generate PDF file. 
File.WriteAllBytes("../../Output.pdf", stream.ToArray()); 
 
Please let us know if you need any further assistances in this. 
 
Regards, 
Surya V 


Marked as answer
Loader.
Up arrow icon