Expire PDF on a Specific Date by VeryPDF Javascript to PDF Embedder Command Line

Javascript to PDF Embedder Command Line home page,

http://www.verypdf.com/app/javascript-to-pdf-embedder-cmd/index.html

A Document Level script can be used to close a document when a certain date has been reached. This is a simple expiration method with minimal security and can be beaten by anyone who knows PDF and Acrobat JavaScript well enough to understand what's going on. But for most users it's sufficient.

this.zoomType = zoomtype.fitP;
CheckDoc();
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function CheckDoc()
{
        //if (HasExpired1(2))
        if (HasExpired2())
        {
                CreateBigButton("ExpireButton", 0);
              this.dirty = false;
                var strMsg = "This Document has Expired. Would you like to close this document?";
                if(this.app.alert(strMsg,2,2) == 4)
                        this.closeDoc()
        }
        else
        {
                app.alert("This document has not expired.");
        }
}
function HasExpired1(NumDays)
{
        var Now = new Date();
        var DifDays = (Now - this.modDate)/(1000*60*60*24);
        return (DifDays>NumDays);
}
function HasExpired2()
{
    // Get the current date and time
        var rightNow = new Date();
    // Setup End Date
        var endDate = new Date("January 1, 2008");
    if(rightNow > endDate)
    {
            return true;
        }
        return false;
}

function CreateBigButton(cName, nPage)
{
        var pgRect = this.getPageBox("Crop", nPage);
        var oFld = this.addField( cName , "button", nPage, pgRect);
        if(oFld != null)
        {
            oFld.display = display.visible;
            oFld.buttonSetCaption("Sorry, you cannot view this page\nbecause this files has expired.");
            oFld.borderStyle = border.b;
            oFld.strokeColor = color.blue;
            oFld.textColor = color.black;
            oFld.fillColor = color.gray;
            oFld.lineWidth = 5;
            oFld.setAction("MouseUp", "app.launchURL('http://www.verypdf.com/', true);" );
        }
        return oFld;
}

You can save above JS code to a text file, then you can run following command line to insert this Javascript code into PDF file,

addjs2pdf.exe -runatopen js.txt in.pdf out.pdf

out.pdf file will contain the Javascript code, when you open this PDF file in Adobe Acrobat software, above Javascript code will be executed automatically.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

This entry was posted in VeryPDF Blog and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!