Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Javascript

Javascript in PDF

Rate me:
Please Sign up or sign in to vote.
4.98/5 (35 votes)
7 May 2012CPOL6 min read 226K   5.8K   57  
This article describes how to use Javascript code to create interactive PDF documents.
using BitMiracle.Docotic.Pdf;

namespace JavascriptInPdf
{
    static class Names
    {
        public static void Run()
        {
            PdfDocument pdf = new PdfDocument();
            pdf.Open(Resources.NamesPdf);

            pdf.SharedScripts.Add(
                pdf.CreateJavaScriptAction(Resources.SynchronizeFields)
            );

            pdf.GetControl("name0").OnLostFocus = pdf.CreateJavaScriptAction("synchronizeFields(\"name0\", \"name1\");");
            pdf.GetControl("name1").OnLostFocus = pdf.CreateJavaScriptAction("synchronizeFields(\"name1\", \"name0\");");

            pdf.Save("NamesModified.pdf");
            System.Diagnostics.Process.Start("NamesModified.pdf");
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Bit Miracle
Russian Federation Russian Federation
Vitaliy Shibaev is a developer and co-founder of Bit Miracle, company developing the Docotic.Pdf, Jpeg2000.Net, LibTiff.Net libraries.

Docotic.Pdf - pure .NET library for PDF processing. It is a high-quality library for text extraction, PDF to image conversion, compressing PDF, and other PDF tasks.

Jpeg2000.Net - the library for encoding/decoding JPEG 2000 images in .NET.

Comments and Discussions