Change the page size

Hello, I’ve been working on splitting a single page into 3 separate sections. I have this working for the most part. Is there a way to change the size of the PDF page. I’m using the SetCropBox (and SetMedaiBox) however, they don’t change the actual size of the page. Is there a way to tell the page it is not 8.5 x 11, maybe 8.5 x 3.5 instead?

Hi James,

The SetMediaBox method should work, I’m unable to reproduce your issue with it.

Here is what I tried:

using (var document = PdfDocument.Load("input.pdf"))
{
    var page = document.Pages[0];
    Console.WriteLine(page.Size);

    page.SetMediaBox(0, 0, page.Size.Width, page.Size.Height / 3);
    Console.WriteLine(page.Size);

    document.Save("output.pdf");
}

Regards,
Mario

Unfortunately, SetMediaBox and SetCropBox are visual functionalities that do not actually move the piece of data to that location in the document. I need to actually move the data into place so it can be read by a parser that is designed to grab information from the document at specific locations. To that end, is there a way to read all of the info from the document within a specific bounds and write that info to a new page and put this data onto that new page at the top of each page?

I would really hate to have to read in the entire document little pieces at a time and write them out little pieces at a time, that would be tedious.

I do want to thank you for your help, what you’ve given me in my few posts here has at least got me started and close to what I need.

Hi,

The CropBox is the visible region and it is optional, but the MediaBox is not. The MediaBox is mandatory and it is used to specify the width and height of the page.

Anyway, what exactly do you mean by “move the data into place”?
Based on your previous topics, I believe you just need to remove the elements that are outside the bounds of your new MediaBox, is that correct?

Perhaps it would be easier to understand your exact requirement if you provide us with some sample files that demonstrate your use case.

Regards,
Mario