PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 23, 2019 4:23 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Mar 20, 2015 1:06 pm 
Offline

Joined: Fri Mar 20, 2015 1:00 pm
Posts: 13
Using this code I'm able to create a pdf using version 1.32

Code:
var doc = new PdfDocument();
var p = doc.AddPage();
p.Size = PageSize.A4;
using (XImage xImg = Image.FromFile(@"c:\temp\test.jpg"))
{
    using (XGraphics xGfx = XGraphics.FromPdfPage(p))
    {
        xGfx.DrawImage(xImg, new XRect(0.0, 197.875, 595, 446.25), new XRect(0, 0, p.Width, p.Height), XGraphicsUnit.Point);
    }
    p.Close();

}
doc.Save(@"c:\temp\" + Guid.NewGuid().ToString() + ".pdf");
doc.Close();


But in version 1.50 Beta it ends with the following exception:
Code:
Could not find file 'C:\temp\testproject\bin\Debug\edff2edc-82ca-4b1b-9e28-3dba72f52865'.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.OpenRead(String path)
   at PdfSharp.Pdf.Advanced.PdfImage.InitializeJpeg()
   at PdfSharp.Pdf.Advanced.PdfImage..ctor(PdfDocument document, XImage image)
   at PdfSharp.Pdf.Advanced.PdfImageTable.GetImage(XImage image)
   at PdfSharp.Pdf.PdfPage.GetImageName(XImage image)
   at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.GetImageName(XImage image)
   at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.Realize(XImage image)
   at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawImage(XImage image, XRect destRect, XRect srcRect, XGraphicsUnit srcUnit)
   at PdfSharp.Drawing.XGraphics.DrawImage(XImage image, XRect destRect, XRect srcRect, XGraphicsUnit srcUnit)


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 21, 2015 9:02 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 316
johnzered wrote:
But in version 1.50 Beta it ends with the following exception[...]
WPF build? GDI+ build? Core build?
Does it happen with all JPEG images or just with some?

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 22, 2015 9:58 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 316
Probably it will work using "XImage xImg = XImage.FromFile" instead of "XImage xImg = Image.FromFile".

Both versions should work, but the former will work better anyway as it gives PDFsharp more control.

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


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 23, 2015 8:00 am 
Offline

Joined: Fri Mar 20, 2015 1:00 pm
Posts: 13
() => true wrote:
johnzered wrote:
But in version 1.50 Beta it ends with the following exception[...]
WPF build? GDI+ build? Core build?
Does it happen with all JPEG images or just with some?

GDI+ build. The Core build can only get image from stream, I think? When I tested the core build using a stream it did work.

() => true wrote:
Probably it will work using "XImage xImg = XImage.FromFile" instead of "XImage xImg = Image.FromFile".

Both versions should work, but the former will work better anyway as it gives PDFsharp more control.

Yes using XImage.FromFile works. But using the same image and Image.FromFile worked fine in 1.32 so something has changed. Just wanted to point that out.

I've included an image giving me problems but I do not think it's image specific.


Attachments:
test2.jpg
test2.jpg [ 21.32 KiB | Viewed 5599 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 26, 2015 9:45 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 316
johnzered wrote:
But using the same image and Image.FromFile worked fine in 1.32 so something has changed. Just wanted to point that out.
The image handling routines in PDFsharp worked fine under Windows XP, but some JPEG files caused problems under Windows 7 and later. Thanks, M$!

Thank you, John, for your feedback. I was able to replicate the problem - and I hope I fixed it. Will forward my fix to the PDFsharp team.
Image.FromFile will work with the next (beta) version of PDFsharp 1.50 (don't ask me for an ETA), but XImage.FromFile is the recommended way.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 02, 2015 10:39 am 
Offline

Joined: Fri Mar 20, 2015 1:00 pm
Posts: 13
() => true wrote:
johnzered wrote:
But using the same image and Image.FromFile worked fine in 1.32 so something has changed. Just wanted to point that out.
The image handling routines in PDFsharp worked fine under Windows XP, but some JPEG files caused problems under Windows 7 and later. Thanks, M$!

Thank you, John, for your feedback. I was able to replicate the problem - and I hope I fixed it. Will forward my fix to the PDFsharp team.
Image.FromFile will work with the next (beta) version of PDFsharp 1.50 (don't ask me for an ETA), but XImage.FromFile is the recommended way.


Thank you, it seems to be working now with beta 2. I do still have som issues using these two methods:
XImage xImg1 = XImage.FromGdiPlusImage(myImage)
XImage xImg2 = Image.FromStream(myMemoryStream)

I only have one problematic image and I'm not sure if I can share it as it is a private document/image.

As you said you have better control when using XImage.FromStream etc. why not just remove the possibilty to create an XImage instance from an Image?


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 05, 2015 10:04 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2953
Location: Cologne, Germany
johnzered wrote:
As you said you have better control when using XImage.FromStream etc. why not just remove the possibilty to create an XImage instance from an Image?
AFAIK it works for all images under XP and for the vast majority of images under later Windows versions.

If we no longer support Image, people who just have an Image will have to save that Image to a stream - and they will get the same problem: works under XP, works for most images under later OS versions.

Maybe we'll mark those functions as deprecated, pointing out the risk that comes with them.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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