Free Support Forum - aspose.com

Converting HTML to PDF Network error

Hello
We have a license for your Aspose.Total,NET

And when I tried to follow example of how to convert HTML to PDF provided at
https://docs.aspose.com/display/htmlnet/HTML+to+PDF+Conversion… I am getting an error

Here is my code

static void Main(string[] args)
{

        String InputHtml = @"C\temp\1005N_TemplateTest.htm";

        // File name for resultant PDF file
        string Resultant_output = @"C\temp\1005N_TemplateTest.pdf";
        // Create PdfRendering Options object
        Aspose.Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
        // The PageSetup also provides different properties i.e. FirstPage, LastPage, LeftPage, RightPage and they are used to setup (PageSize, Margin) for every page. 
        // In most cases, usage of setup any page is enough, but in some complicated cases, you may need to fine tune page settings. It can be done either by CSS styles or by using rendering options.
        // the size for drawing is in pixels
        pdf_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(400, 100));
        // Instantiate PdfDevice object while passing PdfRenderingOptions and resultant file path as arguments
        using (Aspose.Html.Rendering.Pdf.PdfDevice pdf_device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, Resultant_output))
        // Create HtmlRenderer object
        using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
        // Create HtmlDocument instance while passing path of already created HTML file
        using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(InputHtml))
        {
            // Render the output using HtmlRenderer
            renderer.Render(pdf_device, html_document);
        }

The error I am getting is “Network error occurred”

Here is the stacktrace
at Aspose.Html.Dom.Document.(ResponseMessage )
at Aspose.Html.HTMLDocument…ctor(RequestMessage request, Configuration configuration)
at Aspose.Html.HTMLDocument…ctor(String address)
at AsposeHTML.Program.Main(String[] args) in c:\users\nick\documents\visual studio 2017\Projects\AsposeHTML\AsposeHTML\Program.cs:line 29

What network error ? I am trying to run the sample code on my local machine. ?

Can you provide some guidance ?

Thank you.

@nick1234

Thanks for contacting support.

The path to HTML file in your code snippet, seems not in correct format (i.e the colon ‘:’ is missing.). Please use the file path correctly as follows:

String InputHtml = @"C:\temp\1005N_TemplateTest.htm";

In case issue still persists, please let us know.

That did not resolve the issue. Still getting Network error.
The error seems to be in the constructor of your Aspose.Html.Dom.Document object
on this instruction

Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(InputHtml)

at Aspose.Html.Dom.Document.(ResponseMessage )
at Aspose.Html.HTMLDocument…ctor(RequestMessage request, Configuration configuration)
at Aspose.Html.HTMLDocument…ctor(String address)
at AsposeHTML.Program.Main(String[] args) in c:\users\nick\documents\visual studio 2017\Projects\AsposeHTML\AsposeHTML\Program.cs:line 31

@nick1234

Thanks for writing back.

Would you please share the sample HTML file (in ZIP Archive) along with your environment details (i.e OS Version, Application Type, etc.). We will test the scenario in our environment and address it accordingly.

How do I attach the file ?
I didnt see a way to attach the file for this board.

@nick1234

Please click on upload button shown in the screenshot Upload_Files.png (8.9 KB), in order to attach files. Furthermore, you may also drag and drop files into post editor while composing reply.

1005N_Template.zip (13.9 KB)

Here is my input htm file.

The code that I used to run this and got the error is in the beginning of the thread.
A simple console dotnet app.

I am having the same error and it is driving me nuts! It works when I run it local, but not once I push to a server. I’m using a unc path for the file, if that makes any difference.

@nick1234

Thanks for sharing sample HTML file.

We have tested the scenario in our environment using your code snippet and HTML file. We were unable to notice any issue as the code generated PDF document correctly.

1005N_Template.pdf (99.6 KB

However, we have noticed that you were using “1005N_TemplateTest.htm” as file name in your code snippet - whereas it should be “1005N_Template.htm”, according to the file which you have shared. Please also note that we have changed width/height of page in code snippet, in order to fit the HTML content inside PDF Page properly:

pdf_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(792, 598));

Would you please confirm after checking the file name in your code at your side. In case you still face any issue, please share a sample console application which is able to replicate the issue. We will again test the scenario in our environment and address it accordingly.

@nutty2chat

Thanks for your inquiry.

We have tested the scenario in our environment using UNC path for the file, where file was located in the folder shared over network and we were unable to notice any issue. Please make sure that you are using correct path and location of the HTML file is accessible by your program.

In case the issue still persists, please share some details like server information, application type, API version, etc. - along with sample HTML file. We will test the scenario in our environment and address it accordingly.

While I was waiting… I went ahead and read the html content in as a string
and then to pdf from memory stream… So I am good now.

@nick1234

Thank you for your kind feedback.

We are glad to know that your issue has been resolved. Please feel free to contact us if you need any further assistance.