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

Free Support Forum - aspose.com

Issue in setting the page size and height

Hi,

I am trying to set the page size and height of a pdf document but aspose always create the pdf document with same size. Here is the code.

com.aspose.pdf.Document pdfDocument = new Document();
pdfDocument.getPages().add();
pdfDocument.getPageInfo().setHeight(50);
pdfDocument.getPageInfo().setWidth(50);
pdfDocument.save(“c:/documents/testdata/size.pdf”);

Can you please let me know if there is any way through which I can set the page size in aspose.

Thanks
Rajeev Mathur

Hi Rajeev,


Thanks for your inquiry. We have tested the scenario and found that page size is ignored in case of blank page. If we add some object in Page it honor the page size. Please let us know if you have some requirement to create a PDF page with a single blank page. So we will investigate your requirements and will update you accordingly.

com.aspose.pdf.Document pdfDocument = new Document();<o:p></o:p>

Page page=pdfDocument.getPages().add();

pdfDocument.getPageInfo().setHeight(200);

pdfDocument.getPageInfo().setWidth(200);

TextFragment text= new TextFragment("test");

page.getParagraphs().add(text);

pdfDocument.save(myDir+"size_java.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

Hi,

I am creating a pdf from an existing document and I need to change the size of the pdf document. I tried the below code and it does not work.

com.aspose.pdf.Document pdfDocument = new Document(“C:/test.pdf”);

pdfDocument.getPageInfo().setHeight(200);

pdfDocument.getPageInfo().setWidth(200);

pdfDocument.save(myDir+“size_java.pdf”);

Can you please let me know if I am doing anything wrong or if there is an alternative for this.


Thanks

Rajeev Mathur



Hi Rajeev,


Thanks for your inquiry. Please note PageInfo class works while we are creating a new PDF document from scratch. In case to change page dimensions of existing Pdf document SetPageSize property is used as following.

com.aspose.pdf.Document pdfDocument =
new Document(“test.pdf”);<o:p></o:p>

//pdfDocument.getPageInfo().setHeight(200);

//pdfDocument.getPageInfo().setWidth(200);

Page page=pdfDocument.getPages().get_Item(1);

page.setPageSize(200, 200);

pdfDocument.save("size_java.pdf");


Please feel free to contact us for any further assistance.

Best Regards,