B4J Question how to print a pdf file

giannimaione

Well-Known Member
Licensed User
Longtime User
hi all,

i have a pdf file into c:\myfolder\myfile.pdf
how to print a existing pdf file ?
 

AHilton

Active Member
Licensed User
Longtime User
The best way that I've found is to use the third-party SumatraPDF (do a web search on it). Put that .exe somewhere that your B4J app can get to it (File.DirApp, for instance) and call it from there. It's Windows-only, though.

B4X:
                    If Preview = True Then
                        ' Show it
                        fx.ShowExternalDocument(File.GetUri(DataDirName , DataFileName))
                        Sleep(2000)
                        ret = True
                    Else
                        ' Print it
                        Dim Params As List : Params.initialize
                    '    Params.Add("-print-dialog ")
                        Params.Add($"-print-to "$)
                        Params.Add($"""$)
                        Params.Add(Printer)
                        Params.Add($"" "$)
                    '    Params.Add("-exit-when-done ")
                        Params.Add(DataDirName & DataFileName)
                        Dim js As Shell
                        js.Initialize("js", "sumatraPDF.exe", Params)
                        js.WorkingDirectory = File.DirApp
                        js.Run(-1)        ' No timeout
                        
                        Wait For js_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
                        Log("Shell Success=" & Success & ", StdOut=" & StdOut & ", StdErr=" & StdErr)
                        If Success Then
                            ret = True
                        Else
                            ret = False
                        End If
                    End If
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Another option - open the file in the system's default application for pdf, then print it from there:
B4X:
Dim shl As Shell
shl.Initialize("shl", "explorer.exe", Array As String("c:\myfolder\myfile.pdf"))
  shl.Run(-1)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…