#IgnoreWarnings: 12
Sub Class_Globals
Private mCallBack As Object
Private mEvent As String
Private mFileName As String
Private pdfObj As BANanoObject
Private arrayBuffer As Object
Private BANAno As BANano
Private PDFLib As BANanoObject
Private pdfDoc As BANanoObject
Private pages As List
End Sub
Public Sub Initialize(Module As Object, event As String, fileName As String)
mCallBack = Module
mEvent = event
mFileName = fileName
PDFLib.Initialize("PDFLib")
End Sub
Sub OpenTemplate(tmpFile As String)
arrayBuffer = BANAno.Await(BANAno.GetFileAsArrayBuffer(tmpFile, Null))
pdfDoc = BANAno.Await(PDFLib.GetField("PDFDocument").RunMethod("load", arrayBuffer))
'const pdfDoc = await PDFLib.PDFDocument.load(arrayBuffer);
pages = pdfDoc.RunMethod("getPages", Null)
End Sub
Sub AddSignaturePng(pageNumber As Int, signURL As String, x As Int, y As Int, width As Int, height As Int)
Dim tPage As Int = BANAno.parseInt(pageNumber) - 1
Dim sigBuffer As Object = BANAno.Await(BANAno.GetFileAsArrayBuffer(signURL, Null))
Dim pngIMage As Object = BANAno.Await(pdfDoc.RunMethod("embedPng", sigBuffer))
Dim opt As Map = CreateMap()
opt.Put("x", x)
opt.Put("y", y)
opt.Put("width", width)
opt.Put("height", height)
'
Dim page As BANanoObject = pages.Get(tPage)
page.RunMethod("drawImage", Array(pngIMage, opt))
End Sub
Sub AddSignatureJpeg(pageNumber As Int, signURL As String, x As Int, y As Int, width As Int, height As Int)
Dim tPage As Int = BANAno.parseInt(pageNumber) - 1
Dim sigBuffer As Object = BANAno.Await(BANAno.GetFileAsArrayBuffer(signURL, Null))
Dim pngIMage As Object = BANAno.Await(pdfDoc.RunMethod("embedJpg", sigBuffer))
Dim opt As Map = CreateMap()
opt.Put("x", x)
opt.Put("y", y)
opt.Put("width", width)
opt.Put("height", height)
'
Dim page As BANanoObject = pages.Get(tPage)
page.RunMethod("drawImage", Array(pngIMage, opt))
End Sub
Sub SaveToFileObject As BANanoObject
Dim pdfBytes As Object = BANAno.Await(pdfDoc.RunMethod("save", Null))
Dim fc As List
fc.Initialize
fc.Add(pdfBytes)
Dim blob As BANanoObject
blob.Initialize2("Blob",Array(fc, CreateMap("type": "application/pdf")))
' make a new File object
Dim f As BANanoObject
f.Initialize2("File",Array(Array(blob), mFileName, CreateMap("type": blob.getfield("type"))))
Return f
End Sub
Sub Download
Dim pdfBytes As Object = BANAno.Await(pdfDoc.RunMethod("save", Null))
Dim fc As List
fc.Initialize
fc.Add(pdfBytes)
Dim blob As BANanoObject
blob.Initialize2("Blob",Array(fc, CreateMap("type": "application/pdf")))
BANAno.RunJavascriptMethod("saveAs",Array(blob,mFileName))
End Sub