PDF Expiry support?

Posted by: mkulik on 13 November 2018, 9:00 am EST

  • Posted 13 November 2018, 9:00 am EST

    I can't find any information on how we might use this api to generate a PDF that can expire. Is it possible to do that?
  • Marked as Answer

    Replied 13 November 2018, 9:17 pm EST


    PDF expiration is not supported with Documents for PDF.
    Let us know if you need further assistance.

    Best Regards,
  • Replied 19 November 2018, 5:18 pm EST


    AFAIK, there is no standard mechanism built into PDF (defined in the spec) that provides real document expiration. But, there is a way to imitate expiration when the PDF is opened in a viewer that supports JavaScript (e.g. Adobe Acrobat), attached is a working example, here is the relevant code:

    public class PdfExpire
    // Expiry date (year, month index, day):
    const string expDate = "2018, 10, 19";

    readonly string jsclose =
    "var rightNow = new Date();\r\n" +
    $"var endDate = new Date({expDate});\r\n" +
    "if(rightNow.valueOf() > endDate.valueOf()) {\r\n" +
    // Remove next line to close the document right away without alert:
    "app.alert(\"This Document has Expired.\");\r\n" +
    "this.closeDoc();\r\n" +
    "}\r\n" +

    public void CreatePDF(Stream stream)
    var doc = new GcPdfDocument();
    var page = doc.NewPage();
    var g = page.Graphics;

    // Invisible button with action activated on page open:
    var btnExpire = new PushButtonField();
    btnExpire.Widget.Locked = true;
    btnExpire.Widget.Rect = RectangleF.Empty;
    // The JavaScript will compare the current date with the expiry date,
    // and will close the document if the expiry date is in the past:
    btnExpire.Widget.Events.AnnotationPageOpened = new ActionJavaScript(jsclose);
    btnExpire.Widget.Page = page;

    $"If opened in a PDF viewer that supports JavaScript actions, this document will close if the current date is past {expDate} (2nd number is month's 0-based index).",
    // Done:

    Hope this helps.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels