We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert a WORD InputStream to PDF with limited size


Is there an example of code that:
Receive as an input an InputStream of a word file, and a maximum size, and convert this InputStream to a PDF file that will be no longer then the given size.
Lets say the max=10MB and the full pdf is 20MB so the output will be a PDF with the maximum pages possible but with the limitation of 10MB size .


Hi Gil,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. Aspose.Words does not provide the requested feature.

However, you can use PdfSaveOptions to limit the output Pdf pages using PdfSaveOptions.PageIndex and PdfSaveOptions.PageCount properties. Please check the following code example for your kind reference.

Document doc = new Document(MyDir + "in.docx");

for(int i = 0; i < doc.getCount(); i++)


PdfSaveOptions options = new PdfSaveOptions();



doc.save(MyDir + "Out_"+ i +".pdf", options);


It might be possible that the content’s size of first page of document is 10 MB e.g there is big image at first page. So, you need to check the size of each page. In your case, I suggest you following solution.

1) Convert each page of Word document into PDF by using PdfSaveOptions.PageIndex and PdfSaveOptions.PageCount properties
2) Check the size of output Pdf files size
3) Once the size of pdf files come to the limit, stop the conversion.
4) Join the output Pdf files using Aspose.Pdf. Please check following documentation link about joining the Pdf files.


i’ll try it