A PDF I am attempting to generate is not generating correctly when I run it through PDFSharp (gdi 1.50.4845-RC2a). I am attempting to add a border to the top of the page using the code below. The source of the original PDF is Mac OS X 10.8.5 Quartz PDFContext (PDFversion 1.3). I have tested through a number of past versions of PDF sharp gdi and am getting the same result. PDF sharp is not throwing any exception during the generation process, so I do not know where to look for the error, or handle it differently.
I have also tried rendering this through PDFSharp, using XImage XImage.FromFile, same result.
Below is the code I am using, this would appear to be an issue with how the logo image in the original document is being dealt with when the PDF is redrawn, possibly how PDF sharp is dealing with the encoding/compression from that Mac OS X QUartz pdf creator.
I note in the FAQs it mentions layers are not supported (
http://www.pdfsharp.net/wiki/PDFsharpFA ... PDFsharp_7). If this is a layer issue, if this can be detected via an exception or otherwise that would also be useful.
Note:
If I take the original document and print it to PDF using Adobe Reader or Windows print to PDF, it renders correctly using the code below.
Additionally, just adding the pages from the original document into a new PDF without making any changes works fine, and the output file opens correctly in Adobe Reader, Edge, and Chrome.
Code:
PdfSharp.Pdf.PdfDocument outputDocument = new PdfSharp.Pdf.PdfDocument();
XGraphics gfx;
XRect box;
try
{
for (int idx = 0; idx < form.PageCount; idx++)
{
// Add a new page to the output document
PdfSharp.Pdf.PdfPage page = outputDocument.AddPage();
XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.Letter);
if (form.PixelWidth > form.PixelHeight)
{
page.Width = size.Height;
page.Height = size.Width;
}
else
{
page.Width = size.Width;
page.Height = size.Height;
}
int rotate = page.Elements.GetInteger("/Rotate");
gfx = XGraphics.FromPdfPage(page);
box = new XRect(0, 25, page.Width, (page.Height - 25));
// Draw the page identified by the page number like an image
gfx.DrawImage(form, box);
form.PageNumber++;
}
}
I then save the output document. I will send on the test Visual Studio template with my findings. Thanks again guys, hopefully you can point me in the right direction on this one.