Click here to Skip to main content
15,882,017 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 225.8K   5.8K   57  
This article describes how to use Javascript code to create interactive PDF documents.
using BitMiracle.Docotic.Pdf;

namespace JavascriptInPdf
{
    public static class Demo
    {
        public static void Main(string[] args)
        {
            //helloWorld();
            //formWithDate();
            synchronizeNameFields();
        }

        private static void helloWorld()
        {
            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.OnOpenDocument = pdf.CreateJavaScriptAction("app.alert(\"Hello CodeProject!\", 3);");

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

        private static void formWithDate()
        {
            new Date().Run();
        }

        private static void synchronizeNameFields()
        {
            Names.Run();
        }
    }
}

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