PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 1:56 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Dec 03, 2018 3:07 am 
Offline

Joined: Fri Jul 27, 2018 3:29 am
Posts: 19
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 3991 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 3991 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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 03, 2018 3:44 am 
Offline

Joined: Fri Jul 27, 2018 3:29 am
Posts: 19
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 3987 times ]


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 03, 2018 7:34 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 339
Please use the IssueSubmissionTemplate to allow us to replicate the issue.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 165 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group