-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
63 lines (60 loc) · 2.54 KB
/
MainWindow.xaml.cs
File metadata and controls
63 lines (60 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
using Syncfusion.PdfToImageConverter;
using System.Drawing;
using System.IO;
using System.Windows;
namespace PDFToImage_Annotation_Appearance
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//Creates a new pdf document
PdfDocument document = new PdfDocument();
//Creates a new page
PdfPage page = document.Pages.Add();
//Creates PDF free text annotation
PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(new RectangleF(50, 100, 100, 50));
//Sets properties to the annotation
freeText.MarkupText = "Free Text with Callout";
freeText.TextMarkupColor = new PdfColor(System.Drawing.Color.Black);
freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f);
freeText.Color = new PdfColor(System.Drawing.Color.Yellow);
freeText.BorderColor = new PdfColor(System.Drawing.Color.Red);
freeText.Border = new PdfAnnotationBorder(.5f);
freeText.LineEndingStyle = PdfLineEndingStyle.OpenArrow;
freeText.AnnotationFlags = PdfAnnotationFlags.Default;
freeText.Text = "Free Text";
freeText.Opacity = 0.5f;
PointF[] points = { new PointF(100, 450), new PointF(100, 200), new PointF(100, 150) };
freeText.CalloutLines = points;
freeText.SetAppearance(true);
//Adds the annotation to page
page.Annotations.Add(freeText);
//Save the document
document.Save("../../../Output.pdf");
//Closes the document
document.Close(true);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
PdfToImageConverter imageConverter = new PdfToImageConverter();
using (FileStream inputStream = new FileStream("../../../Output.pdf", FileMode.Open, FileAccess.ReadWrite))
{
imageConverter.Load(inputStream);
// Convert the first page (index 0)
using (Stream outputStream = imageConverter.Convert(0, false, false))
using (Bitmap Image = new Bitmap(outputStream))
{
Image.Save("sample.png"); // Produces an image that includes the FreeText annotation
}
}
}
}
}