View previous topic :: View next topic |
Author |
Message |
carter
Joined: 10 Mar 2009 Posts: 2
|
Posted: Tue Mar 10, 2009 6:33 pm Post subject: PDFDocument.Save possibly failing. |
|
|
I'm running pdfsharp on a few terminals and about 5-10 times a day i'm finding 0kb pdf files that are being saved. The logic i have is inside a try/catch and my software isn't reporting any errors. I checked out the source for the pdfdocument object and i found under the public void Save(Stream stream, bool closeStream) there is just a try/finally. So it would seem that if there is any execption whatsoever then it would get ignored. I could check the length of the stream to check to see if the stream has been successfully written to, but what if the write fails 4kb through? Also, i'd like to know what the exception is so i could find out whether it is a permissions problem, os problem, or software problem. Below is the code i am using.
Code: | FileStream ^fs = File::Create(sFileNamePath);
fs->SetLength(0);
PdfDocument ^pdfDocument = gcnew PdfDocument(fs);
for each (Image ^img in arrImages)
{
PdfPage ^page = pdfDocument->AddPage();
page->Orientation = PdfSharp::PageOrientation::Landscape;
XGraphics ^graphics = XGraphics::FromPdfPage(page);
XImage ^xImage = XImage::FromGdiPlusImage(img);
graphics->DrawImage(xImage, Point(10, 10));
}
pdfDocument->Save(fs, false); |
|
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Wed Mar 11, 2009 9:06 am Post subject: Re: PDFDocument.Save possibly failing. |
|
|
Hi!
carter wrote: | I checked out the source for the pdfdocument object and i found under the public void Save(Stream stream, bool closeStream) there is just a try/finally. So it would seem that if there is any execption whatsoever then it would get ignored. |
I don't think that exceptions are ignored by try/finally without catch.
Could be tested by adding something like
Code: | catch/*(Exception ex)*/
{
throw;
} |
to the try/finally statements. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
carter
Joined: 10 Mar 2009 Posts: 2
|
Posted: Wed Mar 11, 2009 3:23 pm Post subject: Re: PDFDocument.Save possibly failing. |
|
|
Thomas Hoevel wrote: | I don't think that exceptions are ignored by try/finally without catch. |
You're right. I thought for sure that try/finally was the equivalent to "On Error Resume.." in vb. I'll do more testing and see what i can come up with. |
|
Back to top |
|
|
|