Hello there,
im currently having trouble resizing the content of a PDF to fit A4 without getting cut(after concatenating multiple PDFs). I made a simple picture to show the actual result i want, attached to this post.
Could someone shar a code snippet on how this could work? Thanks.
Im using Aspose.PDF 10.6.2 for Java.
no one can help?
Hi there,
Document pdfDocument = new Document(“input.pdf”);<o:p></o:p>
// Resize contents of resultant PDF
int[] page_cnt1 = new int[pdfDocument.getPages().size()];
for (int i = 0; i < pdfDocument.getPages().size(); i++)
page_cnt1[i] = i + 1;
PdfFileEditor pfe = new PdfFileEditor();
pfe.resizeContents(pdfDocument, page_cnt1,PdfFileEditor.ContentsResizeParameters.pageResize(com.aspose.pdf.PageSize.getA4().getWidth(), com.aspose.pdf.PageSize.getA4().getHeight()));
// Save output as PDF format
pdfDocument.save("output.pdf");
Thanks for your answer!
Unfortunately i dont have access to “ContentsResizeParameters”.
1. There is no PdfPageEditor.ContentsResizeParameters
2. I found ContentsResizeParameters here: com.aspose.pdf.facades.APdfFileEditor.ContentsResizeParameters
but "The type com.aspose.pdf.facades.APdfFileEditor is not visible"
Maybe the version is not campatible?
Hi there,
Sorry i actually mean PdfFileEditor.ContentsResizeParameters and not PdfPageEditor.
I even updated to 11.1.0 thats how far our Aspose license works.
I attached a picture where you see, theres no ContentResizeParameter available.
Hi there,
com.aspose.pdf.Document pdfDocument = new
com.aspose.pdf.Document(“input.pdf”);<o:p></o:p>
//Resize contents of resultant PDF
int[] page_cnt1 = new int[pdfDocument.getPages().size()];
for (int i = 0; i < pdfDocument.getPages().size(); i++)
page_cnt1[i] = i + 1;
com.aspose.pdf.facades.PdfFileEditor pfe = new com.aspose.pdf.facades.PdfFileEditor();
pfe.resizeContents(pdfDocument, page_cnt1,PdfFileEditor.ContentsResizeParameters.pageResize(com.aspose.pdf.PageSize.getA4().getWidth(), com.aspose.pdf.PageSize.getA4().getHeight()));
//Save output as PDF format
pdfDocument.save("output.pdf");
Best Regards,
Hey once again,
sorry for my late response. I still cant get it to work.
I attached the Demo pdf and my wanted result as an image.
How do i accomplish this result?
Thank you very much.
Hi there,
Thank you! I’m looking forward for a solution
Hi there,
com.aspose.pdf.Document pdfDocument = new
com.aspose.pdf.Document(“D:/Downloads/demo.pdf”);<o:p></o:p>
com.aspose.pdf.facades.PdfFileEditor pfe = new com.aspose.pdf.facades.PdfFileEditor();
PdfFileEditor.ContentsResizeParameters params = PdfFileEditor.ContentsResizeParameters.pageResize(
com.aspose.pdf.PageSize.getA4().getHeight(), com.aspose.pdf.PageSize.getA4().getWidth());
for (int i = 1; i < pdfDocument.getPages().size() + 1; i++) {
if (pdfDocument.getPages().get_Item(1).getRotate() == Rotation.on90) {
double newHight = pdfDocument.getPages().get_Item(i).getRect().getWidth() * com.aspose.pdf.PageSize.getA4().
getWidth() / pdfDocument.getPages().get_Item(i).getRect().getHeight();
double margin = (com.aspose.pdf.PageSize.getA4().getHeight() - newHight) / 2;
// Left and Right margin instead of Top and Bottom as this document was rotated.
params.setLeftMargin(PdfFileEditor.ContentsResizeValue.units(margin));
params.setRightMargin(PdfFileEditor.ContentsResizeValue.units(margin));
// setContentsWidth instead of setContentsHeight as this document was rotated.
params.setContentsWidth(PdfFileEditor.ContentsResizeValue.units(newHight));
pfe.resizeContents(pdfDocument, new int[]{i}, params);
} else {
System.out.println("Requires some additional calculations...");
}
}
pdfDocument.save(myDir+"output.pdf");