33 lines
1.0 KiB
VB.net
33 lines
1.0 KiB
VB.net
Imports PdfSharp.Pdf
|
|
Imports PdfSharp.Pdf.Annotations
|
|
Imports PdfSharp.Pdf.IO
|
|
Imports PdfSharp.Drawing
|
|
Public Class frmAnnotations
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|
|
|
Try
|
|
Dim doc As PdfDocument = PdfReader.Open(CURRENT_DOC_PATH, PdfDocumentOpenMode.Modify)
|
|
Dim firstPage As PdfPage = doc.Pages(txtSeitenzahl.Text)
|
|
|
|
Dim gfx As XGraphics = XGraphics.FromPdfPage(firstPage)
|
|
Dim rect As XRect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(30, 60), New XSize(30, 30)))
|
|
|
|
Dim annot As PdfTextAnnotation = New PdfTextAnnotation
|
|
|
|
|
|
annot.Title = txttitle.Text
|
|
'annot.Subject = txtsubject.Text
|
|
annot.Contents = txtcontent.Text
|
|
annot.Rectangle = New PdfRectangle(rect)
|
|
|
|
|
|
firstPage.Annotations.Add(annot)
|
|
doc.Save(CURRENT_DOC_PATH)
|
|
Me.Close()
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical)
|
|
End Try
|
|
|
|
|
|
End Sub
|
|
End Class |