We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Set PDF CropBox/MediaBox using Aspose.PDF for .NET - CropBox on a page does not crop the page

In Aspose.PDF .NET 20.9.0. Setting CropBox on a page does not crop the page though GetPageRect says it was.

This worked in version 19.4.0

c# nUnit test to repeat:

[Test]
public void CropBoxTest()
{
    string methodName = MethodBase.GetCurrentMethod().Name;
    string path = DocConfig.GetAssetOutputPath(methodName + ".pdf");

    var doc = new Document();

    Page page = doc.Pages.Add();
    page.PageInfo.Width = 678;
    page.PageInfo.Height = 858;
    page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
    page.ArtBox = new Aspose.Pdf.Rectangle(llx: 0, lly: 0, urx: 678, ury: 858);   //678x858
    page.CropBox = new Aspose.Pdf.Rectangle(llx: 0, lly: 0, urx: 678, ury: 858);  //678x858
    page.MediaBox = new Aspose.Pdf.Rectangle(llx: 0, lly: 0, urx: 678, ury: 858); //678x858
    page.Rect = new Aspose.Pdf.Rectangle(llx: 0, lly: 0, urx: 678, ury: 858);     //678x858
    page.TrimBox = new Aspose.Pdf.Rectangle(llx: 33, lly: 33, urx: 645, ury: 825); //612x792
    page.BleedBox = new Aspose.Pdf.Rectangle(llx: 24, lly: 24, urx: 654, ury: 834); //630x810

    page.Paragraphs.Add(new TextFragment($"{methodName} created on {DateTime.Now}"));
    page.Paragraphs.Add(new TextFragment($"{path}"));

    var before = page.GetPageRect(true);
    page.Paragraphs.Add(new TextFragment($"Size before: {before.Width} x {before.Height}"));

    //CROP THE PAGE
    page.ArtBox = page.BleedBox = page.CropBox = page.MediaBox = page.Rect = (Aspose.Pdf.Rectangle)page.TrimBox.Clone();

    var after = page.GetPageRect(true);
    page.Paragraphs.Add(new TextFragment($"Size after: {after.Width} x {after.Height}"));

    doc.Save(path, SaveFormat.Pdf);
    doc.Dispose();

    Assert.AreNotEqual(before.Width, after.Width);

    FileAssert.Exists(path);
}

@dirq

We have logged an investigation ticket as PDFNET-48867 in our issue tracking system for further analysis against this scenario. We will check it in details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

I just upgraded to 21.9.0 and it seems that SetPageSize is cropping from the upper right instead of upper left like it used to.

@dirq

We have recorded your concerns and will surely consider them during ticket investigation. We will investigate the logged ticket from this perspective as well and let you know as soon as it is resolved. Please give us some time.

We apologize for the inconvenience.