static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Starting with Toolkit version 10 native DLLs are no longer // copied to the system folder. The Toolkit constructor must // be called with the path to the native DLLs or place them // in your applications working directory. This example // assumes they are located in the default installation folder. // (Use x86 in the path for 32b applications) string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath)) { // Get the Toolkit Bookmark Manager APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); // Set CopyBookmarks to true to create bookmarks in the output PDF. bookmarkManager.CopyBookmarks = true; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.CopyBookmarks.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile($"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(0, 0); if (result != 1) { WriteResult($"Error copying file: {result.ToString()}", toolkit); return; } } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Starting with Toolkit version 10 native DLLs are no longer // copied to the system folder. The Toolkit constructor must // be called with the path to the native DLLs or place them // in your applications working directory. This example // assumes they are located in the default installation folder. // (Use x86 in the path for 32b applications) string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath)) { // Get the Toolkit Bookmark Manager APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); // Set CopyBookmarks to true to create bookmarks in the output PDF. bookmarkManager.CopyBookmarks = true; // Create the new PDF file int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.AddChild.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Create a child bookmark to each of the two bookmarks // in the example PDF. APToolkitNET.Bookmark parentBookmark = bookmarkManager.FindByTitle(Title: "Page 1 Bookmark"); if (parentBookmark != null) { APToolkitNET.Bookmark newBookmark = bookmarkManager.AddChild(Parent: parentBookmark, Title: "Page 2 Bookmark", Color: "#FFA500", FontStyle: APToolkitNET.FontStyle.Bold); newBookmark.SetInternalLink( DestPage: parentBookmark.GetPageNumber() + 1, LLX: 0, LLY: 0); } parentBookmark = bookmarkManager.FindByTitle(Title: "Page 2 Bookmark"); if (parentBookmark != null) { APToolkitNET.Bookmark newBookmark = bookmarkManager.AddChild(Parent: parentBookmark, Title: "Page 1 Bookmark", Color: "#FFA500", FontStyle: APToolkitNET.FontStyle.Bold); newBookmark.SetInternalLink( DestPage: parentBookmark.GetPageNumber() - 1, LLX: 0, LLY: 0); } // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(FirstPage: 0, LastPage: 0); if (result != 1) { WriteResult($"Error copying file: {result.ToString()}", toolkit); return; } } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
public ActionResult <Response> CreateSampleBookmarks([FromBody] Request request) { try { using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { //Set page dimensions toolkit.OutputPageHeight = 792.0f; toolkit.OutputPageWidth = 612.0f; //Create new file int result = toolkit.OpenOutputFile(FileName: $"{serverDirectory}SampleBookmarks.pdf"); if (result != 0) { throw new Exception($"Could not create destination file: SampleBookmarks.pdf"); } // Open Source File result = toolkit.OpenInputFile($"{ serverDirectory}{request.filename}.pdf"); if (result != 0) { throw new Exception($"Could not Open file: {request.filename}"); } // Add new page to output toolkit.NewPage(); toolkit.SetFont(FontName: "Arial", FontSize: 20); toolkit.PrintText(X: 72.0f, Y: 720.0f, Text: "Table of Contents"); toolkit.AddInternalLink(1, 72, 720, 72, 720, 5, 72, 720, 4); //toolkit.AddInternalLinkBookmark("Section 1", 2, 0, 0); APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); bookmarkManager.CopyBookmarks = true; APToolkitNET.Bookmark root = bookmarkManager.MakeRoot("Table of Contents", "red", APToolkitNET.FontStyle.Bold); var section1 = bookmarkManager.AddChild(root, "Section 1"); section1.SetInternalLink(1, 0, 0); var section11 = bookmarkManager.AddChild(section1, "Section 1.1"); section11.SetInternalLink(2, 0, 0); var section111 = bookmarkManager.AddChild(section1, "Section 1.1.1"); section11.SetInternalLink(3, 0, 0); var section2 = bookmarkManager.AddChild(root, "Section 2"); section2.SetInternalLink(4, 0, 0); var section21 = bookmarkManager.AddChild(section2, "Section 2.1"); section21.SetInternalLink(5, 0, 0); var section211 = bookmarkManager.AddChild(section2, "Section 2.1.1"); section211.SetInternalLink(6, 0, 0); // Close the new file to complete PDF creation toolkit.CopyForm(0, 0); toolkit.CloseInputFile(); toolkit.CloseOutputFile(); return(new Response() { FileContent = string.Empty, FileName = "SampleBookmarks.pdf", Message = "File SampleBookmarks.pdf created successfully", Success = true }); } } catch (Exception ex) { return(new Response() { FileContent = string.Empty, FileName = "", Message = "Could not Create Sample Bookmarks " + ex.Message, Success = false }); } }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Starting with Toolkit version 10 native DLLs are no longer // copied to the system folder. The Toolkit constructor must // be called with the path to the native DLLs or place them // in your applications working directory. This example // assumes they are located in the default installation folder. // (Use x86 in the path for 32b applications) string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath)) { // Get the Toolkit Bookmark Manager APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); // Set CopyBookmarks to true to create bookmarks in the output PDF. bookmarkManager.CopyBookmarks = true; // Create the new PDF file int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.URLBookmark.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Create a new bookmark for the page. APToolkitNET.Bookmark newBookmark = bookmarkManager.NewBookmark(Title: "www.activepdf.com"); // Set the URL to open when the bookmark is selected. newBookmark.SetURL(URL: "https://www.activePDF.com"); // Set the bookmark color - orange newBookmark.Color = "#FFA500"; // Set the bookmark font style newBookmark.FontStyle = APToolkitNET.FontStyle.ItalicBold; // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(FirstPage: 0, LastPage: 0); if (result != 1) { WriteResult($"Error copying file: {result.ToString()}", toolkit); return; } } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }