Cannot set cropbox on rotated page


I have code below that crops the PDF page and then creates a new Document with cropped pdf page.
The code works fine as long as the source pdf page is not rotated. However,when source page has rotation then code is not able to set the page’s CropBox property. Page.CropBox property does not change.

The page’s original Width = 1008 and Original Height = 612. I rotated the page using FoxIt and saved. When the code loads the rotated page, the MediaBox and CropBox property still shows Width = 1008 and Height = 612 ( the rotated page “notworking.pdf” is included in the attached zip)

       static void Main(string[] args)

            // load source documents
            // NOTE: The source document's page is already rotated by 270
            // sourcePage.Rotate is on270

            var sourceFile = AppDomain.CurrentDomain.BaseDirectory + "NotWorking.pdf";
            var sourcePdf = new Document(sourceFile);
            var sourcePage = sourcePdf.Pages[1];
            var sourcedimension = sourcePage.GetPageRect(true);

            var cropBox = new CartesianCropBox()
                LLX = 0,
                LLY = 658, //Y Axis
                URX = sourcedimension.Width,
                URY = sourcedimension.Height,
                Height = sourcedimension.Height - 658, // URY - LLY
                Width = sourcedimension.Width,
            var image = GetCroppedImage(sourcePdf.Pages[1], cropBox);

            // create new document and set page size
            var newDoc = new Document();
            var newPage = newDoc.Pages.Add();
            newPage.SetPageSize(sourcedimension.Width, sourcedimension.Height);

            // add cropped image to page

            // save document
            newDoc.Save(_outputDir + "\\out.pdf");

        private static Aspose.Pdf.Image GetCroppedImage(Aspose.Pdf.Page sourcePage, CartesianCropBox cropBox)
            Aspose.Pdf.Image img = new Image();
            Aspose.Pdf.Rectangle pageRect = new Rectangle(cropBox.LLX, cropBox.LLY, cropBox.URX, cropBox.URY);

            // Issue here ??????????
            // the sourcePage.CropBox does not get set when page has rotation
            sourcePage.CropBox = pageRect;

            img.FixHeight = cropBox.Height;
            img.FixWidth = cropBox.Width;

            // Create Image device with specified attributes            
            JpegDevice imgDevice = new JpegDevice(new Resolution(1920, 1080));
            img.ImageStream = new MemoryStream();

            // Convert a particular page and save the image to stream
            imgDevice.Process(sourcePage, img.ImageStream);
            img.ImageStream.Seek(0L, SeekOrigin.Begin);

            // save image for testing purpose
            using (var fs = new FileStream(_outputDir + "\\out.jpeg", FileMode.Create, FileAccess.Write))

            img.ImageStream.Seek(0L, SeekOrigin.Begin);

            return img;

I have attached the complete solution with working.pdf and notworking.pdf file. The solution needs to rebuild to get aspose.pdf nuget package (476.2 KB)



Thank you for contacting support.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFNET-46916 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.


Thanks Farhan
You have also replied to my same question on stack overflow and i think you have created another ticket id PDFNET-46900

You may want to consolidate both



Thank you for the feedback.

We actually wanted to mention PDFNET-46916 there as well. Since edit is not allowed in comments after some time, we have added a new comment there with correct ticket ID. Sorry for the confusion.


Are there any updates to this issue?

I think i may be related to PDFNET-39040



Thank you for getting back to us.

We are afraid PDFNET-46916 has not been investigated yet. We will let you know once any update will be available in this regard. We have recorded your comments and will be checking if same reason is causing these two issues logged as PDFNET-46916 and PDFNET-39040.