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