PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Dec 08, 2019 9:58 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Nov 25, 2019 8:25 pm 
Offline

Joined: Mon Nov 25, 2019 7:56 pm
Posts: 3
In version 1.50, I am trying to use XImage.FromGdiPlusImage() and it is not available for the selected image frame.

Image img = Image.FromFile(@"C:\\Multi_page.tif");
string destination = @"C:\\Multi_page.pdf";
PdfDocument document = new PdfDocument();

for (int pageIndex = 0; pageIndex < img.GetFrameCount(FrameDimension.Page); pageIndex++)
{
img.SelectActiveFrame(FrameDimension.Page, pageIndex);
PdfSharp.Drawing.XImage xImage = PdfSharp.Drawing.XImage.FromGdiPlusImage(img);
var page = new PdfPage();
if (xImage.PixelWidth > xImage.PointHeight)
{
page.Orientation = PageOrientation.Landscape;
}
else
{
page.Orientation = PageOrientation.Portrait;
}

document.Pages.Add(page);

PdfSharp.Drawing.XGraphics xgr = PdfSharp.Drawing.XGraphics.FromPdfPage(document.Pages[pageIndex]);
xgr.DrawImage(xImage, 0, 0);
}

What is the alternative that should be used?

Thanks so much!!


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 25, 2019 9:21 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 508
Location: CCAA
mnord wrote:
In version 1.50, I am trying to use XImage.FromGdiPlusImage() and it is not available for the selected image frame.
Where's the problem?
You have to take the GDI+ build of PDFsharp if you want to use GDI+-specific methods like XImage.FromGdiPlusImage().


Quote:
if (xImage.PixelWidth > xImage.PointHeight)
What's the point of comparing PixelWidth and PointHeight?

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 25, 2019 9:28 pm 
Offline

Joined: Mon Nov 25, 2019 7:56 pm
Posts: 3
TH-Soft: How do you select the GDI+ build of PDFSharp? It is not an option with the Nuget package.

As for the PixelWidth and PixelHeight, it is used to set the page orientation.

Thanks,
Marty


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 25, 2019 10:11 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 508
Location: CCAA
mnord wrote:
TH-Soft: How do you select the GDI+ build of PDFSharp? It is not an option with the Nuget package.
Try one of those:
https://www.nuget.org/packages/PDFsharp-gdi/
https://www.nuget.org/packages/PDFsharp-MigraDoc-GDI/

mnord wrote:
As for the PixelWidth and PixelHeight, it is used to set the page orientation.
I don't understand why you compare PixelWidth and PointHeight. Comparing PixelWidth with PixelHeight makes sense.

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 25, 2019 10:15 pm 
Offline

Joined: Mon Nov 25, 2019 7:56 pm
Posts: 3
TH-Soft: Thanks for the reply. I didn't know those options were possible.

I made a typo. It should have been PixelHeight instead of PointHeight. My goof.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 31 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