Karl
Karl

Reputation: 1854

Can ABCpdf create a PDF from a page created with Javascript?

A visitor to my website can click on a "Print Preview" button. Javascript code opens a Window and using document.writelin() will create a html page that displays dynamic content (basically, the user is looking at a report. Here's code snippet to show you what I mean:

printerWindow = window.open("");  
printerWindow.document.writeln("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0   Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");  
printerWindow.document.writeln("<html>");  
printerWindow.document.writeln("<head>");  
printerWindow.document.writeln("<title>Report Title</title>");  
printerWindow.document.writeln("<link href='./css/schedule_print_preview.css'  type='text/css' rel='stylesheet'>");  
printerWindow.document.writeln("<link href='./css/schedule_printer.css' rel='stylesheet' type='text/css' media='print'>");  
printerWindow.document.writeln("<script type='text/javascript'>");  
printerWindow.document.writeln("function printcalc() {");  
printerWindow.document.writeln("window.print();");  
printerWindow.document.writeln("};");  
printerWindow.document.writeln("<\/script>");  
printerWindow.document.writeln("</head>");  
printerWindow.document.writeln("<body>");  
printerWindow.document.writeln("<div class='btns'>");  

{...}

I would like to include a "Download PDF" link on this page so visitor can save report to a PDF.

Is this possible with ABCpdf 8.1? (I'm evaluating it.) The problem I'm having is figuring out what example is the closest one to what I need to do. Any suggestions? TIA.

Upvotes: 1

Views: 2354

Answers (1)

tentonipete
tentonipete

Reputation: 5080

I think you should be able to. There are some settings in the c# which will help.

You need to set the

doc.HtmlOptions.UseScript = true; 

this will enable javascript to run.

it's probably worth setting the timeout to give it more time to finish loading

doc.HtmlOptions.Timeout = 10000;

and i've always had better results with the gecko rendering engine

doc.HtmlOptions.Engine = EngineType.Gecko;

Upvotes: 4

Related Questions