ststeiger / PdfSharpCore

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

Watermark Stream with negative height #416

Open es-tomas opened 9 months ago

es-tomas commented 9 months ago

Hi, I'm working on a watermarking of a document and I've got a stream as an input. I try to open it doing the following:

PdfDocument document = PdfReader.Open(stream, PdfDocumentOpenMode.Modify);

My pdf document is returned but with two problems: Orientation is incorrect (it's set to Portrait when it's actually Landscape) and the Height is a negative value.

This is fine if I just return the document to the user as the PDF is readable. The problem is when I try to create the XGraphics as I'm doing it as follows:

XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

This method doesn't accept negative values for the dimensions and therefore throws an exception. If I do Abs on the Height value, then it allows me to do the watermarking but the original pdf content doesn't show up anymore and I can only see the watermark.

Can somebody help with this issue?

Adding up some details about this particular pdf:

image