Java Question com.pdfjet.PDF HELP Please

NewB4JUser

Member
Licensed User
So here is my full code, and the files produces and sits theer as a pdf, but when i try open it i get the following errro:

I have tried tons of changes and just cant get it to work, can anyone see anything obviosuly that i am doing wrong.


1747154026444.png

Errro message


Thanks

Sub btnCreatePDFTested_Click
' Output path
Dim outPath As String = File.Combine(File.DirApp, "TestFile.pdf")
Dim outStream As OutputStream = File.OpenOutput(File.DirApp, "TestFile.pdf", False)

' Create PDF object
Dim pdf As JavaObject
pdf.InitializeNewInstance("com.pdfjet.PDF", Array(outStream))

' Load .stream font from /Files
Dim fontStream As InputStream = File.OpenInput(File.DirAssets, "OpenSans-Regular.ttf.stream")
Dim bStream As JavaObject
bStream.InitializeNewInstance("java.io.BufferedInputStream", Array(fontStream))

' Use only 2 arguments — remove the "0"
Dim font As JavaObject
font.InitializeNewInstance("com.pdfjet.Font", Array(pdf, bStream))

' Create a page
Dim page As JavaObject
page.InitializeNewInstance("com.pdfjet.Page", Array(pdf, 842, 595))

' Create and draw text
Dim text As JavaObject
text.InitializeNewInstance("com.pdfjet.TextLine", Array(font, "✓ PDFjet with .stream font works!"))
text.RunMethod("setPosition", Array(100, 100))
text.RunMethod("drawOn", Array(page))

' Finalize
pdf.RunMethod("flush", Null)
pdf.RunMethod("complete", Null)
outStream.Close

fx.ShowExternalDocument(outPath)
Log("✅ PDF created at: " & outPath)
End Sub
 
Top