Add frmFinalizePDF
This commit is contained in:
96
EnvelopeGenerator.Test/frmFinalizePDF.vb
Normal file
96
EnvelopeGenerator.Test/frmFinalizePDF.vb
Normal file
@@ -0,0 +1,96 @@
|
||||
Imports System.IO
|
||||
Imports DevExpress.Utils
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports GdPicture14
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Public Class frmFinalizePDF
|
||||
Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;"
|
||||
|
||||
Private Database As MSSQLServer
|
||||
Private LogConfig As LogConfig
|
||||
|
||||
Private Viewer As GdPicture14.GdViewer
|
||||
Private Manager As AnnotationManager
|
||||
|
||||
|
||||
|
||||
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))
|
||||
|
||||
Manager = New AnnotationManager()
|
||||
Dim oLicense = New LicenseManager()
|
||||
oLicense.RegisterKEY("21182889975216572111813147150675976632")
|
||||
End Sub
|
||||
|
||||
Private Function LoadAnnotationData() 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 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 oConverter = JsonConvert.DeserializeObject(Of AnnotationData)(oAnnotationData)
|
||||
|
||||
Dim oImages = oConverter.annotations.Where(Function(a) a.type = "pspdfkit/image").ToList()
|
||||
|
||||
Manager.InitFromFile(Application.StartupPath & "/source.pdf")
|
||||
|
||||
For Each oImage In oImages
|
||||
Dim oAttachment = oConverter.attachments.Where(Function(a) a.Key = oImage.imageAttachmentId).Single()
|
||||
Dim oBytes = Convert.FromBase64String(oAttachment.Value.binary)
|
||||
|
||||
|
||||
'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
|
||||
|
||||
Manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.binary, x, y, w, h)
|
||||
|
||||
|
||||
|
||||
Next
|
||||
|
||||
Manager.SaveDocumentToPDF("pdf.pdf")
|
||||
Manager.Close()
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user