TaskFlow/app/DD_PM_WINDREAM/ClassAnnotation.vb
2019-04-16 14:01:35 +02:00

33 lines
1.2 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, Optional ycorrect As Integer = 0, Optional sizecorrect As Integer = 0)
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
LOGGER.Error(ex)
LOGGER.Info("Unexpected error in Annotate pdf: " & ex.Message, False)
Return False
End Try
End Function
End Class