PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Nov 14, 2019 3:37 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Hi

Can somebody confirm if this code is correct for filling an entire A4 page using an image (not using original aspect ratio of the image):

Code:
Image image = section.AddImage(fileName);
//DIN A4. Width is 21 cm, height is 29.7 cm.
image.Height = "29.7cm";
image.Width = "21cm";
image.RelativeHorizontal = RelativeHorizontal.Page;
image.RelativeVertical = RelativeVertical.Page;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Left;


Is there something missing in the code or wrong. Or is 100% correctly to do this?


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 14, 2019 3:47 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
If I add an image like this, a previous page of the PDF is overwritten by the image.

Why is that?

I tried creating a new section before adding the image and adding the image to the new section, but it doesn't work.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 14, 2019 4:33 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Jessica wrote:
If I add an image like this, a previous page of the PDF is overwritten by the image.

Why is that?
You do not add a pagebreak before adding the image, so the image is added to the current page and there may be some overlaps with other contents.
No need to add a new section if you only want a new page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 14, 2019 7:00 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Thomas Hoevel wrote:
Jessica wrote:
If I add an image like this, a previous page of the PDF is overwritten by the image.

Why is that?
You do not add a pagebreak before adding the image, so the image is added to the current page and there may be some overlaps with other contents.


If I make a new paragraph just before adding the image, is the pagebreak needed then?


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 14, 2019 7:09 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
Jessica wrote:
Hi

Can somebody confirm if this code is correct for filling an entire A4 page using an image (not using original aspect ratio of the image):

Code:
Image image = section.AddImage(fileName);
//DIN A4. Width is 21 cm, height is 29.7 cm.
image.Height = "29.7cm";
image.Width = "21cm";
image.RelativeHorizontal = RelativeHorizontal.Page;
image.RelativeVertical = RelativeVertical.Page;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Left;


Is there something missing in the code or wrong. Or is 100% correctly to do this?


Can somebody confirm?


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 15, 2019 7:31 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Jessica wrote:
Can somebody confirm?
I'd have to run that code on my computer to confirm it. But why should I spend 20 minutes to turn this code snippet into a program and try it?

But maybe someone else will confirm it.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Sat Nov 16, 2019 7:45 pm 
Offline

Joined: Sun Nov 03, 2019 7:51 pm
Posts: 47
TH-Soft wrote:
Jessica wrote:
Can somebody confirm?
I'd have to run that code on my computer to confirm it. But why should I spend 20 minutes to turn this code snippet into a program and try it?


Because I trust you, you have experience with MigraDoc :D If you say it works, then I better believe it. I'm not sure because I can't see if the image is really completely drawn (but I don't see page background anymore)


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 18, 2019 10:13 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Jessica wrote:
If you say it works, then I better believe it.
Code looks good, but without testing it in a debugger I cannot be sure it actually works.
I produced lots of code that didn't work as expected. :wink:

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 152 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