Print PDF downloaded from web

  1. 7 months ago

    David S

    30 Jan 2019 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

    30 Jan 2019 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

    30 Jan 2019 Pre-Release Testers, Xojo Pro

    Mac OS. Thanks.

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

  4. Daniel T

    30 Jan 2019 Pre-Release Testers, Xojo Pro
    Edited 7 months 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

    30 Jan 2019 Europe (France, Strasbourg)
    Edited 7 months 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

    30 Jan 2019 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

    31 Jan 2019 Pre-Release Testers, Xojo Pro
    Edited 7 months 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

    31 Jan 2019 Pre-Release Testers, Xojo Pro 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

    31 Jan 2019 Europe (France, Strasbourg)
    Edited 7 months 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

    1 Feb 2019 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.

  11. 6 months ago

    Michael O

    Mar 10 Pre-Release Testers, Xojo Pro Massachusetts

    I'm surprised there is no simple way to hand a pdf (unmodified) off to the printer dialog. While I don't print that often it seems clumsy that I have to run an external app to send a doc to the printer. I can and have used LPR but that will not always observe boarder setting etc..

  12. Hal G

    Mar 10 Pre-Release Testers, Xojo Pro, XDC Speakers CampSoftware.com

    @MichaelOmiccioli I'm surprised there is no simple way to hand a pdf (unmodified) off to the printer dialog.

    This could work: http://printjs.crabbly.com/

  13. Greg O

    Mar 10 Xojo Inc

    @Hal G This could work: http://printjs.crabbly.com/

    Or this project...
    https://mozilla.github.io/pdf.js/

  14. 5 months ago

    Michael O

    Mar 11 Pre-Release Testers, Xojo Pro Massachusetts

    I did some experimenting and arrived at this solution. It works well, basically I treated a PDF as a Graphic and sent it to the printer instead of a Canvas.

    I then get the native OSX printer dialog. Where I can make a few choices and hit print. So not as straight forward as I thought it would be, but all the examples here on the Xojo forum helped out. I would love to optimize this further by setting the proper settings in the print dialogs from my Xojo app so that a single click accomplishes all.

    Dim ps As New PrinterSetup Dim theLabel As Picture Dim g As Graphics Dim Scale As Double = Val(Main.ccSales.tf_Scale.Text) // This is the actual size of the label from shipEngine Dim Width As Double = 275 Dim Height As Double = 432 // set the resolution to 300 DPI for printing ps.MaxHorizontalResolution = 300 ps.MaxVerticalResolution = 300 // Load the label into a Graphic, in this case the PDF theLabel = Picture.Open(Main.ccSales.LabelFile) 'Msgbox(Main.ccSales.LabelFile.DisplayName) If ps.PageSetupDialog Then g = OpenPrinterDialog(ps, Nil) //Draw the picture to the printer instead of canvas g.DrawPicture(theLabel, Val(Main.ccSales.tf_XPos.Text), Val(Main.ccSales.tf_YPos.Text), Width * Scale, Height * Scale, 0, 0, Width, Height) End If

    If I need to view the label I send it to the Canvas and display it. Anybody know how to preset the Print Dialog options so that I can bypass it (meaning no data entering ) and just print?

or Sign Up to reply!