PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 8:47 am

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
 Post subject: DrawImage hangs
PostPosted: Mon Mar 11, 2013 9:32 pm 
Offline

Joined: Mon Mar 11, 2013 9:21 pm
Posts: 6
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


Top
 Profile  
Reply with quote  
 Post subject: Re: DrawImage hangs
PostPosted: Tue Mar 12, 2013 9:12 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: DrawImage hangs
PostPosted: Tue Mar 12, 2013 3:24 pm 
Offline

Joined: Mon Mar 11, 2013 9:21 pm
Posts: 6
"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.


Top
 Profile  
Reply with quote  
 Post subject: Re: DrawImage hangs
PostPosted: Tue Mar 12, 2013 3:52 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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 ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: DrawImage hangs
PostPosted: Tue Mar 12, 2013 3:59 pm 
Offline

Joined: Mon Mar 11, 2013 9:21 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: DrawImage hangs
PostPosted: Tue Mar 12, 2013 4:09 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
kingcrim wrote:
"Does it hang with every PDF?"
Yes.
It did not hang with the PDF I tried.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: DrawImage hangs
PostPosted: Tue Mar 12, 2013 4:18 pm 
Offline

Joined: Mon Mar 11, 2013 9:21 pm
Posts: 6
Yes. On your machine.

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

Thanks anyway.


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: Google [Bot] and 41 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