maxh2815
Member
I'm writing text and numbers to a basic pdf using a PdfDocument object. I want to convert this to a bitmap so I can send it to my Bluetooth POS printer (through StarDust's library). I tried to use the pdf's canvas and write it to a file:
The pdf works perfectly, and looks like this:
This is a cut of the top portion of it. However, when I open the .png file that was supposedly the written bitmap, it just opens to a blank, completely white page with a very small black square in the middle. Am I saving it incorrectly perhaps? Additionally, is there a better way to send a pdf to the POS printer?
Thanks.
B4X:
Dim pdf As PdfDocument
pdf.Initialize
pdf.StartPage(595, 842) 'A4 size
pdf.Canvas.DrawText("Hello", 100, 100, Typeface.DEFAULT_BOLD, 35 / GetDeviceLayoutValues.Scale, Colors.Black, "LEFT")
pdf.Canvas.DrawText("Testing: 123", 100, 140, Typeface.DEFAULT_BOLD, 15 / GetDeviceLayoutValues.Scale, Colors.Black, "LEFT")
pdf.FinishPage
Dim out As OutputStream = File.OpenOutput(rp.GetSafeDirDefaultExternal(""), "testing.png", False)
pdf.Canvas.Bitmap.WriteToStream(out, 100, "PNG")
out.Close
Log("Wrote bitmap to file")
out = File.OpenOutput(rp.GetSafeDirDefaultExternal(""), "testing.pdf", False)
pdf.WriteToStream(out)
out.Close
pdf.Close
Log("Wrote pdf to file")
The pdf works perfectly, and looks like this:
This is a cut of the top portion of it. However, when I open the .png file that was supposedly the written bitmap, it just opens to a blank, completely white page with a very small black square in the middle. Am I saving it incorrectly perhaps? Additionally, is there a better way to send a pdf to the POS printer?
Thanks.