Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved how to select file and then print to printer ?

    General and Desktop
    print pdf file printsupport
    4
    11
    6660
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JonB
      JonB @Qjay last edited by

      @Qjay And what actually happens?

      1 Reply Last reply Reply Quote 0
      • Qjay
        Qjay last edited by

        hey when i select PDF file i get this in console

        QPrintDialog: Cannot be used on non-native printers
        

        but when i select other file like txt file or image file , i get prindialog like this
        0_1518153127756_Capture.PNG

        JonB 1 Reply Last reply Reply Quote 0
        • JonB
          JonB @Qjay last edited by

          @Qjay said in how to select file and then print to printer ?:

          QPrintDialog: Cannot be used on non-native printers

          Well it would have been useful if you had explained that was the situation in the first place :)

          For PDF under Windows, read https://forum.qt.io/topic/5958/qprintdialog-error-on-qt-windows-environment/2:

          QPrintDialog can't be used with pdfs on Windows because it is a native print dialog and has no knowledge of Qt's PDF printer.

          1 Reply Last reply Reply Quote 2
          • Qjay
            Qjay last edited by Qjay

            sorry my bad :/ .

            so what are my options then ? what can i do

            P.S. i think that answer is way too old (2011) , there should be an update right ?

            1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion last edited by mrjj

              Hi
              Since you want to print an EXISTING pdf file, its not
              possible directly with Qt.
              Qt can create a pdf file but its not possible to load/display/print
              external one as far as i know.
              (its outside Qt to display pdfs)
              So i think you need external lib for that.
              https://poppler.freedesktop.org/

              Can I ask you actual use case and what platform you need to support ?

              1 Reply Last reply Reply Quote 6
              • Qjay
                Qjay last edited by

                hey , the platform is windows (windows server) only . The actual use case is to print the pdf to a network printer or any printer available. the application will be on a RDP server.

                Why it's needed ?
                Guacamole client cannot print files. https://guacamole.apache.org/faq/#local-printers

                mrjj 1 Reply Last reply Reply Quote 1
                • mrjj
                  mrjj Lifetime Qt Champion @Qjay last edited by

                  @Qjay
                  hi
                  Ok, if you dont need processing in the Qt app , you could just use external tool to make it possible to print pdf via commandline

                  http://www.win10pdf.com/pdf-to-printer.html

                  or for a more complex one, use ghostscript.
                  https://stackoverflow.com/questions/2599925/how-to-print-pdf-on-default-network-printer-using-ghostscript-gswin32c-exe-she

                  some pdf viewers also support the print % options and could be used.

                  So you could use QProcess to start app that prints the pdf.

                  Qjay 1 Reply Last reply Reply Quote 4
                  • Qjay
                    Qjay @mrjj last edited by

                    @mrjj thanks , this looks like an awesome idea . I will try it out and will let you know !!

                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @Qjay last edited by JonB

                      @Qjay
                      This may not help because I do not know quite how you would do this directly from Qt, but when we want to print a PDF under Windows we use the underlying Win32 function ShellExecute() (https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153(v=vs.85).aspx) to go (effectively) ShellExecute("print", native-path-to-file), and let Windows shell sort it out.

                      This is effectively the same as right-clicking on the file and picking the Print action. So you don't need to know anything about the actual process which does the printing, its arguments etc.

                      1 Reply Last reply Reply Quote 0
                      • J
                        jayden982 Banned last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote -1
                        • First post
                          Last post