public static void Run() { // ExStart:SetExpiryDate // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Instantiate Document object Aspose.Pdf.Document doc = new Aspose.Pdf.Document(); // Add page to pages collection of PDF file doc.Pages.Add(); // Add text fragment to paragraphs collection of page object doc.Pages[1].Paragraphs.Add(new TextFragment("Hello World...")); // Create JavaScript object to set PDF expiry date JavascriptAction javaScript = new JavascriptAction( "var year=2017;" + "var month=5;" + "today = new Date(); today = new Date(today.getFullYear(), today.getMonth());" + "expiry = new Date(year, month);" + "if (today.getTime() > expiry.getTime())" + "app.alert('The file is expired. You need a new one.');"); // Set JavaScript as PDF open action doc.OpenAction = javaScript; dataDir = dataDir + "SetExpiryDate_out.pdf"; // Save PDF Document doc.Save(dataDir); // ExEnd:SetExpiryDate Console.WriteLine("\nPDF expiry date setup successfully.\nFile saved at " + dataDir); }
public void EscapeUri(string uri, string result, bool isEscaped) { //ExStart //ExFor:PdfSaveOptions.EscapeUri //ExFor:PdfSaveOptions.OpenHyperlinksInNewWindow //ExSummary: Shows how to escape hyperlinks or not in the document. DocumentBuilder builder = new DocumentBuilder(); builder.InsertHyperlink("Testlink", uri, false); // Set this property to false if you are sure that hyperlinks in document's model are already escaped PdfSaveOptions options = new PdfSaveOptions(); options.EscapeUri = isEscaped; options.OpenHyperlinksInNewWindow = true; builder.Document.Save(ArtifactsDir + "PdfSaveOptions.EscapedUri.pdf", options); //ExEnd #if !(__MOBILE__ || MAC) Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ArtifactsDir + "PdfSaveOptions.EscapedUri.pdf"); // Get first page Aspose.Pdf.Page page = pdfDocument.Pages[1]; // Get the first link annotation LinkAnnotation linkAnnot = (LinkAnnotation)page.Annotations[1]; JavascriptAction action = (JavascriptAction)linkAnnot.Action; string uriText = action.Script; Assert.AreEqual(result, uriText); #endif }
public static void Run() { // ExStart:AddJavaScriptToPage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Load an existing PDF files Document doc = new Document(dataDir + "input.pdf"); // Adding JavaScript at Document Level // Instantiate JavascriptAction with desried JavaScript statement JavascriptAction javaScript = new JavascriptAction("this.print({bUI:true,bSilent:false,bShrinkToFit:true});"); // Assign JavascriptAction object to desired action of Document doc.OpenAction = javaScript; // Adding JavaScript at Page Level doc.Pages[2].Actions.OnOpen = new JavascriptAction("app.alert('page 1 opened')"); doc.Pages[2].Actions.OnClose = new JavascriptAction("app.alert('page 1 closed')"); dataDir = dataDir + "JavaScript-Added_out.pdf"; // Save PDF Document doc.Save(dataDir); // ExEnd:AddJavaScriptToPage Console.WriteLine("\nJavascript added successfully to a page.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:AddJavaScriptToPage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments(); // Load an existing PDF files Document doc = new Document(dataDir + "input.pdf"); // Adding JavaScript at Document Level // Instantiate JavascriptAction with desried JavaScript statement JavascriptAction javaScript = new JavascriptAction("this.print({bUI:true,bSilent:false,bShrinkToFit:true});"); // Assign JavascriptAction object to desired action of Document doc.OpenAction = javaScript; // Adding JavaScript at Page Level doc.Pages[2].Actions.OnOpen = new JavascriptAction("app.alert('page 1 opened')"); doc.Pages[2].Actions.OnClose = new JavascriptAction("app.alert('page 1 closed')"); dataDir = dataDir + "JavaScript-Added_out_.pdf"; // Save PDF Document doc.Save(dataDir); // ExEnd:AddJavaScriptToPage Console.WriteLine("\nJavascript added successfully to a page.\nFile saved at " + dataDir); }