PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

DrawImage hangs
http://forum.pdfsharp.de/viewtopic.php?f=2&t=2361
Page 1 of 1

Author:  kingcrim [ Mon Mar 11, 2013 9:32 pm ]
Post subject:  DrawImage hangs

I am trying to add page numbers to existing PDF files. I am using the GDI+ 1.32 assemblies from the zipped download.

The code in question is here:

string filename = outputDirectory + "Chart" + i + ".pdf";
PdfDocument outputDocument = new PdfDocument();
PdfPage page = outputDocument.AddPage();

XGraphics gfx = XGraphics.FromPdfPage(page);

XPdfForm form = XPdfForm.FromFile(filename);
form.PageNumber = i;
gfx.DrawImage(form, new XRect(0, 0, form.PointWidth, form.PointHeight));

When it calls DrawImage, it hangs and never returns.

I am able to add outlines in the same application, so it does not appear to be anything like permissions, etc.

Any ideas on what the cause could be, or how I could try to troubleshoot this?

TIA

jdn

Author:  Thomas Hoevel [ Tue Mar 12, 2013 9:12 am ]
Post subject:  Re: DrawImage hangs

Adding page numbers can be done based on the Watermark sample (without DrawImage).

But DrawImage should not hang. Does it hang with every PDF? Or just with some?
Do you run the code locally or on a server?

Not much we can do with just the small code snippet you gave us.

Author:  kingcrim [ Tue Mar 12, 2013 3:24 pm ]
Post subject:  Re: DrawImage hangs

"Does it hang with every PDF?"

Yes.

"Do you run the code locally or on a server?"

Locally.

"Not much we can do with just the small code snippet you gave us."

Yeah, that's the problem. That's all the code. Very simple and it doesn't work.

I got around it using a different technique, but it is troubling that it just doesn't work. I am deploying to Production in the next 10 days so hopefully the other stuff doesn't hang.

Author:  Thomas Hoevel [ Tue Mar 12, 2013 3:52 pm ]
Post subject:  Re: DrawImage hangs

Here's my test code, using the fw4.pdf that comes with PDFsharp:
Code:
static void Main(string[] args)
{

    string filename = @"..\..\fw4.pdf";
    PdfDocument outputDocument = new PdfDocument();
    PdfPage page = outputDocument.AddPage();

    XGraphics gfx = XGraphics.FromPdfPage(page);

    XPdfForm form = XPdfForm.FromFile(filename);
    form.PageNumber = 1;
    gfx.DrawImage(form, new XRect(0, 0, form.PointWidth, form.PointHeight));

    // Save the document...
    const string outputFilename = "HelloWorld.pdf";
    outputDocument.Save(outputFilename);
    // ...and start a viewer.
    Process.Start(outputFilename);
}
It did not hang!
"form.PageNumber" specifies which page of the input PDF will be drawn on the output PDF. Works fine with values 1 or 2, throws an exception with larger values (as it should as there are only 2 pages in the source PDF).

Maybe it's your exception handling that hangs ...

Author:  kingcrim [ Tue Mar 12, 2013 3:59 pm ]
Post subject:  Re: DrawImage hangs

Unfortunately, no. I step through the code and it hangs on that line.

I can get it to throw an exception by putting in a bogus number and it handles as expected.

Author:  Thomas Hoevel [ Tue Mar 12, 2013 4:09 pm ]
Post subject:  Re: DrawImage hangs

kingcrim wrote:
"Does it hang with every PDF?"
Yes.
It did not hang with the PDF I tried.

Author:  kingcrim [ Tue Mar 12, 2013 4:18 pm ]
Post subject:  Re: DrawImage hangs

Yes. On your machine.

Since you can't recreate it, you can't help.

Thanks anyway.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/