public static void Run() { // ExStart:AddPageStampPage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); // Create PdfFileStamp object PdfFileStamp fileStamp = new PdfFileStamp(); // Open Document fileStamp.BindPdf(dataDir + "AddPageStamp-Page.pdf"); // Create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindPdf(dataDir + "temp.pdf", 1); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; // Set particular pages stamp.Pages = new int[] { 2 }; // Add stamp to PDF file fileStamp.AddStamp(stamp); // Save updated PDF file fileStamp.Save(dataDir + "AddPageStamp-Page_out_.pdf"); // Close fileStamp fileStamp.Close(); // ExEnd:AddPageStampPage }
public static void Run() { // ExStart:AddPageStampAll // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); // Create PdfFileStamp object PdfFileStamp fileStamp = new PdfFileStamp(); // Open Document fileStamp.BindPdf(dataDir + "AddPageStampAll.pdf"); // Create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindPdf(dataDir+ "temp.pdf", 1); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; // Add stamp to PDF file fileStamp.AddStamp(stamp); // Save updated PDF file fileStamp.Save(dataDir + "AddPageStampAll_out.pdf"); // Close fileStamp fileStamp.Close(); // ExEnd:AddPageStampAll }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); //create PdfFileStamp object PdfFileStamp fileStamp = new PdfFileStamp(); //Open Document fileStamp.BindPdf(dataDir + "AddTextStampAll.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 14)); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Save(dataDir + "AddTextStampAll_out.pdf"); //close fileStamp fileStamp.Close(); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); //create PdfFileStamp object PdfFileStamp fileStamp = new PdfFileStamp(); //Open Document fileStamp.BindPdf(dataDir + "AddPageStamp-Page.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindPdf(dataDir+ "temp.pdf", 1); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //set particular pages stamp.Pages = new int[] { 2 }; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Save(dataDir + "AddPageStamp-Page_out.pdf"); //close fileStamp fileStamp.Close(); }
public static void Run() { // ExStart:AddImageStampAll // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); // Create PdfFileStamp object PdfFileStamp fileStamp = new PdfFileStamp(); // Open Document fileStamp.BindPdf(dataDir + "AddImageStampAll.pdf"); // Create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindImage(dataDir + "aspose-logo.jpg"); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; // Add stamp to PDF file fileStamp.AddStamp(stamp); // Save updated PDF file fileStamp.Save(dataDir + "AddImageStampAll_out_.pdf"); // Close fileStamp fileStamp.Close(); // ExEnd:AddImageStampAll }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); //create PdfFileStamp object PdfFileStamp fileStamp = new PdfFileStamp(); //Open Document fileStamp.BindPdf(dataDir + "AddImageStamp-Page.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindImage(dataDir + "aspose-logo.jpg"); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //set particular pages stamp.Pages = new int[] { 1 }; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Save(dataDir + "AddImageStamp-Page_out.pdf"); //close fileStamp fileStamp.Close(); }
public static void Run() { // ExStart:RotatingStamp // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles(); // Set path of the image to be set as watermark string imageFile = dataDir + "aspose-logo.jpg"; // Set input file path string inFile = dataDir + "inFile.pdf"; // Set output file path string outFile = dataDir + "RotatingStamp_out.pdf"; // Create PdfFileInfo object to get height and width of the pages PdfFileInfo fileInfo = new PdfFileInfo(inFile); // Create Stamp object Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp(); // Bind image file with the Stamp object aStamp.BindImage(imageFile); // Specify whether the stamp will be added as a background or not aStamp.IsBackground = false; // Specifies at which pages to add the watermark aStamp.Pages = new int[] { 1 }; // Specifies the watermark rotation - rotate at 90 degrees the stamp is rotated about the center point of the stamp object aStamp.Rotation = 90; // Specifies the position of stamp - lower left corner of the stamp aStamp.SetOrigin(fileInfo.GetPageWidth(1) / 2, fileInfo.GetPageHeight(1) / 2); // Set the size of the watermark aStamp.SetImageSize(100, 100); Document doc = new Document(inFile); // Create PdfFileStamp class to bind input and output files PdfFileStamp stamper = new PdfFileStamp(doc); // Add the stamp in the PDF file stamper.AddStamp(aStamp); // Close the PdfFileStamp object stamper.Close(); // ExEnd:RotatingStamp }
public static void AddTextStamps() { // ExStart:AddTextStamps // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles(); // Set Text Stamp to display string Table Of Contents Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp stamp.SetOrigin((new PdfFileInfo(new FileStream(dataDir + "input1.pdf", FileMode.Open)).GetPageWidth(1) / 3), 700); // Set particular pages stamp.Pages = new int[] { 1 }; // ExEnd:AddTextStamps }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); //open document PdfFileStamp fileStamp = new PdfFileStamp(dataDir + "AddImageStampAll.pdf", dataDir + "AddImageStampAll_out.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindImage(dataDir + "aspose-logo.jpg"); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Close(); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document PdfFileStamp fileStamp = new PdfFileStamp(dataDir+ "input.pdf", dataDir+ "output.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindPdf(dataDir+ "temp.pdf", 1); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Close(); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_StampsWatermarks(); //open document PdfFileStamp fileStamp = new PdfFileStamp(dataDir+ "AddImageStampAll.pdf", dataDir+ "AddImageStampAll_out.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindImage(dataDir+ "aspose-logo.jpg"); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Close(); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document PdfFileStamp fileStamp = new PdfFileStamp(dataDir + "input.pdf", dataDir + "output.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindImage(dataDir + "aspose-logo.jpg"); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Close(); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document PdfFileStamp fileStamp = new PdfFileStamp(dataDir + "input.pdf", dataDir + "output.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 14)); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Close(); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document PdfFileStamp fileStamp = new PdfFileStamp(dataDir+ "input.pdf", dataDir+ "output.pdf"); //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 14)); stamp.SetOrigin(200, 200); stamp.Rotation = 90.0F; stamp.IsBackground = true; //add stamp to PDF file fileStamp.AddStamp(stamp); //save updated PDF file fileStamp.Close(); }
public ActionResult <Response> ConcatenateWithContents([FromBody] Request request) { try { Stopwatch stopwatch1 = new Stopwatch(); stopwatch1.Start(); PdfFileEditor pdfEditor = new PdfFileEditor(); using (MemoryStream Concatenated_Stream = new MemoryStream()) { string concFilename = "Concatenated_Table_Of_Contents.pdf"; List <System.IO.Stream> pdfStreams = new List <System.IO.Stream>(); string[] files = System.IO.Directory.GetFiles(serverDirectory); foreach (string file in files) { if (file.ToLower().Contains(concFilename.ToLower())) { continue; } if (!Path.GetExtension(file).Equals(".pdf")) { continue; } System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open); pdfStreams.Add(stream); } //System.IO.FileStream outputPDF = new System.IO.FileStream(serverDirectory + request.filename + ".pdf", System.IO.FileMode.Create); Stopwatch stopwatch2 = new Stopwatch(); stopwatch2.Start(); pdfEditor.Concatenate(pdfStreams.ToArray(), Concatenated_Stream); stopwatch2.Stop(); Console.WriteLine("PdfEditor.Concatenate Action: " + stopwatch2.ElapsedMilliseconds.ToString()); // Insert a blank page at the begining of concatenated file to display Table of Contents Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(Concatenated_Stream); // Insert a empty page in a PDF concatenated_pdfDocument.Pages.Insert(1); using (MemoryStream Document_With_BlankPage = new MemoryStream()) { // Save output file stopwatch2.Reset(); stopwatch2.Start(); concatenated_pdfDocument.Save(Document_With_BlankPage); stopwatch2.Stop(); Console.WriteLine("Concatenated_pdfDocument.Save Action: " + stopwatch2.ElapsedMilliseconds.ToString()); using (var Document_with_TOC_Heading = new MemoryStream()) { // Add Table Of Contents logo as stamp to PDF file PdfFileStamp fileStamp = new PdfFileStamp(); // Find the input file fileStamp.BindPdf(Document_With_BlankPage); // Set Text Stamp to display string Table Of Contents Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp stamp.SetOrigin((new PdfFileInfo(Document_With_BlankPage).GetPageWidth(1) / 3), 700); // Set particular pages stamp.Pages = new int[] { 1 }; // Add stamp to PDF file stopwatch2.Reset(); stopwatch2.Start(); fileStamp.AddStamp(stamp); stopwatch2.Stop(); Console.WriteLine("FileStamp.AddStamp Action: " + stopwatch2.ElapsedMilliseconds.ToString()); int counter = 1; int diff = 0; foreach (System.IO.Stream stream in pdfStreams) { var Document_Link = new Aspose.Pdf.Facades.Stamp(); Document_Link.BindLogo(new FormattedText(counter + " - Link to Document " + counter, System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12)); Document_Link.SetOrigin(150, 650 - diff); Document_Link.Pages = new int[] { 1 }; fileStamp.AddStamp(Document_Link); counter++; diff += 40; } stopwatch2.Reset(); stopwatch2.Start(); fileStamp.Save(Document_with_TOC_Heading); stopwatch2.Stop(); Console.WriteLine("FileStamp.Save Action: " + stopwatch2.ElapsedMilliseconds.ToString()); fileStamp.Close(); PdfContentEditor contentEditor = new PdfContentEditor(); // Bind the PDF file in which we added the blank page contentEditor.BindPdf(Document_with_TOC_Heading); counter = 1; diff = 0; int numberOfpagesOfPreviousFile = 0; foreach (System.IO.Stream stream in pdfStreams) { if (counter == 1) { contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650 - diff, 100, 20), counter + 1, 1, System.Drawing.Color.Transparent); } else { //Replace counter with numberOfpagesOfPreviousFile of the following line to fix Link page number contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650 - diff, 100, 20), counter + 1, 1, System.Drawing.Color.Transparent); } counter++; numberOfpagesOfPreviousFile = new PdfFileInfo(stream).NumberOfPages; diff += 40; } if (System.IO.File.Exists(serverDirectory + concFilename)) { System.IO.File.Delete(serverDirectory + concFilename); } stopwatch2.Reset(); stopwatch2.Start(); contentEditor.Save(serverDirectory + concFilename); stopwatch2.Stop(); Console.WriteLine("FileStamp.Save Action: " + stopwatch2.ElapsedMilliseconds.ToString()); } } } stopwatch1.Stop(); Console.WriteLine("Total Time: " + stopwatch1.ElapsedMilliseconds.ToString()); return(new Response() { FileContent = string.Empty, FileName = "Concatenated_Table_Of_Contents.pdf", Message = "Files Concatenated successfully to: Concatenated_Table_Of_Contents.pdf file", Success = true }); } catch (Exception ex) { return(new Response() { FileContent = string.Empty, FileName = "", Message = "Could not concatenate files. " + ex.Message, Success = false }); } }
public static void CompletedCode() { // ExStart:CompletedCode // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles(); // Create PdfFileEditor object PdfFileEditor pdfEditor = new PdfFileEditor(); // Create a MemoryStream object to hold the resultant PDf file using (MemoryStream Concatenated_Stream = new MemoryStream()) { // Save concatenated output file pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), Concatenated_Stream); // Insert a blank page at the begining of concatenated file to display Table of Contents Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(Concatenated_Stream); // Insert a empty page in a PDF concatenated_pdfDocument.Pages.Insert(1); // Hold the resultnat file with empty page added using (MemoryStream Document_With_BlankPage = new MemoryStream()) { // Save output file concatenated_pdfDocument.Save(Document_With_BlankPage); using (var Document_with_TOC_Heading = new MemoryStream()) { // Add Table Of Contents logo as stamp to PDF file PdfFileStamp fileStamp = new PdfFileStamp(); // Find the input file fileStamp.BindPdf(Document_With_BlankPage); // Set Text Stamp to display string Table Of Contents Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp stamp.SetOrigin((new PdfFileInfo(Document_With_BlankPage).GetPageWidth(1) / 3), 700); // Set particular pages stamp.Pages = new int[] { 1 }; // Add stamp to PDF file fileStamp.AddStamp(stamp); // Create stamp text for first item in Table Of Contents var Document1_Link = new Aspose.Pdf.Facades.Stamp(); Document1_Link.BindLogo(new FormattedText("1 - Link to Document 1", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp Document1_Link.SetOrigin(150, 650); // Set particular pages on which stamp should be displayed Document1_Link.Pages = new int[] { 1 }; // Add stamp to PDF file fileStamp.AddStamp(Document1_Link); // Create stamp text for second item in Table Of Contents var Document2_Link = new Aspose.Pdf.Facades.Stamp(); Document2_Link.BindLogo(new FormattedText("2 - Link to Document 2", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp Document2_Link.SetOrigin(150, 620); // Set particular pages on which stamp should be displayed Document2_Link.Pages = new int[] { 1 }; // Add stamp to PDF file fileStamp.AddStamp(Document2_Link); // Save updated PDF file fileStamp.Save(Document_with_TOC_Heading); fileStamp.Close(); // Now we need to add Heading for Table Of Contents and links for documents PdfContentEditor contentEditor = new PdfContentEditor(); // Bind the PDF file in which we added the blank page contentEditor.BindPdf(Document_with_TOC_Heading); // Create link for first document contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650, 100, 20), 2, 1, System.Drawing.Color.Transparent); // Create link for Second document // We have used new PdfFileInfo("d:/pdftest/Input1.pdf").NumberOfPages + 2 as PdfFileInfo.NumberOfPages(..) returns the page count for first document // and 2 is because, second document will start at Input1+1 and 1 for the page containing Table Of Contents. contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 620, 100, 20), new PdfFileInfo(dataDir + "Input1.pdf").NumberOfPages + 2, 1, System.Drawing.Color.Transparent); // Save updated PDF contentEditor.Save(dataDir + "Concatenated_Table_Of_Contents.pdf"); } } } // ExEnd:CompletedCode }
/// <summary> /// 輸入 DataTable 轉成 有浮水印 的 PDF /// </summary> /// <param name="dt"></param> /// <param name="columnNameMappings"></param> /// <param name="folderName"></param> /// <param name="watermark"></param> /// <param name="pot"></param> /// <returns>產生的 pdf 檔名 (fullpath) </returns> private static string GenPDF(DataTable dt, Dictionary <string, string> columnNameMappings , string folderName, string watermark, PageOrientationType pot) { ChangeColumnDisplayName(dt, columnNameMappings); //output file name var fileNameWithoutExt = $"{Guid.NewGuid().ToString("N")}"; var outputExcel = Path.Combine(folderName, $"{fileNameWithoutExt}_tmp.xlsx"); var tempPdf = Path.Combine(folderName, $"{fileNameWithoutExt}_tmp.pdf"); var outputPdf = Path.Combine(folderName, $"{fileNameWithoutExt}.pdf"); //proc excel // Instantiating a Workbook object var workbook = new Workbook(); var worksheet = workbook.Worksheets[0]; worksheet.Cells.ImportDataTable(dt, true, "A1"); worksheet.AutoFitColumns(); worksheet.AutoFitRows(); var range = worksheet.Cells.MaxDisplayRange; var pageSetup = workbook.Worksheets[0].PageSetup; //var titleEndColumnName = CellsHelper.ColumnIndexToName(range.ColumnCount-1); //pageSetup.PrintTitleColumns = $"$A:${titleEndColumnName}"; pageSetup.PrintTitleRows = "$1:$1"; pageSetup.IsPercentScale = true; pageSetup.Orientation = pot; //border //Setting border for each cell in the range var style = workbook.CreateStyle(); var colorBlack = System.Drawing.Color.Black; style.SetBorder(BorderType.BottomBorder, CellBorderType.Medium, colorBlack); style.SetBorder(BorderType.LeftBorder, CellBorderType.Medium, colorBlack); style.SetBorder(BorderType.RightBorder, CellBorderType.Medium, colorBlack); style.SetBorder(BorderType.TopBorder, CellBorderType.Medium, colorBlack); range.SetStyle(style); // Saving the Excel file //workbook.Save(outputExcel); //workbook.Save(tempPdf); //save to stream var pdfStream = new MemoryStream(); workbook.Save(pdfStream, Aspose.Cells.SaveFormat.Pdf); var pdfDocument = new Aspose.Pdf.Document(pdfStream); if (!string.IsNullOrWhiteSpace(watermark)) { //針對 PDF 加入 Watermark Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp(); aStamp.Rotation = 45; var textStamp = new TextStamp(watermark); //set properties of the stamp // textStamp.Background = true; textStamp.Opacity = 0.2; textStamp.TextState.FontSize = 60.0F; textStamp.HorizontalAlignment = HorizontalAlignment.Center; textStamp.VerticalAlignment = VerticalAlignment.Center; textStamp.RotateAngle = aStamp.Rotation; textStamp.TextState.Font = FontRepository.FindFont("Arial"); textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Gray; foreach (var page in pdfDocument.Pages) { page.AddStamp(textStamp); } } pdfDocument.Save(outputPdf); return(outputPdf); }
public static void UploadPic(List <shap> shapes, string filename, string aspectRatio) { Document doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf")); //Create image stamp ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png")); for (int i = 0; i < shapes.Count; i++) { //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); float shapeX = (shapes[i].x * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeY = (shapes[i].y * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeW = (shapes[i].w * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeH = (shapes[i].h * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); double yaxis = (float)(doc.Pages[shapes[i].p].Rect.URY - (shapeH + shapeY)); var isSpecial = true;//regexItem.IsMatch(shapes[i].imName); if (shapes[i].Itype == "highlight" || shapes[i].Itype == "image") { if (shapes[i].Itype == "highlight") { imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png")); } else { imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("Images/" + shapes[i].imName)); } imageStamp.Background = false; imageStamp.XIndent = (float)(shapeX); imageStamp.YIndent = (float)(yaxis); imageStamp.Height = shapeH; imageStamp.Width = shapeW; //Add stamp to particular page doc.Pages[shapes[i].p].AddStamp(imageStamp); } else if (shapes[i].Itype == "text") { /* * // create TextBuilder for first page * TextBuilder tb = new TextBuilder(doc.Pages[shapes[i].p]); * * // TextFragment with sample text * TextFragment fragment = new TextFragment(shapes[i].t); * * // set the font for TextFragment * fragment.TextState.Font = FontRepository.FindFont(shapes[i].n); * fragment.TextState.FontSize = Convert.ToInt32(shapes[i].s); * if (shapes[i].wt == "bold") * { * fragment.TextState.FontStyle = FontStyles.Bold; * } * * if (shapes[i].st == "italic") * { * fragment.TextState.FontStyle = FontStyles.Italic; * } * * // set the formatting of text as Underline * // fragment.TextState.Underline = true; * fragment.TextState.ForegroundColor = GetColor(shapes[i].c); * // specify the position where TextFragment needs to be placed * fragment.Position = new Position((float)(shapeX), (float)(yaxis)); * * // fragment.Rectangle.Rotate((360 - (Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI); * * // append TextFragment to PDF file * tb.AppendText(fragment); */ //create text stamp TextStamp textStamp = new TextStamp(shapes[i].t); //set whether stamp is background // textStamp.Background = true; //set origin textStamp.XIndent = (float)(shapeX); textStamp.YIndent = (float)(yaxis); //rotate stamp textStamp.RotateAngle = 360 - ((Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI); //set text properties textStamp.TextState.Font = FontRepository.FindFont(shapes[i].n); textStamp.TextState.FontSize = Convert.ToInt32(shapes[i].s) * 0.75f; if (shapes[i].wt == "bold") { textStamp.TextState.FontStyle = FontStyles.Bold; } if (shapes[i].st == "italic") { textStamp.TextState.FontStyle = FontStyles.Italic; } textStamp.TextState.ForegroundColor = GetColor(shapes[i].c); //add stamp to particular page doc.Pages[shapes[i].p].AddStamp(textStamp); } else if (shapes[i].Itype == "field" && isSpecial) { if (shapes[i].fieldType == "Text") { // Get a field TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as TextBoxField; // Modify field value textBoxField.Value = shapes[i].t; } else if (shapes[i].fieldType == "CheckBox") { // Get a field CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as CheckboxField; if (shapes[i].t != "") { // Modify field value checkBoxField.Checked = Convert.ToBoolean(shapes[i].t); } } else if (shapes[i].fieldType == "Radio") { RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(shapes[i].imName)]; RadioButtonField rbf = (RadioButtonField)field.Parent; if (Convert.ToBoolean(shapes[i].t)) { rbf.Selected = rbf.Options[field.OptionName].Index; } else { field.ActiveState = "Off"; } } else if (shapes[i].fieldType == "ComboBox") { // Get a field ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as ComboBoxField; var values = shapes[i].t.Split(new string[] { "^^^" }, StringSplitOptions.None)[0]; foreach (var item in comboBoxField.Options.Cast <Option>()) { if (item.Value == values) { comboBoxField.Selected = item.Index; } } } } } doc.Save(HttpContext.Current.Server.MapPath("Convert/Export.pdf")); }
public static void CompletedCode() { // ExStart:CompletedCode // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles(); // Create PdfFileEditor object PdfFileEditor pdfEditor = new PdfFileEditor(); // Create a MemoryStream object to hold the resultant PDf file using (MemoryStream Concatenated_Stream = new MemoryStream()) { // Save concatenated output file pdfEditor.Concatenate(new FileStream(dataDir + "input1.pdf", FileMode.Open), new FileStream(dataDir + "input2.pdf", FileMode.Open), Concatenated_Stream); // Insert a blank page at the begining of concatenated file to display Table of Contents Aspose.Pdf.Document concatenated_pdfDocument = new Aspose.Pdf.Document(Concatenated_Stream); // Insert a empty page in a PDF concatenated_pdfDocument.Pages.Insert(1); // Hold the resultnat file with empty page added using (MemoryStream Document_With_BlankPage = new MemoryStream()) { // Save output file concatenated_pdfDocument.Save(Document_With_BlankPage); using (var Document_with_TOC_Heading = new MemoryStream()) { // Add Table Of Contents logo as stamp to PDF file PdfFileStamp fileStamp = new PdfFileStamp(); // Find the input file fileStamp.BindPdf(Document_With_BlankPage); // Set Text Stamp to display string Table Of Contents Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new FormattedText("Table Of Contents", System.Drawing.Color.Maroon, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 18)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp stamp.SetOrigin((new PdfFileInfo(Document_With_BlankPage).GetPageWidth(1) / 3), 700); // Set particular pages stamp.Pages = new int[] { 1 }; // Add stamp to PDF file fileStamp.AddStamp(stamp); // Create stamp text for first item in Table Of Contents var Document1_Link = new Aspose.Pdf.Facades.Stamp(); Document1_Link.BindLogo(new FormattedText("1 - Link to Document 1", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp Document1_Link.SetOrigin(150, 650); // Set particular pages on which stamp should be displayed Document1_Link.Pages = new int[] { 1 }; // Add stamp to PDF file fileStamp.AddStamp(Document1_Link); // Create stamp text for second item in Table Of Contents var Document2_Link = new Aspose.Pdf.Facades.Stamp(); Document2_Link.BindLogo(new FormattedText("2 - Link to Document 2", System.Drawing.Color.Black, System.Drawing.Color.Transparent, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 12)); // Specify the origin of Stamp. We are getting the page width and specifying the X coordinate for stamp Document2_Link.SetOrigin(150, 620); // Set particular pages on which stamp should be displayed Document2_Link.Pages = new int[] { 1 }; // Add stamp to PDF file fileStamp.AddStamp(Document2_Link); // Save updated PDF file fileStamp.Save(Document_with_TOC_Heading); fileStamp.Close(); // Now we need to add Heading for Table Of Contents and links for documents PdfContentEditor contentEditor = new PdfContentEditor(); // Bind the PDF file in which we added the blank page contentEditor.BindPdf(Document_with_TOC_Heading); // Create link for first document contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 650, 100, 20), 2, 1, System.Drawing.Color.Transparent); // Create link for Second document // We have used new PdfFileInfo("d:/pdftest/Input1.pdf").NumberOfPages + 2 as PdfFileInfo.NumberOfPages(..) returns the page count for first document // And 2 is because, second document will start at Input1+1 and 1 for the page containing Table Of Contents. contentEditor.CreateLocalLink(new System.Drawing.Rectangle(150, 620, 100, 20), new PdfFileInfo(dataDir + "Input1.pdf").NumberOfPages + 2, 1, System.Drawing.Color.Transparent); // Save updated PDF contentEditor.Save( dataDir + "Concatenated_Table_Of_Contents.pdf"); } } } // ExEnd:CompletedCode }
public IHttpActionResult UploadPic(UploadPicModel uploadPicModel) { var fullPath = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId); var downloadFileName = "document.pdf"; var documentFileName = Path.Combine(Config.Configuration.WorkingDirectory, "Editor", uploadPicModel.documentId, downloadFileName); Document doc = new Document(documentFileName); //Create image stamp ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("/img/Test.png")); for (int i = 0; i < uploadPicModel.shapes.Count; i++) { //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); float shapeX = (uploadPicModel.shapes[i].x * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); float shapeY = (uploadPicModel.shapes[i].y * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); float shapeW = (uploadPicModel.shapes[i].w * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); float shapeH = (uploadPicModel.shapes[i].h * 72 / 150) / (float)Convert.ToDouble(uploadPicModel.shapes[i].ratio); double yaxis = (float)(doc.Pages[uploadPicModel.shapes[i].p].Rect.URY - (shapeH + shapeY)); var isSpecial = true; //regexItem.IsMatch(uploadPicModel.shapes[i].imName); if (uploadPicModel.shapes[i].Itype == "highlight" || uploadPicModel.shapes[i].Itype == "image") { imageStamp = uploadPicModel.shapes[i].Itype == "highlight" ? new ImageStamp(HttpContext.Current.Server.MapPath("/img/test.png")) : new ImageStamp(fullPath + uploadPicModel.shapes[i].imName); imageStamp.Background = false; imageStamp.XIndent = (float)(shapeX); imageStamp.YIndent = (float)(yaxis); imageStamp.Height = shapeH; imageStamp.Width = shapeW; //Add stamp to particular page doc.Pages[uploadPicModel.shapes[i].p].AddStamp(imageStamp); } else if (uploadPicModel.shapes[i].Itype == "text") { //create text stamp TextStamp textStamp = new TextStamp(uploadPicModel.shapes[i].t); textStamp.XIndent = (float)(shapeX); textStamp.YIndent = (float)(yaxis); //rotate stamp textStamp.RotateAngle = 360 - (Convert.ToDouble(uploadPicModel.shapes[i].fieldType) * 180 / Math.PI); //set text properties textStamp.TextState.Font = FontRepository.FindFont(uploadPicModel.shapes[i].n); textStamp.TextState.FontSize = Convert.ToInt32(uploadPicModel.shapes[i].s) * 0.75f; if (uploadPicModel.shapes[i].wt == "bold") { textStamp.TextState.FontStyle = FontStyles.Bold; } if (uploadPicModel.shapes[i].st == "italic") { textStamp.TextState.FontStyle = FontStyles.Italic; } textStamp.TextState.ForegroundColor = GetColor(uploadPicModel.shapes[i].c); //add stamp to particular page doc.Pages[uploadPicModel.shapes[i].p].AddStamp(textStamp); } else if (uploadPicModel.shapes[i].Itype == "field" && isSpecial) { if (uploadPicModel.shapes[i].fieldType == "Text") { // Get a field TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as TextBoxField; // Modify field value textBoxField.Value = uploadPicModel.shapes[i].t; } else if (uploadPicModel.shapes[i].fieldType == "CheckBox") { // Get a field CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as CheckboxField; if (uploadPicModel.shapes[i].t != "") { // Modify field value checkBoxField.Checked = Convert.ToBoolean(uploadPicModel.shapes[i].t); } } else if (uploadPicModel.shapes[i].fieldType == "Radio") { RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)]; RadioButtonField rbf = (RadioButtonField)field.Parent; if (Convert.ToBoolean(uploadPicModel.shapes[i].t)) { rbf.Selected = rbf.Options[field.OptionName].Index; } else { field.ActiveState = "Off"; } } else if (uploadPicModel.shapes[i].fieldType == "ComboBox") { // Get a field ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(uploadPicModel.shapes[i].imName)] as ComboBoxField; var values = uploadPicModel.shapes[i].t.Split(new[] { "^^^" }, StringSplitOptions.None)[0]; foreach (var item in comboBoxField.Options.Cast <Option>()) { if (item.Value == values) { comboBoxField.Selected = item.Index; } } } } } doc.Save(Config.Configuration.OutputDirectory + "/Export.pdf"); return(Ok(new DocStatusModel())); }
public static void UploadPic(List<shap> shapes , string filename, string aspectRatio) { Document doc = new Document(HttpContext.Current.Server.MapPath("Convert/output.pdf")); //Create image stamp ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png")); for (int i = 0; i < shapes.Count; i++) { //create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); float shapeX = (shapes[i].x * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeY = (shapes[i].y * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeW = (shapes[i].w * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); float shapeH = (shapes[i].h * 72 / 150) / (float)Convert.ToDouble(shapes[i].ratio); double yaxis = (float)(doc.Pages[shapes[i].p].Rect.URY - (shapeH + shapeY)); var isSpecial = true;//regexItem.IsMatch(shapes[i].imName); if (shapes[i].Itype == "highlight" || shapes[i].Itype == "image") { if (shapes[i].Itype == "highlight") { imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("test.png")); } else { imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("Images/"+shapes[i].imName)); } imageStamp.Background = false; imageStamp.XIndent = (float)(shapeX); imageStamp.YIndent = (float)(yaxis); imageStamp.Height = shapeH; imageStamp.Width = shapeW; //Add stamp to particular page doc.Pages[shapes[i].p].AddStamp(imageStamp); } else if(shapes[i].Itype == "text") { /* // create TextBuilder for first page TextBuilder tb = new TextBuilder(doc.Pages[shapes[i].p]); // TextFragment with sample text TextFragment fragment = new TextFragment(shapes[i].t); // set the font for TextFragment fragment.TextState.Font = FontRepository.FindFont(shapes[i].n); fragment.TextState.FontSize = Convert.ToInt32(shapes[i].s); if (shapes[i].wt == "bold") { fragment.TextState.FontStyle = FontStyles.Bold; } if (shapes[i].st == "italic") { fragment.TextState.FontStyle = FontStyles.Italic; } // set the formatting of text as Underline // fragment.TextState.Underline = true; fragment.TextState.ForegroundColor = GetColor(shapes[i].c); // specify the position where TextFragment needs to be placed fragment.Position = new Position((float)(shapeX), (float)(yaxis)); // fragment.Rectangle.Rotate((360 - (Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI); // append TextFragment to PDF file tb.AppendText(fragment); */ //create text stamp TextStamp textStamp = new TextStamp(shapes[i].t); //set whether stamp is background // textStamp.Background = true; //set origin textStamp.XIndent = (float)(shapeX); textStamp.YIndent = (float)(yaxis); //rotate stamp textStamp.RotateAngle = 360 - ((Convert.ToDouble(shapes[i].fieldType)) * 180 / Math.PI); //set text properties textStamp.TextState.Font = FontRepository.FindFont(shapes[i].n); textStamp.TextState.FontSize = Convert.ToInt32(shapes[i].s) * 0.75f; if (shapes[i].wt == "bold") { textStamp.TextState.FontStyle = FontStyles.Bold; } if (shapes[i].st == "italic") { textStamp.TextState.FontStyle = FontStyles.Italic; } textStamp.TextState.ForegroundColor = GetColor(shapes[i].c); //add stamp to particular page doc.Pages[shapes[i].p].AddStamp(textStamp); } else if (shapes[i].Itype == "field" && isSpecial) { if (shapes[i].fieldType == "Text") { // Get a field TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as TextBoxField; // Modify field value textBoxField.Value = shapes[i].t; } else if (shapes[i].fieldType == "CheckBox") { // Get a field CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as CheckboxField; if(shapes[i].t != "") // Modify field value checkBoxField.Checked = Convert.ToBoolean(shapes[i].t); } else if (shapes[i].fieldType == "Radio") { RadioButtonOptionField field = (RadioButtonOptionField)doc.Form.Fields[Convert.ToInt32(shapes[i].imName)]; RadioButtonField rbf = (RadioButtonField)field.Parent; if (Convert.ToBoolean(shapes[i].t)) { rbf.Selected = rbf.Options[field.OptionName].Index; } else { field.ActiveState = "Off"; } } else if (shapes[i].fieldType == "ComboBox") { // Get a field ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(shapes[i].imName)] as ComboBoxField; var values = shapes[i].t.Split(new string[]{"^^^"},StringSplitOptions.None)[0]; foreach (var item in comboBoxField.Options.Cast<Option>()) { if (item.Value == values) { comboBoxField.Selected = item.Index; } } } } } doc.Save(HttpContext.Current.Server.MapPath("Convert/Export.pdf")); }