Handle vector based signatures
This commit is contained in:
@@ -4,6 +4,7 @@ Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports GdPicture14
|
||||
Imports Newtonsoft.Json
|
||||
Imports Newtonsoft.Json.Linq
|
||||
|
||||
Public Class frmFinalizePDF
|
||||
Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;"
|
||||
@@ -13,84 +14,70 @@ Public Class frmFinalizePDF
|
||||
|
||||
Private Viewer As GdPicture14.GdViewer
|
||||
Private Manager As AnnotationManager
|
||||
|
||||
Private PDFBurner As PDFBurner
|
||||
|
||||
|
||||
Private Sub frmFinalizePDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath)
|
||||
Database = New MSSQLServer(LogConfig, MSSQLServer.DecryptConnectionString(CONNECTIONSTRING))
|
||||
|
||||
PDFBurner = New PDFBurner(LogConfig, "21182889975216572111813147150675976632")
|
||||
|
||||
Manager = New AnnotationManager()
|
||||
Dim oLicense = New LicenseManager()
|
||||
oLicense.RegisterKEY("21182889975216572111813147150675976632")
|
||||
End Sub
|
||||
|
||||
Private Function LoadAnnotationData() As String
|
||||
Private Function LoadAnnotationDataForReceiver() As String
|
||||
Dim oSql = $"SELECT VALUE FROM [TBSIG_DOCUMENT_STATUS] WHERE ENVELOPE_ID = {txtEnvelope.Text} AND RECEIVER_ID = {txtReceiver.Text}"
|
||||
Return Database.GetScalarValue(oSql)
|
||||
|
||||
End Function
|
||||
|
||||
Private Function LoadAnnotationDataForEnvelope() As DataTable
|
||||
Dim oSql = $"SELECT VALUE FROM [TBSIG_DOCUMENT_STATUS] WHERE ENVELOPE_ID = {txtEnvelope.Text}"
|
||||
Return Database.GetDatatable(oSql)
|
||||
|
||||
End Function
|
||||
|
||||
Private Function LoadEnvelopeDocument() As String
|
||||
Dim oSql = $"SELECT FILEPATH FROM [TBSIG_ENVELOPE_DOCUMENT] WHERE ENVELOPE_ID = {txtEnvelope.Text}"
|
||||
Return Database.GetScalarValue(oSql)
|
||||
|
||||
End Function
|
||||
|
||||
Public Class AnnotationData
|
||||
|
||||
Public Property annotations As List(Of Annotation)
|
||||
Public Property attachments As Dictionary(Of String, Attachment)
|
||||
End Class
|
||||
|
||||
Public Class Annotation
|
||||
Public Property id As String
|
||||
Public Property bbox As List(Of Double)
|
||||
Public Property type As String
|
||||
Public Property isSignature As Boolean
|
||||
Public Property imageAttachmentId As String
|
||||
End Class
|
||||
|
||||
|
||||
|
||||
Public Class Attachment
|
||||
Public Property binary As String
|
||||
Public Property contentType As String
|
||||
End Class
|
||||
|
||||
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
||||
Dim oAnnotationData = LoadAnnotationData()
|
||||
Dim oDocumentPath = LoadEnvelopeDocument()
|
||||
Dim oTable = LoadAnnotationDataForEnvelope()
|
||||
Dim oJsonList = oTable.Rows.
|
||||
Cast(Of DataRow).
|
||||
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
|
||||
ToList()
|
||||
|
||||
Dim oConverter = JsonConvert.DeserializeObject(Of AnnotationData)(oAnnotationData)
|
||||
PDFBurner.BurnInstantJSONAnnotationsToPDF(oDocumentPath, oJsonList, $"{oDocumentPath}.burned.pdf")
|
||||
End Sub
|
||||
|
||||
Dim oImages = oConverter.annotations.Where(Function(a) a.type = "pspdfkit/image").ToList()
|
||||
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
|
||||
Try
|
||||
Dim oTable = LoadAnnotationDataForEnvelope()
|
||||
Dim oJsonList = oTable.Rows.
|
||||
Cast(Of DataRow).
|
||||
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
|
||||
Select(Function(s As String) JObject.Parse(s)).
|
||||
ToList()
|
||||
|
||||
Manager.InitFromFile(Application.StartupPath & "/source.pdf")
|
||||
Dim oJObject1 = oJsonList.First()
|
||||
Dim oJObject2 = oJsonList.ElementAt(1)
|
||||
|
||||
For Each oImage In oImages
|
||||
Dim oAttachment = oConverter.attachments.Where(Function(a) a.Key = oImage.imageAttachmentId).Single()
|
||||
Dim oBytes = Convert.FromBase64String(oAttachment.Value.binary)
|
||||
oJObject1.Merge(oJObject2)
|
||||
|
||||
txtResult.Text = oJObject1.ToString()
|
||||
|
||||
|
||||
'Using oStream As New MemoryStream(oBytes)
|
||||
' Using oFileStream As New FileStream($"{oImage.imageAttachmentId}.png", FileMode.OpenOrCreate)
|
||||
' oStream.CopyTo(oFileStream)
|
||||
' oStream.Flush()
|
||||
' End Using
|
||||
'End Using
|
||||
Dim x = oImage.bbox.Item(0) / 72
|
||||
Dim y = oImage.bbox.Item(1) / 72
|
||||
Dim w = oImage.bbox.Item(2) / 72
|
||||
Dim h = oImage.bbox.Item(3) / 72
|
||||
Catch ex As Exception
|
||||
|
||||
Manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.binary, x, y, w, h)
|
||||
|
||||
|
||||
|
||||
Next
|
||||
|
||||
Manager.SaveDocumentToPDF("pdf.pdf")
|
||||
Manager.Close()
|
||||
End Try
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user