當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfDocument.SetAdditionalAction方法代碼示例

本文整理匯總了C#中PdfSharp.Pdf.PdfDocument.SetAdditionalAction方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDocument.SetAdditionalAction方法的具體用法?C# PdfDocument.SetAdditionalAction怎麽用?C# PdfDocument.SetAdditionalAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PdfSharp.Pdf.PdfDocument的用法示例。


在下文中一共展示了PdfDocument.SetAdditionalAction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddPrintExpireOnOpen

        private void AddPrintExpireOnOpen(PdfDocument doc, DateTime ExpDate)
        {
            ExpDate = ExpDate.ToUniversalTime();
            var ExpireYear = ExpDate.Year;
            var ExpireMonth = ExpDate.Month;
            var ExpireDate = ExpDate.Day;
            var ExpireHour = ExpDate.Hour;
            var ExpireMin = ExpDate.Minute;

            //https://forums.adobe.com/thread/286036?start=0&tstart=0
            //http://forum.pdfsharp.net/viewtopic.php?f=2&t=368
            //This javascript string has been formatted for ease of update and reading
            string fullscript = @"function checkExpiration(LastYear, LastMonth, LastDate, LastHour, LastMin, LastSec, LastMS) {
    // document level function to see if passed date less than today's date 
    // check that numbers are passed as parameters 
    'use strict';
    if (isNaN(LastYear)) {
        LastYear = 1900;
    }
    if (isNaN(LastMonth)) {
        LastMonth = 1;
    }
    if (isNaN(LastDate)) {
        LastDate = 1;
    }
    if (isNaN(LastHour)) {
        LastHour = 0;
    }
    if (isNaN(LastMin)) {
        LastMin = 0;
    }
    if (isNaN(LastSec)) {
        LastSec = 0;
    }
    if (isNaN(LastMS)) {
        LastMS = 0;
    }

    LastMonth = LastMonth - 1; // adjust the passed month to the zero based month 
    // make the expiration date time object a numeric value 
    var myDate = new Date(Date.UTC(Number(LastYear), Number(LastMonth), Number(LastDate), Number(LastHour), Number(LastMin), Number(LastSec), Number(LastMS))).valueOf(), today = new Date().valueOf(); // convert passed expiration date time to a date time object value // get the current date time's object as a numeric value

    // return logical value of the comparison of the passed expiration date value to today - if true document has expired 
    return (myDate < today);
}
var ExpireYear = " + ExpireYear + @"; //2008
var ExpireMonth = " + ExpireMonth + @"; //March
var ExpireDate = " + ExpireDate + @"; //21st
var ExpireHour = " + ExpireHour + @"; //noon
var ExpireMin = " + ExpireMin + @"; //1

if (checkExpiration(ExpireYear, ExpireMonth, ExpireDate, ExpireHour, ExpireMin)) {
    try {
        this.closeDoc(1);
    } catch (e) {}
    app.alert('The file has expired. Contact creator to reprint the document.', 1, 0, 'Expired');
} else {
    //app.alert('Expires in ' + ExpireMonth + ' ' + ExpireDate + ' ' + ExpireYear + ' ' + ExpireHour + ' ' + ExpireMin, 1, 0, 'Expires in');
    this.syncAnnotScan();
    var annots = this.getAnnots();
    var i;
    for (i = 0; i < annots.length; i += 1) {
        if (annots[i].contents === 'ScreenProtector') {
            annots[i].hidden = true;
        }
    }

    this.print();
}";
            string DidPrintScript = @"
this.syncAnnotScan();
var annots = this.getAnnots();
var i;
for (i = 0; i < annots.length; i += 1) {
    if (annots[i].contents === 'ScreenProtector') {
        annots[i].hidden = false;
    }
}
try {
    this.closeDoc(1);
} catch (e) {}";
            /* Alternate method
            //If copies are needed
            //var pp = this.getPrintParams();
            //pp.NumCopies=eval(1);
            //this.print(pp);
            PdfDictionary PrintDictionary = new PdfDictionary();
            PrintDictionary.Elements["/Type"] = new PdfName("/Action");
            PrintDictionary.Elements["/S"] = new PdfName("/Named");
            PrintDictionary.Elements["/N"] = new PdfName("/Print");*/

            PdfDictionary DidPrintJavaScriptDictionary = new PdfDictionary();
            DidPrintJavaScriptDictionary.Elements["/Type"] = new PdfName("/Action");
            DidPrintJavaScriptDictionary.Elements["/S"] = new PdfName("/JavaScript");
            DidPrintJavaScriptDictionary.Elements.SetString("/JS", DidPrintScript);

            doc.SetAdditionalAction(new PdfName("/DP"), DidPrintJavaScriptDictionary);

            PdfDictionary UnhideDictionary = new PdfDictionary();
            UnhideDictionary.Elements["/Type"] = new PdfName("/Action");
//.........這裏部分代碼省略.........
開發者ID:Septarius,項目名稱:SharpPDFLabel,代碼行數:101,代碼來源:CustomLabelCreator.cs


注:本文中的PdfSharp.Pdf.PdfDocument.SetAdditionalAction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。