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 ...