public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks(); // Create TextState object to transfer advanced properties TextState ts = new TextState(); // Set color for stroke ts.StrokingColor = Color.Gray; // Set text rendering mode ts.RenderingMode = TextRenderingMode.StrokeText; // Load an input PDF document Facades.PdfFileStamp fileStamp = new Facades.PdfFileStamp(new Aspose.Pdf.Document(dataDir + "input.pdf")); Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(new Facades.FormattedText("PAID IN FULL", System.Drawing.Color.Gray, "Arial", Facades.EncodingType.Winansi, true, 78)); // Bind TextState stamp.BindTextState(ts); // Set X,Y origin stamp.SetOrigin(100, 100); stamp.Opacity = 5; stamp.BlendingSpace = Facades.BlendingColorSpace.DeviceRGB; stamp.Rotation = 45.0F; stamp.IsBackground = false; // Add Stamp fileStamp.AddStamp(stamp); fileStamp.Save(dataDir + "ouput_out.pdf"); fileStamp.Close(); // ExEnd:1 }
internal static void AddStampToPDF(string filename, string text) { var path = $"original\\{filename}"; var formattedText = new Aspose.Pdf.Facades.FormattedText( text, System.Drawing.Color.Black, Aspose.Pdf.Facades.FontStyle.Helvetica, Aspose.Pdf.Facades.EncodingType.Winansi, true, 14); using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(path)) { var fileStamp = new Aspose.Pdf.Facades.PdfFileStamp(doc); // Create stamp Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); stamp.BindLogo(formattedText); stamp.Pages = new int[] { 1 }; fileStamp.AddStamp(stamp); fileStamp.Save($"revised\\stamped_{filename}"); fileStamp.Close(); } Console.WriteLine("stamped...."); }
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") { imageStamp = shapes[i].Itype == "highlight" ? new ImageStamp(HttpContext.Current.Server.MapPath("test.png")) : 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[] { "^^^" }, 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")); }