"Illegal characters in path" during HTML-to-PDF to Conversion

Last post 12-22-2010, 9:26 AM by john.szucs. 5 replies.
Sort Posts: Previous Next
  •  12-15-2010, 11:52 PM 274131 in reply to 274616

    "Illegal characters in path" during HTML-to-PDF to Conversion .NET

    I am currently evaluating the Aspose.Total package for integration into a product that my company is developing. I began the evaluation with HTML-to-PDF conversion with Aspose.Pdf, based on the sample code in the knowledge base article entitled "HTML to PDF using InLineHTML."

    The Pdf.Save() method throws an ArgumentException with the message "Illegal characters in path." I searched the forums and saw that some other users experienced similar issues. One thread suggested that Version 4.8.0 of Aspose.Pdf.dll fixed issues like this, so I double-checked my version of the library and that is indeed the version that I am running.

    See below for my code. When I call my function with http://en.wikipedia.org/wiki/Main_Page as the url parameter it should be functionally identical to the code in your knowledge base article. A variant of this function which attempts to save the PDF document to a MemoryStream (which is my actual intent for integration into our product) fails in the same way. Including or removing the setting of the ImgUrl property also has no effect on the behavior. The c:\temp folder used in my code below does, in fact, exist.

    Please respond with a solution as soon as possible. We are very interested in your suite, but will not be able to make a purchase until I can successfully complete my evaluation.

    --
    John J. Szucs, Venio, Inc., http://www.myvenio.com
    Venio: Achieve the Vision

    -----

            public static byte[] GetPageContentAsPdf(string url)
            {
                //  Create a Web Request object to connect to remote URL
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                // 10-second timeout period
                request.Timeout = 10000; /* milliseconds */

                //  Retrieve request info headers
                HttpWebResponse localWebResponse = (HttpWebResponse)request.GetResponse();

                //  Use Windows default code page
                Encoding encoding = Encoding.GetEncoding(1252);

                //  Read the contents of response into StreamReader object
                StreamReader localResponseStream = new StreamReader(localWebResponse.GetResponseStream(), encoding);

                //  Instantiate a PDF document object
                Pdf pdf = new Pdf();

                //  Add a new section to the PDF document
                Aspose.Pdf.Section section = pdf.Sections.Add();

                //  Create text paragraphs containing HTML text
                Aspose.Pdf.Text text2 = new Aspose.Pdf.Text(section, localResponseStream.ReadToEnd());
                //  Enable HTML formatting
                text2.IsHtmlTagSupported = true;

                // Add text to section
                section.Paragraphs.Add(text2);

                //  HACK: Hard-coded path
                pdf.HtmlInfo.ImgUrl = @"http://en.wikipedia.org";

                //  Save PDF document to a temporary file
                //  HACK: Hard-coded path
                pdf.Save(@"c:\temp\test.pdf");

                //  Close response and associated stream
                localWebResponse.Close();
                localResponseStream.Close();

                //  Return resulting PDF document in memory
                return null;
            }


    ---
    John J. Szucs
    Chief Technology Officer,
    http://www.veniolabs.com
    Venio: Achieve the Vision
     
  •  12-17-2010, 2:31 PM 274480

    "Illegal characters in path" during HTML-to-PDF to Conversion .NET

    I am currently evaluating the Aspose.Total package for integration into a product that my company is developing. I began the evaluation with HTML-to-PDF conversion with Aspose.Pdf, based on the sample code in the knowledge base article entitled "HTML to PDF using InLineHTML."

    The Pdf.Save() method throws an ArgumentException with the message "Illegal characters in path." I searched the forums and saw that some other users experienced similar issues. One thread suggested that Version 4.8.0 of Aspose.Pdf.dll fixed issues like this, so I double-checked my version of the library and that is indeed the version that I am running.

    See below for my code. When I call my function with http://en.wikipedia.org/wiki/Main_Page as the url parameter it should be functionally identical to the code in your knowledge base article. A variant of this function which attempts to save the PDF document to a MemoryStream (which is my actual intent for integration into our product) fails in the same way. Including or removing the setting of the ImgUrl property also has no effect on the behavior. The c:\temp folder used in my code below does, in fact, exist.

    Please respond with a solution as soon as possible. We are very interested in your suite, but will not be able to make a purchase until I can successfully complete my evaluation.

    --
    John J. Szucs, Venio, Inc., http://www.myvenio.com
    Venio: Achieve the Vision

    -----

            public static byte[] GetPageContentAsPdf(string url)
            {
                //  Create a Web Request object to connect to remote URL
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                // 10-second timeout period
                request.Timeout = 10000; /* milliseconds */

                //  Retrieve request info headers
                HttpWebResponse localWebResponse = (HttpWebResponse)request.GetResponse();

                //  Use Windows default code page
                Encoding encoding = Encoding.GetEncoding(1252);

                //  Read the contents of response into StreamReader object
                StreamReader localResponseStream = new StreamReader(localWebResponse.GetResponseStream(), encoding);

                //  Instantiate a PDF document object
                Pdf pdf = new Pdf();

                //  Add a new section to the PDF document
                Aspose.Pdf.Section section = pdf.Sections.Add();

                //  Create text paragraphs containing HTML text
                Aspose.Pdf.Text text2 = new Aspose.Pdf.Text(section, localResponseStream.ReadToEnd());
                //  Enable HTML formatting
                text2.IsHtmlTagSupported = true;

                // Add text to section
                section.Paragraphs.Add(text2);

                //  HACK: Hard-coded path
                pdf.HtmlInfo.ImgUrl = @"http://en.wikipedia.org";

                //  Save PDF document to a temporary file
                //  HACK: Hard-coded path
                pdf.Save(@"c:\temp\test.pdf");

                //  Close response and associated stream
                localWebResponse.Close();
                localResponseStream.Close();

                //  Return resulting PDF document in memory
                return null;
            }


    This message was posted using Email2Forum by haley.stuart.
    ---
    John J. Szucs
    Chief Technology Officer,
    http://www.veniolabs.com
    Venio: Achieve the Vision
     
  •  12-20-2010, 5:14 AM 274616 in reply to 274480

    Re: "Illegal characters in path" during HTML-to-PDF to Conversion

    Hello John,

    Thanks for using our products and sorry for replying you late.

    The feature of converting web URL into PDF format is not stable. In fact the method shared in live documentation is a workaround. Nevertheless, the original requirement of converting URL into PDF format is already logged in our issue tracking system as PDFNET-14508. Our development team is looking into the details of this requirement and as soon as we have made some definite progress towards its implementation, we would be pleased to update you with the status of correction. We apologize for your inconvenience.

    Please be patient and spare us little time.


    Nayyer Shahbaz
    Support Developer, Aspose Sialkot Team
    About Us
    Contact Us

    Keep in touch! We're on Twitter and Facebook
     
  •  12-20-2010, 8:56 AM 274643 in reply to 274616

    Re: "Illegal characters in path" during HTML-to-PDF to Conversion

    Thanks for your reply. Can any of the other products in the Aspose.Total suite meet this requirement?

    -- John

    ---
    John J. Szucs
    Chief Technology Officer,
    http://www.veniolabs.com
    Venio: Achieve the Vision
     
  •  12-22-2010, 2:40 AM 275032 in reply to 274643

    Re: "Illegal characters in path" during HTML-to-PDF to Conversion

    Hi John,

     

    Thanks for your interest in Aspose products. You can use Aspose.Words to convert HTML to PDF. For example you can use code like the following:

     

    string url = "http://localhost/mysite/default.html";

    //Prepare the web page we will be asking for

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    request.Method = "GET";

    request.ContentType = "application/msword";

    request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";

    //Execute the request

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    //We will read data via the response stream

    Stream resStream = response.GetResponseStream();

    //Write content into the MemoryStream

    BinaryReader resReader = new BinaryReader(resStream);

    MemoryStream docStream = new MemoryStream(resReader.ReadBytes((int)response.ContentLength));

    //Create document

    Aspose.Words.Document doc = new Aspose.Words.Document(docStream);

    //Save document

    doc.Save(@"Test001\out.pdf");

     

    Hope this helps.

     

    Best regards,


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  12-22-2010, 9:26 AM 275094 in reply to 275032

    Re: "Illegal characters in path" during HTML-to-PDF to Conversion

    Alexey,

    Thanks for the response. I tried this and it does work, but the fidelity of the conversion process is nowhere near as good as I've seen with dedicated HTML-to-PDF converters or with Aspose.Words own conversion of Word documents to PDF (which I am thoroughly impressed by).

    At this point, I'm ready to close this issue. I think that for our project, we're going to have to license Aspose.Total for document conversion and separately license a dedicated HTML-to-PDF converter for high-fidelity capture of Web content.

    Thanks for your help!

    -- John

    ---
    John J. Szucs
    Chief Technology Officer,
    http://www.veniolabs.com
    Venio: Achieve the Vision
     
View as RSS news feed in XML