ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.08k stars 237 forks source link

InsertPage #455

Open FreeVB opened 1 week ago

FreeVB commented 1 week ago

Why is there an error when inserting a picture?

Inserts the specified page in this document. If the page is from an external document, it is imported to this document. In this case the returned page is not the same object as the specified one.

PdfDocument document = PdfReader.Open(sourcePdfPath, PdfDocumentOpenMode.Modify);
PdfPage newPage = document.AddPage();
XImage image = XImage.FromFile(imagePath);
XGraphics gfx = XGraphics.FromPdfPage(newPage);
gfx.DrawImage(image, 0, 0, newPage.Width, newPage.Height);
if (pageIndex < document.PageCount - 1)
{
    document.InsertPage(pageIndex + 1, newPage);
}
else
{
    document.AddPage(newPage);
}