자바스크립트 액션 추가 PDF
PdfContentEditor 클래스는 Aspose.Pdf.Facades 패키지에 포함되어 있으며 PDF 파일에 자바스크립트 액션을 추가할 수 있는 유연성을 제공합니다. PDF 뷰어에서 메뉴 항목을 실행하는 일련의 액션에 해당하는 링크를 생성할 수 있습니다. 이 클래스는 문서 이벤트에 대한 추가 액션을 생성하는 기능도 제공합니다.
우선, Document 객체가 그려지며, 우리의 예에서는 Rectangle 입니다. 그리고 Rectangle에 createJavaScriptLink 액션을 설정합니다. 이후 문서를 저장할 수 있습니다.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddJavascriptAction ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using ( var editor = new Aspose . Pdf . Facades . PdfContentEditor ())
{
// Bind PDF document
editor . BindPdf ( dataDir + "sample.pdf" );
// Create Javascript link
var rect = new System . Drawing . Rectangle ( 50 , 750 , 50 , 50 );
var code = "app.alert('Welcome to Aspose!');" ;
editor . CreateJavaScriptLink ( code , rect , 1 , System . Drawing . Color . Green );
// Save PDF document
editor . Save ( dataDir + "JavaScriptAdded_out.pdf" );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddJavascriptAction ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using var editor = new Aspose . Pdf . Facades . PdfContentEditor ();
// Bind PDF document
editor . BindPdf ( dataDir + "sample.pdf" );
// Create Javascript link
var rect = new System . Drawing . Rectangle ( 50 , 750 , 50 , 50 );
var code = "app.alert('Welcome to Aspose!');" ;
editor . CreateJavaScriptLink ( code , rect , 1 , System . Drawing . Color . Green );
// Save PDF document
editor . Save ( dataDir + "JavaScriptAdded_out.pdf" );
}