Setting CropBox to PdfPage only works once

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.

I’m using version 19.2.0 of Aspose.PDF for .NET.

@bitterlich

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.

It doesn’t matter what PDF we are using, but I’ve attached an example.
Example_LS.pdf (596.8 KB)

@bitterlich

Thanks for sharing sample PDF.

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.

We are sorry for the inconvenience.

Any update on PDFNET-46911. I’ve also been having trouble setting CropBox since version 19.4. See my recent issue: Set PDF CropBox/MediaBox using Aspose.PDF for .NET - CropBox on a page does not crop the page

@dirq

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.

We apologize for the inconvenience caused.

I am experiencing this too. Steps are:

// 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);

@ast3

We have updated the information of the ticket accordingly and will surely inform you as soon as it is resolved.

We apologize for the inconvenience.

Any updates on PDFNET-46911?

@dirq

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 apologize for the inconvenience.

@asad.ali
Any updates on PDFNET-46911?

@asposeuuups

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.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-46911) have been fixed in Aspose.PDF for .NET 22.9.