Reputation:
I need to crop portion of pdf using Aspose
Java jar. I searched and find the following code
Document document = new Document("copy.pdf");
document.Pages.Insert(2, document.Pages[1]);
document.Pages.Insert(3, document.Pages[1]);
document.Pages.Insert(4, document.Pages[1]);
double segment = (document.Pages[1].Rect.Height / 4);
double half = (document.Pages[1].Rect.Height / 2);
double width = document.Pages[1].Rect.Width;
double height = document.Pages[1].Rect.Height;
Aspose.Pdf.Rectangle pageRect = new Aspose.Pdf.Rectangle(0, height - segment, width, height);
document.Pages[1].CropBox = pageRect;
pageRect = new Aspose.Pdf.Rectangle(0, height - half, width, height - segment);
document.Pages[2].CropBox = pageRect;
pageRect = new Aspose.Pdf.Rectangle(0, height - half, width, (height - half) - segment);
document.Pages[3].CropBox = pageRect;
pageRect = new Aspose.Pdf.Rectangle(0, 0, width, half - segment);
document.Pages[4].CropBox = pageRect;
document.Save("test_Crop.pdf");
I am using the aspose-pdf-10.2.0.jar
. But I am not able to add all the necessary imports. Suggest the exact library for the above code to work fine.
Upvotes: 0
Views: 447
Reputation: 728
It seems your platform is Java and the shared code is C#. So to working in java you need to use Aspose.Pdf for Java jar, add aspose-pdf-10.2.0.jar to your project. Please check java version of your above shared code. Hopefully it will help you to accomplish the task.
com.aspose.pdf.Document document = new com.aspose.pdf.Document("copy.pdf");
document.getPages().insert(2, document.getPages().get_Item(1));
document.getPages().insert(3, document.getPages().get_Item(1));
document.getPages().insert(4, document.getPages().get_Item(1));
double segment = (document.getPages().get_Item(1).getRect().getHeight() / 4);
double half = (document.getPages().get_Item(1).getRect().getHeight() / 2);
double width = document.getPages().get_Item(1).getRect().getWidth();
double height = document.getPages().get_Item(1).getRect().getHeight();
com.aspose.pdf.Rectangle pageRect = new com.aspose.pdf.Rectangle(0, height - segment, width, height);
document.getPages().get_Item(1).setCropBox(pageRect);
pageRect = new com.aspose.pdf.Rectangle(0, height - half, width, height - segment);
document.getPages().get_Item(2).setCropBox(pageRect);
pageRect = new com.aspose.pdf.Rectangle(0, height - half, width, (height - half) - segment);
document.getPages().get_Item(3).setCropBox(pageRect);
pageRect = new com.aspose.pdf.Rectangle(0, 0, width, half - segment);
document.getPages().get_Item(4).setCropBox(pageRect);
document.save("test_Crop.pdf");
Upvotes: 1