PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Missing or crop image in PDFSharp 1.52rc2a
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3884
Page 1 of 1

Author:  boba21 [ Mon Dec 03, 2018 3:07 am ]
Post subject:  Missing or crop image in PDFSharp 1.52rc2a

Hi, I found an issue when using your PDFSharp 1.52rc2a when drawing an image.
Here the code I'm using for generate the pdf. Both version I'm using this code, the different only PDFSharp version.
Code:
PdfDocument document = new PdfDocument();
document.Options.ColorMode = PdfColorMode.Cmyk; // set colour sep as original

// Create an empty page
PdfPage page = document.AddPage();
page.Size = PageSize.A4;

XGraphics gfx = XGraphics.FromPdfPage(page);

// get the image
XImage image = XImage.FromFile("D:\\sample_image.pdf");

double imageCenter_X = image.PointWidth / 2;
double pageCenter_X = page.Width / 2;
double center_X = pageCenter_X - imageCenter_X;

// draw the image - 1st
gfx.DrawImage(image, center_X, 60);

// draw the text  - 2nd
XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
gfx.DrawString("Using: XBrushes.Black | Processed Image Drawn First", font, XBrushes.Black, pageCenter_X, 20, XStringFormats.Center);
gfx.DrawString("PDFSharp 1.32.3057", font, XBrushes.Black, pageCenter_X, 40, XStringFormats.Center);

// Save the pdf document...
string filename = "D:\\Test\\PDFOutput_" + string.Format("{0:ddMMyyyy_HHmmss}.pdf", DateTime.Now);

document.Info.Title = filename;
document.Save(filename);


The pdf generated using PDFSharp 1.32.3057
Attachment:
PDFSharp 1.32.3057.PNG
PDFSharp 1.32.3057.PNG [ 72.6 KiB | Viewed 454 times ]


The pdf generated using PDFSharp 1.50.4845-RC2a
Attachment:
PDFSharp 1.50.4845-RC2a.PNG
PDFSharp 1.50.4845-RC2a.PNG [ 62.87 KiB | Viewed 454 times ]


In both generated pdf, I draw the image first then I draw text. The 1.32 version give the correct image output, but 1.5 give a crop output.
The image crop and seem like transparent, I open the gridlines in Adobe Reader to display the missing image.

Author:  boba21 [ Mon Dec 03, 2018 3:44 am ]
Post subject:  Re: Missing or crop image in PDFSharp 1.52rc2a

Found another issue, when generate pdf using PDFSharp 1.32.
I draw the text first, set to purple colour (Xbrushes.Purple) then draw the image after the text.
I just change the arrangement to draw text first and image second.
Below is the code:
Code:
PdfDocument document = new PdfDocument();
document.Options.ColorMode = PdfColorMode.Cmyk; // set colour sep as original

// Create an empty page
PdfPage page = document.AddPage();
page.Size = PageSize.A4;

XGraphics gfx = XGraphics.FromPdfPage(page);

// get the image
XImage image = XImage.FromFile("D:\\sample_image.pdf");

double imageCenter_X = image.PointWidth / 2;
double pageCenter_X = page.Width / 2;
double center_X = pageCenter_X - imageCenter_X;

// draw the text  - 1st
XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
gfx.DrawString("Using: XBrushes.Purple| Processed Image Drawn First", font, XBrushes.Purple, pageCenter_X, 20, XStringFormats.Center);
gfx.DrawString("PDFSharp 1.32.3057", font, XBrushes.Purple, pageCenter_X, 40, XStringFormats.Center);

// draw the image - 2nd
gfx.DrawImage(image, center_X, 60);

// Save the pdf document...
string filename = "D:\\Test\\PDFOutput_" + string.Format("{0:ddMMyyyy_HHmmss}.pdf", DateTime.Now);

document.Info.Title = filename;
document.Save(filename);


The result will give me an image mix up with the purple colour.
The image will reflex based on the last colour set to the text. So, if I set last colour to green, the image will have green colour.
Here the screenshot of the pdf generated when draw text first and image later.
Attachment:
PDFSharp 1.32.3057 - purple.PNG
PDFSharp 1.32.3057 - purple.PNG [ 77.81 KiB | Viewed 450 times ]

Author:  () => true [ Mon Dec 03, 2018 7:34 am ]
Post subject:  Re: Missing or crop image in PDFSharp 1.52rc2a

Please use the IssueSubmissionTemplate to allow us to replicate the issue.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/