Print PDF downloaded from web

  1. 2 weeks ago

    David S

    Jan 30 Pre-Release Testers, Xojo Pro

    Good afternoon.

    I use Xojo Desktop 2018 r3 to print PDF files downloaded from the web. Currently, I am printing files using:

    s.Execute "lpr " + f.ShellPath

    It would be nice to display a print dialog to give the user feedback that the print job is being sent to the printer. Also, if they could choose the printer (for those who have more than one) that would be nice.

    Any ideas? Thanks.

  2. Christian S

    Jan 30 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    Mac? Win? Linux?

    MBS Plugins comes with examples to print on Mac via PDFKit and Windows using DynaPDF.

  3. David S

    Jan 30 Pre-Release Testers, Xojo Pro

    Mac OS. Thanks.

    Is there a shell command to print with a print dialog?

  4. Daniel T

    Jan 30 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago

    Here's a function that uses AppleEvents and Preview.app to print a PDF, optionally with a print dialog. Notes:
    • It obviously requires Preview.app to be installed.
    • It will block the calling function until the user clicks Print or Cancel, or the AppleEvent times out. (See AppleEvent.Timeout in Xojo's docs.)

    Public Function PrintPDF(objFile As FolderItem, bolShowPrintDialog As Boolean) as Integer
      #If TargetMacOS Then
        Dim objEvent as AppleEvent
        Dim objDescList as AppleEventDescList
        
        objEvent = New AppleEvent("aevt", "pdoc", "com.apple.Preview")
        
        objDescList = New AppleEventDescList
        objDescList.AppendFolderItem(objFile)
        objEvent.DescListParam("----") = objDescList
        
        objEvent.BooleanParam("pdlg") = bolShowPrintDialog
        
        If objEvent.Send = True Then
          Return 0
        Else
          Return -1
        End If
        
      #Else
        Return -1
      #EndIf
    End Function
  5. Emile S

    Jan 30 Europe (France, Strasbourg)
    Edited 2 weeks ago

    Simply use Xojo code to print your data to pdf: the user will have to set the Print Options and click in PDF button…

    And there is a virtual PDF driver on Windows 10 too. For Linux: I do not know; someone ?

    Nota: that is funny, because usually people want a silent (invisible) way to print data ;)

  6. Christian S

    Jan 30 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    You can print with MBS Plugin and PDFKit classes:

    // select a PDF
    dim f as FolderItem = GetOpenFolderItem("")
    if f = nil then Return
    
    // open PDF
    dim doc as new PDFDocumentMBS(f)
    
    // define some print setting via PrintInfo
    dim PrintInfo as new NSPrintInfoMBS
    
    // start print operation
    dim printOperation as NSPrintOperationMBS = doc.PrintOperation(printinfo)
    
    printOperation.showsPrintPanel = true
    printOperation.showsProgressPanel = true
    
    call printOperation.runOperation

    see PDFDocumentMBS , NSPrintInfoMBS and NSPrintOperationMBS classes.

  7. David S

    Jan 31 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago

    @Emile S Simply use Xojo code to print your data to pdf: the user will have to set the Print Options and click in PDF button…

    How would that be in Xojo code? I'm not sure about that.

  8. Michel B

    Jan 31 Pre-Release Testers RubberViews.com

    @David S Mac OS. Thanks.

    Is there a shell command to print with a print dialog?

    You should change the channel to macOS, that will be easier to find later on.

  9. Emile S

    Jan 31 Europe (France, Strasbourg)
    Edited 2 weeks ago

    @David S How would that be in Xojo code? I'm not sure about that.

    Error: I misread your question. You already have the pdf and want to print it.

    f.Launch will fire your default pdf reader (usually Preview) and let the user print it (command-P or File --> Print). Then the usual print process runs.

  10. David S

    Feb 1 Pre-Release Testers, Xojo Pro

    @Emile S f.Launch will fire your default pdf reader (usually Preview) and let the user print it (command-P or File --> Print).

    Got it. Thanks.

or Sign Up to reply!