XHtmlOptions UseScript Property. Whether to enable JavaScript and VBScript. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

 

Type Default Value Read Only Description
[C#] bool

[Visual Basic]
Boolean
false No Whether to enable JavaScript and VBScript.

 

   

Notes
 

This property determines whether JavaScript and VBScript are enabled.

By default, client-side script such as JavaScript is disabled when rendering HTML documents.

This is done for good security reasons, and we strongly recommend that you do not change this setting.

However, if you are sure that your source documents do not pose a security risk, you can enable Script using this setting.

If you have a server edition of Windows (e.g. Windows Server 2008) and are using the MSHTML engine, you may need to also disable Enhanced Security Configuration for user running the program/application pool to allow JavaScript execution.

Script-Accessible Functions and Properties. These are functions and properties that script inside HTML can access. The function signatures shown are in C#-like syntax. You'll need to pass in the correct number of arguments.

MSHTML only   window.external.ABCpdf_RenderWait – Delays ABCpdf's rendering of the HTML page.

Syntax
  bool ABCpdf_RenderWait()

Params
 
Name Description
return True if ABCpdf waits (i.e. the function succeeds), otherwise false.

Notes
  When this function is called before the page load is considered complete, the page load is not considered complete until ABCpdf_RenderComplete is called. This function returns false if ABCpdf_RenderComplete has been called. This is useful if the page relies on timeout/asynchronous events (AJAX).

 

MSHTML only   window.external.ABCpdf_RenderComplete – Resumes ABCpdf's rendering of the HTML page.

Syntax
  bool ABCpdf_RenderComplete()
bool ABCpdf_RenderComplete(bool force)

Params
 
Name Description
force Whether ABCpdf ignores normal indications of page load completion. The default value is false.
return True if ABCpdf resumes rendering as requested (i.e. the function succeeds), otherwise false.

Notes
  This function can be called whether ABCpdf_RenderWait has/has not been called. If force is false, ABCpdf resumes normal rendering. If force is true, ABCpdf starts rendering immediately, ignoring all other indications of page load completion. This function returns false if force is false and the function has been previously called with force true. This is useful if the page relies on timeout/asynchronous events (AJAX).

 

Gecko only   window.ABCpdf_go – Specifies whether ABCpdf proceeds to render the HTML page.

Syntax
  bool ABCpdf_go

Params
 
Value Description
undefined (initial value), true ABCpdf proceeds to render the HTML page.
false ABCpdf waits.

Notes
  UseScript has to be true and OnLoadScript has to be non-empty for this property to be effectual. ABCpdf will wait for this property to be either undefined or true before rendering the HTML page. The whole HTML rendering operation is still subject to the Timeout property's value. Usually, this property is set to false in OnLoadScript and is also set to true in an event listener added in OnLoadScript. If assignments to this property are provided in both OnLoadScript and the script in the web page, please refer to the notes in OnLoadScript for the order of execution.

Example
 

[C#]
Doc doc = new Doc();
doc.HtmlOptions.Engine = EngineType.Gecko;
doc.HtmlOptions.UseScript = true;

// Render after 3 seconds
doc.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 3000); })();";

doc.AddImageUrl("http://www.websupergoo.com");
doc.Save(Server.MapPath("wsg.pdf"));

[Visual Basic]
Dim theDoc As Doc = New Doc()

theDoc.HtmlOptions.Engine = EngineType.Gecko
theDoc.HtmlOptions.UseScript = True

' Render after 3 seconds
theDoc.HtmlOptions.OnLoadScript = "(function(){ window.ABCpdf_go = false; setTimeout(function(){ window.ABCpdf_go = true; }, 3000); })();"

theDoc.AddImageUrl("http://www.websupergoo.com")
theDoc.Save(Server.MapPath("wsg.pdf"))

   

Example
 

The following example shows one method of crawling and transferring an entire site to PDF. Here, we use JavaScript to determine the links present on the page. However, you could equally well use the HtmlCallback to do the same thing.

