Subject: ImportHTML - System.Exception
Date: 2011-07-25 19:37:54
From: Chris B.R.
Source: importhtml-system-exception
----------------------------------------------------------------------

Objective: Convert HTML to PDF

Issue: Getting System.Exception error running in local IIS 5.1 (Windows XP Pro) or in server IIS 7.5 (Windows 2008 R2). No error when running in DEBUG mode in Visual Studio 2010.

Error Message:System.Exception: There was an error while loading the html file at ComponentPro.Pdf.PdfDocument.ImportHtml(String uri, String userName, String password, Html2PdfOptions options) at ComponentPro.Pdf.PdfDocument.ImportHtml(String uri, Html2PdfOptions options) at emsAbsenteeOnline.syssuperfile.testPDF(String inHTMLFile) in x:\xxxxxxxxx\xxxxxxxxxxx\xxxxxxxxx.aspx.cs:line 279

Source Code:

        private string testPDF(string inURI)
        {
           
            string outPDFname = "C:\\TEMP\\test.pdf";

            //Create a PDF document
            PdfDocument doc = new PdfDocument();

            //Set page margins
            doc.PageSettings.SetMargins(15, 15, 15, 15);

            //Set page orientation
            doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
            //doc.PageSettings.Orientation = PdfPageOrientation.Landscape;

            //Set rotation
            doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle0;
            doc.PageSettings.Size = PdfPageSize.Letter;

            //Add a page
            PdfPage page = doc.Pages.Add();

            //SizeF pageSize = page.GetClientSize();

            PdfUnitConvertor convertor = new PdfUnitConvertor();
            float width = -1;
            float height = -1;

            //Calculates the height and width of the pdf image
            AspectRatio dimension = AspectRatio.None;

            //dimension = AspectRatio.KeepHeight;
            //height = convertor.ConvertToPixels(page.GetClientSize().Height, PdfGraphicsUnit.Point);           
            dimension = AspectRatio.KeepHeight;
            height = convertor.ConvertToPixels(page.GetClientSize().Height, PdfGraphicsUnit.Point);
            width = convertor.ConvertToPixels(page.GetClientSize().Width * 2, PdfGraphicsUnit.Point);

            Html2PdfOptions options = new Html2PdfOptions();
            options.EnableJavaScript = true;
            options.AutoDetectPageBreak = false;
            options.EnableHyperlinks = false;
            options.Width = (int)width;
            options.Height = (int)height;
            options.SplitTextLines = false;
            options.AspectRatio = dimension;

            doc.ImportHtml(inURI, options);

            //Save the document.
            doc.Save(outPDFname);
            doc.Close();

        }

Tested URIs:
http://face2face.si.edu/my_weblog/2011/07/the-150th-anniversary-of-the-battle-of-bull-run.html
http://www.nasa.gov/audience/forstudents/index.html


Please help. Thanks,

Chris R.

---------------------------------------------------------------------- Note: This question has been asked on the Q&A forum of Thang Dang's fraudulent ComponentPro brand If you purchased anything from ComponentPro, you have been scammed. Contact the payment processor who sold you the license and ask for your money back. Back to ComponentPro Q&A Forum Index