←Select platform

PDFJavaScript Structure

Summary

Contains the properties of a single PDF JavaScript action.

Syntax
C#
C++/CLI
Java
Python
[SerializableAttribute()] 
public struct PDFJavaScript 
public class PDFJavaScript 
[SerializableAttribute()] 
public value class PDFJavaScript : public System.ValueType  
class PDFJavaScript: 
Remarks

The PDFJavaScript structure contains the properties of a single PDF JavaScript action. The JavaScript actions are stored as an array and are not part of any page. They are typically processed when the file is opened and before any image is shown.

Each JavaScript action has a name and the javascript code. The array is sorted in ascending order based on the name. The actions get executed in the order in which they are read. So to ensure the actions get executed in correct order, make sure the names reflect the desired order. The name comparison is not case sensitive. If one name is the beginning of another name, the shorter name will be written first.

So, if one action is called "name" and the other "name1", "name" will be considered to be "smaller" than "name1".

The array of JavaScript actions will be sorted in ascending order based on the name, so they might not be written in the order in which you put them in the array.

The JavaScript action has the following properties to represent its appearance:

  • Name: The name of the JavaScript action. The name determines the order and can also be used from inside the PDF file to identify an action.

  • Code: The actual JavaScript code, which will be interpreted by the JavaScript engine in the viewer.

Both of these properties are strings.

Example
C#
Java
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
 
 
public void TestExtractJavaScript_string_string() 
{ 
   string fileName = Path.Combine(LEAD_VARS.ImagesDir, "leadtools.pdf"); 
   IList<PDFJavaScript> list = PDFFile.ExtractJavaScript(fileName, null); 
 
   if (list == null || list.Count == 0) 
      Console.WriteLine("The source files does not have any javaScript"); 
   else 
   { 
      Console.WriteLine($"The source files has {list.Count} javascript actions"); 
      for (int i = 0; i < list.Count; i++) 
      { 
         Console.WriteLine($"  [{i}] Name = {list[i].Name}"); 
         Console.WriteLine($"  [{i}] Code = {list[i].Code}\n"); 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.ByteArrayInputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.FileReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.nio.file.Files; 
import java.nio.file.Paths; 
import java.nio.file.StandardCopyOption; 
import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 
import java.util.Scanner; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.pdf.*; 
 
 
public void pdfFileExtractJavaScriptExample() { 
 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String fileName = combine(LEAD_VARS_IMAGES_DIR, "leadtools.pdf"); 
 
   List<PDFJavaScript> list = PDFFile.extractJavaScript(fileName, null); 
 
   if (list == null || list.size() == 0) 
      System.out.println("The source files does not have any javaScript"); 
   else { 
      System.out.println("The source files has " + list.size() + " javascript actions"); 
      for (int i = 0; i < list.size(); i++) { 
         System.out.println("  [" + i + "] Name = " + list.get(i).getName()); 
         System.out.println("  [" + i + "] Code = " + list.get(i).getCode() + "\n"); 
      } 
   } 
 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.