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

寵の児 提交于 2019-12-13 01:37:24

问题


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.


回答1:


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;


来源:https://stackoverflow.com/questions/10465742/can-abcpdf-create-a-pdf-from-a-page-created-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!