B4J Question Snapshot

RobRock92

Member
Licensed User
Longtime User
Hi , I would like to know how to make the screen shot of the form and print it with printhtml tool, thanks :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2014-01-31_07.59.21.png


You should create a template file. It should point to the image:
B4X:
<img src="image.png" />
Now in your code you should save the snapshot to this image and print the template:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private sh As Shell
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   
End Sub
Sub Button1_Action
   Dim out As OutputStream = File.OpenOutput(File.DirApp, "image.png", False)
   MainForm.RootPane.Snapshot.WriteToStream(out)
   out.Close
   Dim params As List
   params.Initialize
   'params.Add("printername=novapdf")
   params.Add("file=template.html")
   sh.Initialize("sh", "printhtml.exe", params)
   sh.WorkingDirectory = File.DirApp
   sh.Run(-1)
End Sub

Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   Log("Success=" & Success & ", StdOut=" & StdOut & ", StdErr=" & StdErr)
End Sub
 
Upvote 0

RobRock92

Member
Licensed User
Longtime User
SS-2014-01-31_07.59.21.png


You should create a template file. It should point to the image:
B4X:
<img src="image.png" />
Now in your code you should save the snapshot to this image and print the template:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private sh As Shell
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
  
End Sub
Sub Button1_Action
   Dim out As OutputStream = File.OpenOutput(File.DirApp, "image.png", False)
   MainForm.RootPane.Snapshot.WriteToStream(out)
   out.Close
   Dim params As List
   params.Initialize
   'params.Add("printername=novapdf")
   params.Add("file=template.html")
   sh.Initialize("sh", "printhtml.exe", params)
   sh.WorkingDirectory = File.DirApp
   sh.Run(-1)
End Sub

Sub sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   Log("Success=" & Success & ", StdOut=" & StdOut & ", StdErr=" & StdErr)
End Sub


And how create a template file programmatically and delet it after print? thanks Erel :)
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hi all,
I've error this,how to get rid of this. Assume I've added my picture at Files Tab already(my picture is bigger than permit posting.)

Program started.
Success=true, StdOut=HTMLPRINT 4.0.0.19 - Copyright 2013
Unable to load HTML from file 'template.html'. The file does not exist.
, StdErr=
 

Attachments

  • TestSnapshot.zip
    1.3 KB · Views: 385
Upvote 0

magoandroid

Member
Licensed User
Longtime User
Hi all,
I've error this,how to get rid of this. Assume I've added my picture at Files Tab already(my picture is bigger than permit posting.)

Hi Theera,
I looked your code.
Printhtml.exe expects to find the template file in the folder of the application (File.DirApp) where you save the file "ThaiHistory.png."
Your file "template.html" instead is located in the DirAssets.
Flip it and you'll see that it will work.

Greetings.
MAgo
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Hi all,
In post#2,I think Erel forgot to add alike this code,doesn't he? as below:
File.ReadString(File.DirAssets,"template.html")
,but I cann't make it work.

P.S. I compared with Erel's print example.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Ok Work Now.

I use this code instead of the post#7
B4X:
File.Copy(File.DirAssets,"template.html",File.DirApp,"template.html")
 
Last edited:
Upvote 0
Top