public void PutStampAnnotationTest() { UploadFile(AttachmentFile, AttachmentFile); StampAnnotation annotation = new StampAnnotation(Rect: new Rectangle(100, 100, 200, 200)) { Name = "Updated Test", Flags = new List <AnnotationFlags> { AnnotationFlags.Hidden, AnnotationFlags.NoView }, HorizontalAlignment = HorizontalAlignment.Center, RichText = "Rich Text Updated", Subject = "Subj Updated", ZIndex = 1, Title = "Title Updated", Modified = "01/01/2018 00:00:00.000 AM", FilePath = Path.Combine(TempFolder, AttachmentFile), }; var lineResponse = PdfApi.GetDocumentStampAnnotations(Name, folder: TempFolder); string annotationId = lineResponse.Annotations.List[0].Id; var response = PdfApi.PutStampAnnotation(Name, annotationId, annotation, folder: TempFolder); Assert.That(response.Code, Is.EqualTo(200)); }
public void PutStampAnnotationTest() { UploadFile(AttachmentFile, AttachmentFile); StampAnnotation annotation = new StampAnnotation() { Name = "Updated Test", Rect = new Rectangle(100, 100, 200, 200), Flags = new List <AnnotationFlags> { AnnotationFlags.Hidden, AnnotationFlags.NoView }, HorizontalAlignment = HorizontalAlignment.Center, RichText = "Rich Text Updated", Subject = "Subj Updated", ZIndex = 1, Title = "Title Updated", Modified = "01/01/2018 00:00:00.000 AM", FilePath = Path.Combine(FolderName, AttachmentFile), }; var lineResponse = api.GetDocumentStampAnnotations(Name, folder: FolderName); string annotationId = lineResponse.Annotations.List[0].Id; var response = api.PutStampAnnotation(Name, annotationId, annotation, folder: FolderName); Console.WriteLine(response); }
public static void Run() { //ExStart:ExtractTextFromStampAnnotation string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks(); Document doc = new Document(dataDir + "test.pdf"); StampAnnotation annot = doc.Pages[1].Annotations[3] as StampAnnotation; TextAbsorber ta = new TextAbsorber(); XForm ap = annot.Appearance["N"]; ta.Visit(ap); Console.WriteLine(ta.Text); //ExEnd: ExtractTextFromStampAnnotation }
// Вставляет указанное изображение на страницу PDF-документа private static void InsertImage(Page page, ImageHelper imageHelper, double x, double y) { using (var memoryStream = new MemoryStream()) { imageHelper.Bitmap.Save(memoryStream, ImageFormat.Png); memoryStream.Seek(0, SeekOrigin.Begin); var annotation = new StampAnnotation(page, new Rectangle(x, y, x + imageHelper.Width, y + imageHelper.Height)); annotation.Image = memoryStream; page.Annotations.Add(annotation); } }
public List <StampAnnotation> GetAppearance(OfdReader ctx, AtomicSignId idProvider) { // 解析OFD页码获取页面对应的ID string id = string.Empty; //ctx.getPageObjectId(page).ref (); StampAnnotation annotation = new StampAnnotation(null) { Id = idProvider.IncrementAndGet(), Boundary = (new StBox(Tlx, Tly, Width, Height)), PageRef = string.Empty }; List <StampAnnotation> res = new List <StampAnnotation>(1) { annotation }; return(res); }
public void CreatePDF(Stream stream) { var doc = new GcPdfDocument(); // Load an existing PDF to which we will add a stamp annotation // (see LoadPDF for details on loading documents): var jsFile = Path.Combine("Resources", "PDFs", "The-Rich-History-of-JavaScript.pdf"); using (var fs = new FileStream(jsFile, FileMode.Open, FileAccess.Read)) { doc.Load(fs); var rect = new RectangleF(PointF.Empty, doc.Pages[0].Size); // Create a FormXObject to use as the stamp appearance: var fxo = new FormXObject(doc, rect); // Get an image from the resources, and draw it on the FormXObject's graphics // (see Transformations for details on using GcGraphics.Transform): using (var image = Image.FromFile(Path.Combine("Resources", "ImagesBis", "draft-copy-450x72.png"))) { var center = new Vector2(fxo.Bounds.Width / 2, fxo.Bounds.Height / 2); fxo.Graphics.Transform = Matrix3x2.CreateRotation((float)(-55 * Math.PI) / 180f, center) * Matrix3x2.CreateScale(6, center); fxo.Graphics.DrawImage(image, fxo.Bounds, null, ImageAlign.CenterImage); // Loop over pages, add a stamp to each page: foreach (var page in doc.Pages) { // Create a StampAnnotation over the whole page: var stamp = new StampAnnotation() { Icon = StampAnnotationIcon.Draft.ToString(), Name = "draft", Page = page, Rect = rect, UserName = "******" }; // Re-use the same FormXObject on all pages: stamp.AppearanceStreams.Normal.Default = fxo; } // Done: doc.Save(stream); } } }
public void CreatePDF(Stream stream) { var doc = new GcPdfDocument(); var date = new DateTime(1961, 4, 12, 6, 7, 0, DateTimeKind.Utc); // Mark the document as PDF/A-3u conformant: doc.ConformanceLevel = PdfAConformanceLevel.PdfA3u; var fnt = Font.FromFile(Path.Combine("Resources", "Fonts", "arial.ttf")); var gap = 36; // PDF/A-3a requires all content to be tagged so create and populate StructElement when rendering: StructElement sePart = new StructElement("Part"); doc.StructTreeRoot.Children.Add(sePart); TextLayout tl = null; // Add 3 pages with sample content tagged according to PDF/A rules: for (int pageNo = 1; pageNo <= 3; ++pageNo) { var page = doc.Pages.Add(); var g = page.Graphics; float y = 72; if (doc.Pages.Count == 1) { // Create paragraph element: var seParagraph = new StructElement("P") { DefaultPage = page }; // Add it to Part element: sePart.Children.Add(seParagraph); tl = g.CreateTextLayout(); tl.MarginAll = 72; tl.MaxWidth = page.Size.Width; tl.DefaultFormat.Font = fnt; tl.DefaultFormat.FontBold = true; tl.DefaultFormat.FontSize = 20; tl.Append("PDF/A-3A Document"); // PerformLayout is done automatically in a new TextLayout or after a Clear(): //tl.PerformLayout(true); // Draw TextLayout within tagged content: g.BeginMarkedContent(new TagMcid("P", 0)); g.DrawTextLayout(tl, PointF.Empty); g.EndMarkedContent(); y = tl.ContentRectangle.Bottom + gap; seParagraph.ContentItems.Add(new McidContentItemLink(0)); } // Add some sample paragraphs tagged according to PDF/A rules: for (int i = 1; i <= 3; ++i) { // Create paragraph element: var seParagraph = new StructElement("P") { DefaultPage = page }; // Add it to Part element: sePart.Children.Add(seParagraph); var sb = new StringBuilder(); sb.Append(string.Format("Paragraph {0} on page {1}: ", i, pageNo)); sb.Append(Common.Util.LoremIpsum(1, 2, 4, 5, 10)); var para = sb.ToString(); tl.Clear(); tl.DefaultFormat.FontSize = 14; tl.DefaultFormat.FontBold = false; tl.MarginTop = y; tl.Append(para); // Draw TextLayout within tagged content: g.BeginMarkedContent(new TagMcid("P", i)); g.DrawTextLayout(tl, PointF.Empty); g.EndMarkedContent(); y += tl.ContentHeight + gap; // Add content item to paragraph StructElement: seParagraph.ContentItems.Add(new McidContentItemLink(i)); // PDF/A-3 allows to embed files into document, but they should be associated with some document element // add embedded file associated with seParagraph: var ef1 = EmbeddedFileStream.FromBytes(doc, Encoding.UTF8.GetBytes(para)); // ModificationDate and MimeType should be specified in case of PDF/A: ef1.ModificationDate = date; ef1.MimeType = "text/plain"; var fn = string.Format("Page{0}_Paragraph{1}.txt", pageNo, i); var fs1 = FileSpecification.FromEmbeddedStream(fn, ef1); // Relationship should be specified in case of PDF/A: fs1.Relationship = AFRelationship.Unspecified; doc.EmbeddedFiles.Add(fn, fs1); seParagraph.AssociatedFiles.Add(fs1); } } // PDF/A-3 allows transparency drawing in PDF file, add some: var gpage = doc.Pages[0].Graphics; gpage.FillRectangle(new RectangleF(20, 20, 200, 200), Color.FromArgb(40, Color.Red)); // PDF/A-3 allows to use FormXObjects, add one with transparency: var r = new RectangleF(0, 0, 144, 72); var fxo = new FormXObject(doc, r); var gfxo = fxo.Graphics; gfxo.FillRectangle(r, Color.FromArgb(40, Color.Violet)); TextFormat tf = new TextFormat() { Font = fnt, FontSize = 16, ForeColor = Color.FromArgb(100, Color.Black), }; gfxo.DrawString("FormXObject", tf, r, TextAlignment.Center, ParagraphAlignment.Center); gfxo.DrawRectangle(r, Color.Blue, 3); gpage.DrawForm(fxo, new RectangleF(300, 250, r.Width, r.Height), null, ImageAlign.ScaleImage); // PDF/A-3 allows to use embedded files, but each embedded file must be associated with a document's element: EmbeddedFileStream ef = EmbeddedFileStream.FromFile(doc, Path.Combine("Resources", "WordDocs", "ProcurementLetter.docx")); // ModificationDate and MimeType should be specified for EmbeddedFile in PDF/A: ef.ModificationDate = date; ef.MimeType = "application/msword"; var fs = FileSpecification.FromEmbeddedFile(ef); fs.Relationship = AFRelationship.Unspecified; doc.EmbeddedFiles.Add("ProcurementLetter.docx", fs); // Associate embedded file with the document: doc.AssociatedFiles.Add(fs); // Add an attachment associated with an annotation: var sa = new StampAnnotation() { UserName = "******", Font = fnt, Rect = new RectangleF(300, 36, 220, 72), }; sa.Flags |= AnnotationFlags.Print; // Use a FormXObject to represent the stamp annotation: var stampFxo = new FormXObject(doc, new RectangleF(PointF.Empty, sa.Rect.Size)); var gstampFxo = stampFxo.Graphics; gstampFxo.FillRectangle(stampFxo.Bounds, Color.FromArgb(40, Color.Green)); gstampFxo.DrawString("Stamp Annotation\nassociated with minerva.jpg", tf, stampFxo.Bounds, TextAlignment.Center, ParagraphAlignment.Center); gstampFxo.DrawRectangle(stampFxo.Bounds, Color.Green, 3); // sa.AppearanceStreams.Normal.Default = stampFxo; doc.Pages[0].Annotations.Add(sa); ef = EmbeddedFileStream.FromFile(doc, Path.Combine("Resources", "Images", "minerva.jpg")); ef.ModificationDate = date; ef.MimeType = "image/jpeg"; fs = FileSpecification.FromEmbeddedFile(ef); fs.Relationship = AFRelationship.Unspecified; doc.EmbeddedFiles.Add("minerva.jpg", fs); sa.AssociatedFiles.Add(fs); // Mark the document as conforming to Tagged PDF conventions (required for PDF/A): doc.MarkInfo.Marked = true; // Metadata.CreatorTool and DocumentInfo.Creator should be the same for a PDF/A document: doc.Metadata.CreatorTool = doc.DocumentInfo.Creator; // A title should be specified for PDF/A document: doc.Metadata.Title = "GcPdf Document"; doc.ViewerPreferences.DisplayDocTitle = true; // Done: doc.Save(stream); }
public static BaseAnnotation Translate(ImageDoc.Annotation annotation, float scale, ColourFormat colourFormat, PointF controlOffset, PointF imageOffset) { BaseAnnotation imagingAnnotation = null; ImageDoc.ImagingAnnotationTypes annType = (ImageDoc.ImagingAnnotationTypes) Enum.Parse(typeof(ImageDoc.ImagingAnnotationTypes), annotation.AnnotationType); switch (annType) { case ImageDoc.ImagingAnnotationTypes.FreeLine: { imagingAnnotation = new FreeLineAnnotation(SimpleTypeToColor(annotation.LineColor), annotation.LineThickness, scale, colourFormat, controlOffset, imageOffset); break; } case ImageDoc.ImagingAnnotationTypes.Highlighter: case ImageDoc.ImagingAnnotationTypes.Polygon: { imagingAnnotation = new PolygonAnnotation(SimpleTypeToColor(annotation.LineColor), annotation.LineThickness, scale, colourFormat, controlOffset, imageOffset); } break; case ImageDoc.ImagingAnnotationTypes.Stamp: { imagingAnnotation = new StampAnnotation(annotation.LineThickness, scale, colourFormat, controlOffset, imageOffset); } break; case ImageDoc.ImagingAnnotationTypes.StraightLine: { imagingAnnotation = new StraightLineAnnotation(SimpleTypeToColor(annotation.LineColor), annotation.LineThickness, scale, colourFormat, controlOffset, imageOffset); } break; case ImageDoc.ImagingAnnotationTypes.TextAnnotation: { // Top left of the text Point topLeft = new Point((int)annotation.Rect.TopLeft.X, (int)annotation.Rect.TopLeft.Y); imagingAnnotation = new TextAnnotation(topLeft, controlOffset, imageOffset, scale, colourFormat); } break; case ImageDoc.ImagingAnnotationTypes.Svg: { // Top left of the text Point topLeft = new Point((int)annotation.Rect.TopLeft.X, (int)annotation.Rect.TopLeft.Y); imagingAnnotation = new SvgAnnotation(topLeft, controlOffset, imageOffset, scale, colourFormat); (imagingAnnotation as SvgAnnotation).ImageName = annotation.SvgImageName; } break; } if ((imagingAnnotation is PolygonAnnotation)) { (imagingAnnotation as PolygonAnnotation).ShapeName = annotation.SvgImageName; foreach (ImageDoc.Point point in annotation.Points) { Point intPoint = new Point((int)point.X, (int)point.Y); (imagingAnnotation as PolygonAnnotation).AddPoint(intPoint); } // This forces the initialisation of some required objects (imagingAnnotation as PolygonAnnotation).EndDrawing(); } if ((imagingAnnotation is StampAnnotation)) { foreach (ImageDoc.Point point in annotation.Points) { Point intPoint = new Point((int)point.X, (int)point.Y); (imagingAnnotation as StampAnnotation).Points.Add(intPoint); } } if ((imagingAnnotation is TextAnnotation)) { (imagingAnnotation as TextAnnotation).Text = annotation.Text; (imagingAnnotation as TextAnnotation).TextFont = annotation.Font.ToFont(); (imagingAnnotation as TextAnnotation).TextColor = SimpleTypeToColor(annotation.TextColor); } imagingAnnotation.Rect = SimpleTypeToRect(annotation.Rect); imagingAnnotation.Filled = true; imagingAnnotation.FillColor = SimpleTypeToColor(annotation.FillColor); imagingAnnotation.FillOpacity = annotation.FillOpacity; //imagingAnnotation.Outline = annotation.Outline; return imagingAnnotation; }