0

I'm trying to do some simple DOM manipulation when a page is rendered as a PDF using ABCPdf. I followed what they document here: http://www.websupergoo.com/helppdf9net/source/5-abcpdf/xhtmloptions/2-properties/usescript.htm

But when I try something as simple as the following:

var doc = new Doc();
doc.HtmlOptions.UseScript = true;
doc.HtmlOptions.UseNoCache = true;
doc.HtmlOptions.PageCachePurge();
doc.HtmlOptions.OnLoadScript = @"var reportElms = document.getElementsByClassName(""report"");";
doc.Page = doc.AddPage();
doc.AddImageUrl(Url.Action("TestPdf", "Pdf", new { }, "http"));

I get the exception:

Unable to render HTML. Unable to apply JScript.
COM error 80020101.

Script 'var reportElms = document.getElementsByClassName("report");'.

Any thoughts as to what I'm doing wrong?

Not even the built in functions work

I'm even getting the same exception with the following script:

doc.HtmlOptions.OnLoadScript = @"
    window.ABCpdf_RenderWait(); 
    window.ABCpdf_RenderComplete();";

Btw, I'm using version 8 because that's what we have a licence for.

Edit:

I was missing the .external for the ABCpdf_RenderWait() and ABCpdf_RenderComplete() calls. It works if you reference them properly (imagine that):

doc.HtmlOptions.OnLoadScript = @"
    window.external.ABCpdf_RenderWait(); 
    window.external.ABCpdf_RenderComplete();";

Though as I mention in my answer, there are a lot of security hoops that need to be jumped through for IE also.

Josh Russo
  • 3,080
  • 2
  • 41
  • 62
  • Do you use Gecko or IE? Did you try the window.ABCpdf_go example? – devio Feb 03 '13 at 19:26
  • The default is IE and when I tried to switch it complained about a missing Gecko DLL, so I'm just sticking with IE. – Josh Russo Feb 03 '13 at 19:36
  • Guess I cannot help you then. I switched to Gecko as I experienced several problems, such as inconsistencies depending on OS/IE. Maybe my posts can help you in any way http://devio.wordpress.com/category/abcpdf/ – devio Feb 04 '13 at 07:57

1 Answers1

0

So I didn't actually get the IE engine to execute JavaScript the way I wanted but I was able to find a solution using the Gecko engine. The original NuGet install did not include the Gecko DLL, so I just downloaded the standalone install and added the DLLs manually.

After that everything worked exactly as expected.

I believe that the IE engine didn't work because it requires a lot of security configuration, because the FAQs spend a lot of time discussing debugging of security: http://www.websupergoo.com/support.htm#6.7

Josh Russo
  • 3,080
  • 2
  • 41
  • 62