PDF to images with margins?

Hello.
I have a task.

  1. Load PDF file with one page. Inside we see an image

  2. I want to save this image and manipulate of margins.

  3. The result I wish to see like a PDF page - 30 mm from Header Margin and - 50 mm from Footer margin. Is’t possible to do by Gembox.PDF or Gembox.Document?
    Thanks

Hi,

Try this:

using (var document = PdfDocument.Load("input.pdf"))
{
    var imageElement = (PdfImageContent)document.Pages[0].Content.Elements
        .All(true)
        .First(e => e.ElementType == PdfContentElementType.Image);

    double imageWidth = imageElement.Bounds.Right - imageElement.Bounds.Left;
    double imageHeight = imageElement.Bounds.Top - imageElement.Bounds.Bottom;

    const int marginTop = 30;
    const int marginBottom = 50;

    var page = document.Pages.Add();
    page.Content.DrawImage(imageElement.Image,
        new PdfPoint(0, marginBottom),
        new PdfSize(imageWidth, imageHeight));

    page.SetMediaBox(imageWidth, marginTop + imageHeight + marginBottom);

    document.Save("output.png",
        new ImageSaveOptions(ImageSaveFormat.Png)
        {
            PageNumber = document.Pages.Count - 1
        });
}

Does this solve your issue?

Regards,
Mario