39 lines
1.5 KiB
VB.net
39 lines
1.5 KiB
VB.net
Imports PdfSharp.Pdf
|
|
Imports PdfSharp.Pdf.Annotations
|
|
Imports PdfSharp.Pdf.IO
|
|
Imports PdfSharp.Drawing
|
|
Public Class ClassAnnotation
|
|
Public Shared Function Annotate_PDF(title As String, content As String, page As Integer, fromGui As Boolean, Optional ycorrect As Integer = 0, Optional sizecorrect As Integer = 0)
|
|
If CURRENT_DOC_PATH.Length > 0 Then
|
|
Try
|
|
Dim doc As PdfDocument = PdfReader.Open(CURRENT_DOC_PATH, PdfDocumentOpenMode.Modify)
|
|
Dim firstPage As PdfPage = doc.Pages(page)
|
|
|
|
Dim gfx As XGraphics = XGraphics.FromPdfPage(firstPage)
|
|
Dim rect As XRect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(30, 60 + ycorrect), New XSize(60 + sizecorrect, 40 + sizecorrect)))
|
|
|
|
Dim annot As PdfTextAnnotation = New PdfTextAnnotation
|
|
|
|
annot.Title = title
|
|
'annot.Subject = txtsubject.Text
|
|
annot.Contents = content
|
|
annot.Rectangle = New PdfRectangle(rect)
|
|
|
|
|
|
firstPage.Annotations.Add(annot)
|
|
doc.Save(CURRENT_DOC_PATH)
|
|
Return True
|
|
Catch ex As Exception
|
|
If fromGui = True Then
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in Annotate pdf:")
|
|
End If
|
|
LOGGER.Error(ex)
|
|
LOGGER.Info("Unexpected error in Annotate pdf: " & ex.Message, False)
|
|
Return False
|
|
End Try
|
|
End If
|
|
|
|
|
|
End Function
|
|
End Class
|