I’m trying to render multiple images (tiles) from a single page of a PDF document to circumvent GDI / memory restrictions for high resolution rendering of large PDF pages.
I was using the follwing code (bounadries of the last row / col not checked, but that’s not the issue):
using (var pdf = new Document(sourceStream))
{
for (var page = 1; page <= pdf.Pages.Count; page++)
{
var dev = new JpegDevice(new Resolution(300), 90);
var pdfPage = pdf.Pages[page];
var pageRect = pdfPage.GetPageRect(true);
var tileSize = 350;
// check if tiles should be used
if (pageRect.Width > tileSize || pageRect.Height > tileSize)
{
var rows = (int)Math.Ceiling(pageRect.Height / tileSize);
var cols = (int)Math.Ceiling(pageRect.Width / tileSize);
var cropBox = pdfPage.CropBox;
for (var row = 0; row < rows; row++)
{
for (var col = 0; col < cols; col++)
{
var tileBox = new Aspose.Pdf.Rectangle(col * tileSize, pageRect.Height - row * tileSize, (col+1) * tileSize, pageRect.Height - (row + 1)* tileSize);
pdfPage.CropBox = tileBox;
dev.Process(pdfPage, $"image_{page_{row}x{col}.jpg");
}
}
}
else
{
dev.Process(pdfPage, $"image_{page}_.jpg");
}
}
}
Now if the CropBox property is set in the first iteration of columns, this value will stay constant, regardless what value will be set to CropBox later on.
So how can I “reset” the CropBox property of a page. I don’t want to create a new instance of Document for all the tiles for all pages.
Would you please share your sample PDF document which you are using in your code snippet as a source. We will test the scenario in our environment and address it accordingly.
We have tested the scenario in our environment while using Aspose.PDF for .NET 19.8 and were able to notice the issue that you have mentioned. Therefore, an investigation ticket as PDFNET-46911 has been logged in our issue tracking system. We will further look into details of the issue and keep you posted with the status of ticket resolution. Please be patient and spare us little time.
Sadly, the earlier logged ticket in this forum thread is not yet resolved. We will surely update this forum thread as soon as we have certain news over ticket resolution. Furthermore, we have also responded to your other inquiry after logging the issue in our issue management system. You may please follow up there.
// Load PDF
var pdf = new Aspose.Pdf.Document(path);
// Change CropBox first time - this works
pdf.Pages[1].CropBox = new Aspose.Pdf.Rectangle(0,0,400,500);
// Change CropBox second time - DOES NOT WORK
pdf.Pages[1].CropBox = new Aspose.Pdf.Rectangle(0,0,401,501);
Regretfully, the ticket has not been yet resolved. However, we will surely provide an update in this forum thread as soon as some significant progress is made towards its resolution.
We are afraid that the earlier logged issue is not yet resolved. However, we have recorded your concerns and will surely let you know as soon as issue is resolved. Please be patient and spare us some time.