Аннотация - отличный способ сделать заметки о документах, изображениях или других типах файлов. Их можно лучше использовать, чтобы выделить или объяснить конкретные моменты, предоставить обратную связь или обмениваться информацией в файле данных. Аннотация также могут быть созданы с помощью особых видов инструментов разметки, чтобы пробиться, подчеркнуть или выделить текст или изображения в документе. Существует множество различных типов аннотаций, которые разработчики могут использовать для различных целей, таких как прямоугольная область, полилина, стрелка, эллипс, ссылка, водяной знак и аннотация текста. Если вы хотите автоматизировать процессы аннотации документа и изображения, вы можете использовать API -интерфейсы GroupDocs.annotation для платформ .NET и Java. Эти мощные библиотеки созданы для работы с PDF, Microsoft Office (Word, Excel, PowerPoint, Visio), OpenDocument, чертежами CAD и изображениями, а также HTML и файлами электронной почты, позволяющие разработчикам приложений .NET и Java добавлять аннотации в документ в легкий путь. API предназначены для использования в языках C#, ASP.NET, VB.NET и Java, в нескольких рамках и средах.
Перед началом работы, пожалуйста, проверьте .NET а также Java Руководства по установке GroupDocs.annotation API, чтобы помочь вам правильно настроить среду разработки.
Давайте посмотрим на некоторые варианты использования, предназначенные для того, чтобы сделать процесс аннотирования документа удобным и простым для вас.
Как разработчик приложений, вы всегда ищете способы упростить процесс строительства приложений и сэкономить время на время.Именно здесь API GroupDocs.annotation приносят непревзойденное мастерство и предоставит вам правильную платформу.Используя эти легкие кроссплатформенные библиотеки, разработчики .NET и Java могут создавать функции, богатые и более умные решения для добавления аннотаций в PDF, а также документы Word, документы Excel и PowerPoint, а также файлы VSD, DWG, PNG и JPEG.
using (Annotator annotator = new Annotator("input.pdf"))
{
AreaAnnotation area = new AreaAnnotation
{
BackgroundColor = 65535,
Box = new Rectangle(100, 100, 100, 100),
CreatedOn = DateTime.Now,
Message = "This is area annotation",
Opacity = 0.7,
PageNumber = 0,
PenColor = 65535,
PenStyle = PenStyle.Dot,
PenWidth = 3,
Replies = new List
{
new Reply
{
Comment = "First comment",
RepliedOn = DateTime.Now
},
new Reply
{
Comment = "Second comment",
RepliedOn = DateTime.Now
}
}
};
annotator.Add(area);
annotator.Save("result.pdf");
}
using (Annotator annotator = new Annotator("input.pdf"))
{
ImageAnnotation area = new ImageAnnotation
{
Box = new Rectangle(100, 100, 100, 100),
Opacity = 0.7,
PageNumber = 0,
ImagePath = "www.google.com.ua/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png",
Angle = 100
};
annotator.Add(area);
annotator.Save("result.pdf");
}
Annotator annotator = new Annotator("inputPath");
try {
// Create an instance of Reply class and add comments
Reply reply1 = new Reply();
reply1.setComment("First comment");
reply1.setRepliedOn(Calendar.getInstance().getTime());
Reply reply2 = new Reply();
reply2.setComment("Second comment");
reply2.setRepliedOn(Calendar.getInstance().getTime());
java.util.List replies = new ArrayList();
replies.add(reply1);
replies.add(reply2);
// Create an instance of TextFieldAnnotation class and set options
TextFieldAnnotation textField = new TextFieldAnnotation();
textField.setBackgroundColor(65535);
textField.setBox(new Rectangle(100, 100, 100, 100));
textField.setCreatedOn(Calendar.getInstance().getTime());
textField.setText("Some text");
textField.setFontColor(65535);
textField.setFontSize((double)12);
textField.setMessage("This is text field annotation");
textField.setOpacity(0.7);
textField.setPageNumber(0);
textField.setPenStyle(PenStyle.Dot);
textField.setPenWidth((byte) 3);
textField.setReplies(replies);
// Add annotation and save to file
annotator.add(textField);
annotator.save("outputPath");
} finally {
if (annotator != null) {
annotator.dispose();
}
}
Annotator annotator = new Annotator("inputPath");
try {
// Create an instance of Reply class and add comments
Reply reply1 = new Reply();
reply1.setComment("First comment");
reply1.setRepliedOn(Calendar.getInstance().getTime());
Reply reply2 = new Reply();
reply2.setComment("Second comment");
reply2.setRepliedOn(Calendar.getInstance().getTime());
java.util.List replies = Arrays.asList(reply1, reply2);
List points = Arrays.asList(new Point(80, 730), new Point(240, 730), new Point(80, 650), new Point(240, 650));
// Create an instance of LinkAnnotation class and set options
LinkAnnotation link = new LinkAnnotation();
link.setCreatedOn(Calendar.getInstance().getTime());
link.setMessage("This is link annotation");
link.setOpacity(0.7);
link.setPageNumber(0);
link.setPoints(points);
link.setReplies(replies);
link.setUrl("https://www.google.com");
// Add annotation and save to file
annotator.add(link);
annotator.save("outputPath");
} finally {
if (annotator != null) {
annotator.dispose();
}
}
Текстовые водяные знаки обычно используются в официальных и личных файлах в качестве символа авторского права или товарного знака, даты истечения срока действия или в какой-либо другой форме текста, которую необходимо отобразить в документе.API API -интерфейсы GroupDocs.annotation позволяют добавлять аннотации водяных знаков в разные файлы данных как в .NET и Java.
using (Annotator annotator = new Annotator("input.pdf"))
{
WatermarkAnnotation watermark = new WatermarkAnnotation
{
Angle = 75,
Box = new Rectangle(200, 200, 100, 50),
CreatedOn = DateTime.Now,
Text = "Watermark",
FontColor = 65535,
FontSize = 12,
Message = "This is watermark annotation",
Opacity = 0.7,
AutoScale = true,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Replies = new List
{
new Reply
{
Comment = "First comment",
RepliedOn = DateTime.Now
},
new Reply
{
Comment = "Second comment",
RepliedOn = DateTime.Now
}
}
};
annotator.Add(watermark);
annotator.Save("result.pdf");
}
Annotator annotator = new Annotator("inputPath");
try {
// Create an instance of Reply class and add comments
Reply reply1 = new Reply();
reply1.setComment("First comment");
reply1.setRepliedOn(Calendar.getInstance().getTime());
Reply reply2 = new Reply();
reply2.setComment("Second comment");
reply2.setRepliedOn(Calendar.getInstance().getTime());
java.util.List replies = new ArrayList();
replies.add(reply1);
replies.add(reply2);
// Create an instance of WatermarkAnnotation class and set options
WatermarkAnnotation watermark = new WatermarkAnnotation();
watermark.setAngle((double) 75);
watermark.setBox(new Rectangle(200, 200, 100, 50));
watermark.setCreatedOn(Calendar.getInstance().getTime());
watermark.setText("Watermark");
watermark.setFontColor(65535);
watermark.setFontSize((double) 12);
watermark.setMessage("This is watermark annotation");
watermark.setOpacity(0.7);
watermark.setPageNumber(0);
watermark.setReplies(replies);
// Add annotation and save to file
annotator.add(watermark);
annotator.save("outputPath");
} finally {
if (annotator != null) {
annotator.dispose();
}
}
Чтобы отличить определенные части текста от других содержимого в документе, вам нужно будет применять украшения наценки текста, подчеркивая или вычеркнув текст.Такие функции разметки были интегрированы в наши API в форме подчеркивания и поражений, которые вы можете использовать в своих документах и изображениях.
using (Annotator annotator = new Annotator("input.pdf"))
{
SquigglyAnnotation squiggly = new SquigglyAnnotation
{
CreatedOn = DateTime.Now,
FontColor = 65535,
BackgroundColor = 16761035,
Message = "This is squiggly annotation",
Opacity = 0.7,
PageNumber = 0,
SquigglyColor = 1422623, //Supported only Word and PDF
Points = new List
{
new Point(80, 730), new Point(240, 730), new Point(80, 650), new Point(240, 650)
},
Replies = new List
{
new Reply
{
Comment = "First comment",
RepliedOn = DateTime.Now
},
new Reply
{
Comment = "Second comment",
RepliedOn = DateTime.Now
}
}
};
annotator.Add(squiggly);
annotator.Save("result.pdf");
}
using (Annotator annotator = new Annotator("input.pdf"))
{
StrikeoutAnnotation strikeout = new StrikeoutAnnotation
{
CreatedOn = DateTime.Now,
FontColor = 65535,
BackgroundColor = 16761035,
Message = "This is strikeout annotation",
Opacity = 0.7,
PageNumber = 0,
Points = new List
{
new Point(80, 730), new Point(240, 730), new Point(80, 650), new Point(240, 650)
},
Replies = new List
{
new Reply
{
Comment = "First comment",
RepliedOn = DateTime.Now
},
new Reply
{
Comment = "Second comment",
RepliedOn = DateTime.Now
}
}
};
annotator.Add(strikeout);
annotator.Save("result.pdf");
}
Annotator annotator = new Annotator("inputPath");
try {
// Create an instance of Reply class and add comments
Reply reply1 = new Reply();
reply1.setComment("First comment");
reply1.setRepliedOn(Calendar.getInstance().getTime());
Reply reply2 = new Reply();
reply2.setComment("Second comment");
reply2.setRepliedOn(Calendar.getInstance().getTime());
java.util.List replies = new ArrayList();
replies.add(reply1);
replies.add(reply2);
Point point1 = new Point(80, 730);
Point point2 = new Point(240, 730);
Point point3 = new Point(80, 650);
Point point4 = new Point(240, 650);
List points = new ArrayList();
points.add(point1);
points.add(point2);
points.add(point3);
points.add(point4);
// Create an instance of HighlightAnnotation class and set options
HighlightAnnotation highlight = new HighlightAnnotation();
highlight.setBackgroundColor(65535);
highlight.setCreatedOn(Calendar.getInstance().getTime());
highlight.setFontColor(0);
highlight.setMessage("This is highlight annotation");
highlight.setOpacity(0.5);
highlight.setPageNumber(0);
highlight.setPoints(points);
highlight.setReplies(replies);
// Add annotation and save to file
annotator.add(highlight);
annotator.save("outputPath");
} finally {
if (annotator != null) {
annotator.dispose();
}
}
Annotator annotator = new Annotator("inputPath");
try {
// Create an instance of Reply class and add comments
Reply reply1 = new Reply();
reply1.setComment("First comment");
reply1.setRepliedOn(Calendar.getInstance().getTime());
Reply reply2 = new Reply();
reply2.setComment("Second comment");
reply2.setRepliedOn(Calendar.getInstance().getTime());
java.util.List replies = new ArrayList();
replies.add(reply1);
replies.add(reply2);
Point point1 = new Point(80, 730);
Point point2 = new Point(240, 730);
Point point3 = new Point(80, 650);
Point point4 = new Point(240, 650);
List points = new ArrayList();
points.add(point1);
points.add(point2);
points.add(point3);
points.add(point4);
// Create an instance of AreaAnnotation class and set options
UnderlineAnnotation underline = new UnderlineAnnotation();
underline.setCreatedOn(Calendar.getInstance().getTime());
underline.setFontColor(65535);
underline.setMessage("This is underline annotation");
underline.setOpacity(0.1);
underline.setPageNumber(0);
underline.setPoints(points);
underline.setReplies(replies);
// Add annotation and save to file
annotator.add(underline);
annotator.save("outputPath");
} finally {
if (annotator != null) {
annotator.dispose();
}
}
Вы можете не только добавить новые аннотации, но и извлечь существующие аннотации из ваших файлов и удалить дополнительные аннотации перед экспортом документа в его предварительное состояние в ваших приложениях C#, ASP.NET, VB.NET и Java.
using (Annotator annotator = new Annotator("annotated.pdf"))
{
List annotations = annotator.Get();
XmlSerializer formatter = new XmlSerializer(typeof(List));
using (FileStream fs = new FileStream("annotations.xml", FileMode.Create))
{
fs.SetLength(0);
formatter.Serialize(fs, annotations);
}
}
LoadOptions tmp0 = new LoadOptions();
// Create an instance of Annotator class
Annotator annotator = new Annotator("InputPath", tmp0);
// Get all annotations
List annotations = annotator.get();
// Create an instance of Annotator class
Annotator annotator = new Annotator("inputPath");
SaveOptions saveOptions = new SaveOptions();
saveOptions.setAnnotationTypes(AnnotationType.None);
// Save result to file
annotator.save("outputPath", saveOptions);