protected void btnGeneratePdf_Click(object sender, EventArgs e) { APToolkitNET.Toolkit a = new APToolkitNET.Toolkit(); string imagePath = System.AppDomain.CurrentDomain.BaseDirectory; int outputFile = a.OpenOutputFile(imagePath + "Test.pdf"); a.OutputPageHeight = 792.0f; a.OutputPageWidth = 612.0f; var images = Directory.EnumerateFiles(imagePath + "image", "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".jpg") || s.EndsWith(".png") || s.EndsWith(".gif") || s.EndsWith(".tiff")); int pageNumber = 1; foreach (string image in images) { a.NewPage(); a.PrintImage(image, 200, 400, 200, 200, true, 0); a.SetFont("Helvetica", 16); a.PrintText(500, 50, "Page " + pageNumber.ToString()); a.PrintText(40, 30, "Signature:"); pageNumber++; } a.CloseOutputFile(); a.Dispose(); Response.Redirect("load.aspx", true); }
public static void Example() { string strPath; int intOpenOutputFile; int intOpenInputFile; int intCopyForm; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Here you can place any code that will alter the output file // Such as adding security, setting page dimensions, etc. // Create the new PDF file intOpenOutputFile = oTK.OpenOutputFile(strPath + "new.pdf"); if (intOpenOutputFile != 0) { ErrorHandler("OpenOutputFile", intOpenOutputFile); } // Open the template PDF intOpenInputFile = oTK.OpenInputFile(strPath + "PDF.pdf"); if (intOpenInputFile != 0) { ErrorHandler("OpenInputFile", intOpenInputFile); } // Here you can call any Toolkit functions that will manipulate // the input file such as text and image stamping, form filling, etc. // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages intCopyForm = oTK.CopyForm(0, 0); if (intCopyForm != 1) { ErrorHandler("CopyForm", intCopyForm); } // Close the new file to complete PDF creation oTK.CloseOutputFile(); // Release Object oTK.Dispose(); // Process Complete WriteResults("Done!"); }
public async Task <IActionResult> Upload(IFormFile file) { try { if (file != null && file.Length > 0) { var name = Path.GetFileName(file.FileName); var extension = Path.GetExtension(file.FileName); if (!_validExtensions.Contains(extension.ToLowerInvariant())) { TempData["Message"] = "Not a valid file extension"; return(RedirectToAction("Index")); } string filePath = Path.Combine("Output", String.Format("{0}_{1}.{2}", Guid.NewGuid(), name, extension)); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Set the PDF page Height and Width to Letter (72 = 1") oTK.OutputPageHeight = 792.0f; oTK.OutputPageWidth = 612.0f; // Create the new PDF file string pdfFileName = "output.pdf"; var intOpenOutputFile = oTK.OpenOutputFile(String.Format("{0}/{1}", "output", pdfFileName)); if (intOpenOutputFile != 0) { //log and redirect to custom error page //for demo just throw throw new Exception("error in pdf creation"); } oTK.NewPage(); oTK.SetFont("Helvetica", 12); oTK.PrintText(50.0f, 20.0f, "Signature: Mher Sarkissian"); oTK.PrintImage(filePath, 0.0f, 200.0f, 612.0f, 792.0f, true, 0); oTK.CloseOutputFile(); oTK.Dispose(); } else { TempData["Message"] = "Invalid file upload"; return(RedirectToAction("Index")); } } catch (Exception e) { //log and redirect to custom error page //for demo just throw throw e; } return(View("ViewPDF")); }
public static void Example() { int intOpenOutputFile; string strPath; int intOpenInputFile; int intCopyForm; string memPDF; int intMergeFile; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Here you can place any code that will alter the output file // Such as adding security, setting page dimensions, etc. APToolkitNET.FieldInfo oFI = oTK.FieldInfo("name", 1); string TKversion = oTK.ToolkitVersion; // Create the new PDF file in memory intOpenOutputFile = oTK.OpenOutputFile("MEMORY"); if (intOpenOutputFile != 0) { ErrorHandler("OpenOutputFile", intOpenOutputFile); } //convert pdf to byte array byte[] bytes = System.IO.File.ReadAllBytes(strPath + "form.pdf"); oTK.InputByteArray = bytes; // Open the template PDF intOpenInputFile = oTK.OpenInputFile("MEMORY"); if (intOpenInputFile != 0) { ErrorHandler("OpenInputFile", intOpenInputFile); } // Here you can call any Toolkit functions that will manipulate // the input file such as text and image stamping, form filling, etc. short formCount = oTK.CountFormFields(); Console.WriteLine(TKversion + "Count form fields = " + formCount); Console.ReadKey(); // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages intCopyForm = oTK.CopyForm(0, 0); if (intCopyForm != 1) { ErrorHandler("CopyForm", intCopyForm); } // Close the new file to complete PDF creation oTK.CloseOutputFile(); // Set the in memory PDF to a variable // To retrieve the PDF as a byte array use oTK.BinaryImage memPDF = oTK.OutputByteStream; // Toolkit can take a PDF in memory and use it as an input file // Here we will use the PDF we just created in memory // Create the final PDF on disk intOpenOutputFile = oTK.OpenOutputFile(strPath + "final.pdf"); if (intOpenOutputFile != 0) { ErrorHandler("OpenOutputFile", intOpenOutputFile); } // Prepare the in memory PDF to be used with Toolkit // For .NET Toolkit also has InputByteArray to accept Byte Arrays oTK.InputByteStream = memPDF; // Now we can use 'MEMORY' as the filename with OpenInputFile or MergeFile intMergeFile = oTK.MergeFile("MEMORY", 0, 0); if (intMergeFile != 1) { ErrorHandler("MergeFile", intMergeFile); } // Close the final file to complete PDF creation oTK.CloseOutputFile(); // To save a PDF in memory to a file directly call SaveMemoryToDisk oTK.SaveMemoryToDisk(strPath + "SavedMemory.pdf"); // Release Object oTK.Dispose(); // Process Complete WriteResults("Done!"); }
public static void Example() { string strPath; int intOpenOutputFile; int intOpenInputFile; long longSetDocumentProperty; long longSetCustomProperty; long longSetUserProperty; int intCopyForm; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Create the new PDF file intOpenOutputFile = oTK.OpenOutputFile(strPath + "new.pdf"); if (intOpenOutputFile != 0) { ErrorHandler("OpenOutputFile", intOpenOutputFile); } // Open the template PDF intOpenInputFile = oTK.OpenInputFile(strPath + "form.pdf"); if (intOpenInputFile != 0) { ErrorHandler("OpenInputFile", intOpenInputFile); } // Get the reference to the XMP object APToolkitNET.XMPManager oXMP = oTK.GetXMPManager(); // Set a document property longSetDocumentProperty = oXMP.SetDocumentProperty(APToolkitNET.XMPProperty.Author, "John Doe"); if (longSetDocumentProperty != 0) { ErrorHandler("SetDocumentProperty", longSetDocumentProperty); } // Set a custom property longSetCustomProperty = oXMP.SetCustomProperty("example", "http://examples.activepdf.com"); if (longSetCustomProperty != 0) { ErrorHandler("SetCustomProperty", longSetCustomProperty); } // Set the namespace for the user property oXMP.SetNamespace("dc", "http://purl.org/dc/elements/1.1/"); // Set a user property longSetUserProperty = oXMP.SetUserProperty("contributor", "ActivePDF"); if (longSetUserProperty != 0) { ErrorHandler("SetUserProperty", longSetUserProperty); } // Remove a property oXMP.RemoveDocumentProperty(APToolkitNET.XMPProperty.Author); // Get the reference to the InitialViewInfo object APToolkitNET.InitialViewInfo oIVI = oTK.GetInitialViewInfo(); // Options for viewer window oIVI.CenterWindow = true; oIVI.FullScreen = false; oIVI.ResizeWindow = true; oIVI.Show = APToolkitNET.IVShow.IVShow_DocumentTitle; // Show or hide UI elements of the viewer oIVI.HideMenuBar = true; oIVI.HideToolBars = true; oIVI.HideWindowControls = true; oIVI.NavigationTab = APToolkitNET.IVNavigationTab.IVNavigationTab_PageOnly; // Page settings oIVI.Magnification = APToolkitNET.IVMagnification.IVMagnification_150; oIVI.OpenToPage = 2; oIVI.PageLayout = APToolkitNET.IVPageLayout.IVPageLayout_SinglePageContinuous; // Populate and flatten the fields, the data will remain in the place // of the field and the field data will be added to the XMP data oTK.SetFormFieldData("name", "John Doe", -997); oTK.SetFormFieldData("date", "1/1/2000", -997); oTK.SetFormFieldData("amount", "15.00", -997); // Copy the template (with any changes) to the new file intCopyForm = oTK.CopyForm(0, 0); if (intCopyForm != 1) { ErrorHandler("CopyForm", intCopyForm); } // Close the new file to complete PDF creation oTK.CloseOutputFile(); // Release Object oTK.Dispose(); // Process Complete WriteResults("Done!"); }