Convert HTML to PDF using PDFNet

Q: I am facing problem while converting report from html to pdf, details are below:

  1. While I am using your method HTML2PDF.Convert(doc, URL) for

url : https://stagin??? ?user=PMGR%

the Convert method returning false means some warning/error has been encountered, I couldn’t Identify, why it happening while I am trying same conversion with “Winnovative software" 's library, it seems to be working, but its quality is not so much good compare to yours due to that want to purchase your product, Please guide me where I am doing Mistake, code are below

lReportName = ReportName.Substring(0, ReportName.IndexOf(’&’)) + “_Pdftron.pdf”;

outFile = Path.Combine(Application.StartupPath, lReportName);

string pdfError = “”;

try

{

PDFNet.Initialize();

HTML2PDF.SetModulePath(Application.StartupPath);

using (PDFDoc doc = new PDFDoc())

{

// now convert a web page, sending generated PDF pages to doc

//if ( HTML2PDF.Convert(doc, host + page0) )

if (HTML2PDF.Convert(doc, URL))

doc.Save(outFile, SDFDoc.SaveOptions.e_linearized);

}

}

catch (Exception ex)

{

}

Its Working fine while I am setting Url to www.google.com etc , but its not solving my purpose.

A:

The code seems to be correct. However, I’m unable to test this properly as I get a blank page in my browser. Try the following suggestions.

  1. Call HTML2PDF.WebPageSettings.SetAllowPlugins(true)

  2. Try HTML2PDF.WebPageSettings.SetJavaScriptDelay(ms) // this will give the page time to load

Finally, if the above doesn’t help, try switching to the following code

using (PDFDoc doc = new PDFDoc()) {

// now convert a web page, sending generated PDF pages to doc

//if ( HTML2PDF.Convert(doc, host + page0) )

HTML2PDF converter = new HTML2PDF();

converter.InsertFromURL(URL);

if (converter.convert(doc))

doc.Save(outFile, SDFDoc.SaveOptions.e_linearized);

else

Console.WriteLine(converter.GetLog());

}

And send us the output from GetLog().

To clarify, the correct way to use the optional WebPageSettings (as
seen in the samples) is the following...

HTML2PDF converter = new HTML2PDF();
HTML2PDF.WebPageSettings settings = new HTML2PDF.WebPageSettings();
settings.SetAllowPlugins(true);
settings.SetJavaScriptDelay(2000); // give 2 seconds for JS
converter.InsertFromURL(URL, settings);
if (converter.convert(doc))
    doc.Save(outFile, SDFDoc.SaveOptions.e_linearized);
else
    Console.WriteLine(converter.GetLog());

This will help ensure that the website is allowed to process the
parameters in the url.