C#如何給PDF文檔添加註釋

使用C#語言添加PDF註釋當中,須要使用到Spire.PDF for .NET。能夠在官網上下載免費版(https://www.e-iceblue.cn/Downloads/Free-Spire-PDF-NET.html)。html

注意,須要添加dll文件到程序中,而且也要添加using 指令編程

1.給文本添加註釋編程語言

主要代碼以下:code

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13);
string text = "HelloWorld";
PointF point = new PointF(200, 100);
page.Canvas.DrawString(text, font, PdfBrushes.Red, point);

PdfTextMarkupAnnotation annotation1 = new PdfTextMarkupAnnotation("管理員", "通常來講,這是每一種計算機編程語言中最基本、最簡單的程序", text, new PointF(0, 0), font);
annotation1.Border = new PdfAnnotationBorder(0.75f);
annotation1.TextMarkupColor = Color.Green;
annotation1.Location = new PointF(point.X + doc.PageSettings.Margins.Left, point.Y + doc.PageSettings.Margins.Left);

(page as PdfNewPage).Annotations.Add(annotation1);
doc.SaveToFile("result.pdf");

效果示例:orm

 

2.添加自由文本註釋htm

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

RectangleF rect = new RectangleF(0, 40, 150, 50);
PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(rect);
textAnnotation.Text = "Free text annotation ";

PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 10);
PdfAnnotationBorder border = new PdfAnnotationBorder(1f);
textAnnotation.Font = font;
textAnnotation.Border = border;
textAnnotation.BorderColor = Color. Purple;
textAnnotation.LineEndingStyle = PdfLineEndingStyle.Circle;

textAnnotation.Color = Color. Pink;
textAnnotation.Opacity = 0.8f;

page.AnnotationsWidget.Add(textAnnotation); 

doc.SaveToFile("FreeTextAnnotation.pdf", FileFormat.PDF);
System.Diagnostics.Process.Start("FreeTextAnnotation.pdf");

效果示例:ci

本文爲轉載文章,詳細信息能夠查看原文。get

相關文章
相關標籤/搜索