[C#]
Doc theDoc = new Doc();
string theURL = "http://www.fbi.gov/";
// Set HTML options
theDoc.HtmlOptions.AddLinks = true;
theDoc.HtmlOptions.UseScript = true;
theDoc.HtmlOptions.PageCacheEnabled = false;
// JavaScript is used to extract all links from the page
theDoc.HtmlOptions.OnLoadScript = "var hrefCollection = document.all.tags(\"a\");" +
  "var allLinks = \"\";" +
  "for(i = 0; i < hrefCollection.length; ++i) {" +
  "if (i > 0)" +
  "  allLinks += \",\";" +
  "allLinks += hrefCollection.item(i).href;" +
  "};"+
  "document.documentElement.abcpdf = allLinks;";
// Array of links - start with base URL
ArrayList links = new ArrayList();
links.Add(theURL);
for (int i = 0; i < links.Count; i++) {
  // Stop if we render more than 20 pages
  if (theDoc.PageCount > 20)
    break;
  // Add page
  theDoc.Page = theDoc.AddPage();
  int theID = theDoc.AddImageUrl(links[i] as string);
  // Links from the rendered page
  string allLinks = theDoc.HtmlOptions.GetScriptReturn(theID);
  string[] newLinks = allLinks.Split(new char[] {','});
  foreach (string link in newLinks) {
    // Check to see if we allready rendered this page
    if (links.BinarySearch(link) < 0) {
      // Skip links inside the page
      int pos = link.IndexOf("#");
      if (! ( pos > 0 && links.BinarySearch(link.Substring(0, pos)) >= 0)) {
        if (link.StartsWith(theURL)) {
          links.Add(link);
        }
      }
    }
  }
  // Add other pages
  while (true) {
    theDoc.FrameRect();
    if (!theDoc.Chainable(theID))
      break;
    theDoc.Page = theDoc.AddPage();
    theID = theDoc.AddImageToChain(theID);
  }
}
// Link pages together
theDoc.HtmlOptions.LinkPages();
// Flatten all pages
for (int i = 1; i <= theDoc.PageCount; i++) {
  theDoc.PageNumber = i;
  theDoc.Flatten();
}
// Save the document
theDoc.Save(Server.MapPath("HtmlOptionsJavaScript.pdf"));
theDoc.Clear();

[Visual Basic]
Dim theDoc As Doc = New Doc()
Dim theURL As String = "http://www.fbi.gov/"
' Set HTML options
theDoc.HtmlOptions.AddLinks = True
theDoc.HtmlOptions.UseScript = True
theDoc.HtmlOptions.PageCacheEnabled = False
' JavaScript is used to extract all links from the page
theDoc.HtmlOptions.OnLoadScript = "var hrefCollection = document.all.tags(""a"");" + _
  "var allLinks = """";" + _
  "for(i = 0; i < hrefCollection.length; ++i) {" + _
  "if (i > 0)" + _
  "  allLinks += "","";" + _
  "allLinks += hrefCollection.item(i).href;" + _
  "};" + _
  "document.documentElement.abcpdf = allLinks;"
' Array of links - start with base URL
Dim links As ArrayList = New ArrayList()
links.Add(theURL)
Dim theID As Integer
For i As Integer = 0 To links.Count - 1
  ' Stop if we render more than 20 pages
  If theDoc.PageCount > 20 Then Exit For
  ' Add page
  theDoc.Page = theDoc.AddPage()
  theID = theDoc.AddImageUrl(links(i))
  ' Links from the rendered page
  Dim allLinks As String
  allLinks = theDoc.HtmlOptions.GetScriptReturn(theID)
  Dim newLinks() As String
  newLinks = allLinks.Split(New Char() {","})
  Dim link As String
  For Each link in newLinks
    ' Check to see if we allready rendered this page
    If links.BinarySearch(link) < 0 Then
      ' Skip links inside the page
      Dim pos As Integer
      pos = link.IndexOf("#")
      If Not ( pos > 0 And links.BinarySearch(link.Substring(0, pos)) >= 0) Then
        If link.StartsWith(theURL) Then links.Add(link)
      End If
    End If
  Next
  ' Add other pages
  Do
    theDoc.FrameRect()
    If Not theDoc.Chainable(theID) Then Exit Do
    theDoc.Page = theDoc.AddPage()
    theID = theDoc.AddImageToChain(theID)
  Loop
Next
' Link pages together
theDoc.HtmlOptions.LinkPages()
' Flatten all pages
For i As Integer = 1 To theDoc.PageCount
  theDoc.PageNumber = i
  theDoc.Flatten()
Next
' Save the document
theDoc.Save(Server.MapPath("HtmlOptionsJavaScript.pdf"))
theDoc.Clear()


HtmlOptionsJavaScript.pdf - [Page 1]

HtmlOptionsJavaScript.pdf - [Page 2]

HtmlOptionsJavaScript.pdf - [Page 3]

HtmlOptionsJavaScript.pdf - [Page 4]