B4J Question how to print a pdf file

Discussion in 'B4J Questions' started by giannimaione, Jan 12, 2019.

  1. giannimaione

    giannimaione Well-Known Member Licensed User

    hi all,

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

    AHilton Active Member Licensed 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.

    Code:
    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
     
    giannimaione and inakigarm like this.
  3. derez

    derez Expert Licensed User

    Another option - open the file in the system's default application for pdf, then print it from there:
    Code:
    Dim shl As Shell
    shl.Initialize(
    "shl""explorer.exe"Array As String("c:\myfolder\myfile.pdf"))
      shl.Run(-
    1)
     
    jimmyF likes this.
  4. Harris

    Harris Well-Known Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice