Announcement

Collapse
No announcement yet.

Print a PDF-file in a PB-program?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Print a PDF-file in a PB-program?

    Is there any possibility to print a PDF file to a specific printer in a PB program?
    /Fim W.
    Fim Wästberg

  • #2
    Do you mean only printing an (existing) pdf file, or creating a new pdf file?...
    Regards,
    Peter

    Comment


    • #3
      Not sure what you mean but are you looking for XPRINT ATTACH CHOOSE?

      Comment


      • #4
        More links
        https://forum.powerbasic.com/forum/u...ntly-print-pdf
        (same question) https://forum.powerbasic.com/forum/u...-to-a-pdf-file
        How long is an idea? Write it down.

        Comment


        • #5
          I mean only printing an existing pdf file.
          What I can see, it is not possible to print a PDF-file via XPRINT.
          /Fim W.
          Fim Wästberg

          Comment


          • #6
            I use PdfToPrinter utility: http://www.columbia.edu/~em36/pdftoprinter.html
            Regards,
            Peter

            Comment


            • #7
              PdfToPrinter works on default printer.
              Trying to use a specific printer.
              /Fim W.
              Fim Wästberg

              Comment


              • #8
                ??
                To print to a specific printer, add the name of the printer in quotation marks:

                PDFtoPrinter filename.pdf "Name of Printer"
                Regards,
                Peter

                Comment


                • #9
                  Originally posted by Peter Lameijn View Post
                  I wasnt familiar with that one. Reading that page:

                  "The program is a compiled AutoIt script that effectively serves as a "wrapper" around the free PDF-Xchange Viewer,"

                  If you can write an AutoIt wrapper for that I'm sure you can use it directly in PB.

                  Comment


                  • #10
                    Hmm That's an 18MB exe file that you have to have available and shell to just to print a file.

                    You might as well install FoxIt PDF Reader and Shell to that

                    '
                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    #INCLUDE ONCE "WIN32API.INC" 'Roca includes
                    
                    FUNCTION PBMAIN () AS LONG
                       LOCAL strFilename, strPrinter,strCmd AS  STRING
                       LOCAL lRes AS LONG
                       DISPLAY OPENFILE 0, , , "SelectFile", CURDIR$, CHR$("PDF File", 0, "*.pdf", 0), _
                            "", "", %OFN_FILEMUSTEXIST  TO strfilename
                       XPRINT ATTACH CHOOSE
                       XPRINT GET ATTACH TO strPrinter
                       strCmd = $DQ & "C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe" & $DQ & " /t " & $DQ & strFileName & $DQ & " " & $DQ & strPrinter & $DQ
                       SHELL strCmd
                    END FUNCTION
                    '

                    Comment


                    • #11
                      Originally posted by Mike Doty View Post
                      Nope, that earlier thread is about how to print TO a PDF file.

                      Comment


                      • #12
                        Hmm That's an 18MB exe file that you have to have available and shell to just to print a file.
                        PdfToPrinter is 'only' 9MB...

                        You might as well install FoxIt PDF Reader and Shell to that
                        That's a bit more... (250MB total)
                        Regards,
                        Peter

                        Comment


                        • #13
                          Originally posted by Peter Lameijn View Post
                          PdfToPrinter is 'only' 9MB...


                          That's a bit more... (250MB total)

                          That's strange, it's just an Autoit wrapper aroound PDF-Xchange Viewer, I just downloaded that file and it's 18MB. ( guess they've used UPX or something)

                          Foxit v 9.72 is only 83 MB and it's the PDF viewer/creator I recommended to my clients. It's a lot more than just a tool for printing a PDF from the command line.

                          (Note v9.72 - they've removed the PDF Printer driver fro ver 10. I do NOT recommend using it)

                          Comment


                          • #14
                            Try Podofo library available at http://podofo.sourceforge.net/. It would require a bit of C++ knowledge but you can create a COM Object which is accessible from PB
                            An&

                            Comment


                            • #15
                              Maybe it would be easier to ..

                              1. Save default printer
                              2. Change system default printer to printer of choice
                              3. Print file to that new default (SHELL or similar)
                              4. Restore the default printer.

                              It's a thought; and considering what you are trying to do, namely changing the behavior of a program you do not control, "thoughts" are about all you will will get. Except we usually call those "stuff you can try but no promises" items.
                              Michael Mattias
                              Tal Systems Inc. (retired)
                              Racine WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                Originally posted by Michael Mattias View Post
                                Maybe it would be easier to ..

                                1. Save default printer
                                2. Change system default printer to printer of choice
                                3. Print file to that new default (SHELL or similar)
                                4. Restore the default printer.
                                Good idea ( as long as there is a default application to print a PDF)

                                '
                                Code:
                                #COMPILE EXE
                                #DIM ALL
                                #INCLUDE "win32api.inc" 'Roca Inc  (PB Inc doesn't have GetDefaultPrinter! )
                                
                                FUNCTION PrintIt (myfile AS STRING) AS STRING
                                ' Get Registration Key for default PRINT application for a filename [and call the application]
                                    LOCAL retval AS LONG
                                    LOCAL hkey AS LONG
                                    LOCAL filetype AS ASCIIZ * %MAX_PATH
                                    LOCAL extension AS ASCIIZ * %MAX_PATH
                                    LOCAL printcmd AS ASCIIZ * %MAX_PATH
                                    extension = PATHNAME$(EXTN,myfile)
                                    retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,extension,0,%key_query_value,hkey)
                                    retval = regqueryvalueex(hkey,"",0,%reg_sz,filetype,256)
                                    retval = regclosekey(hkey)
                                    extension = filetype & "\SHELL\PRINT\command"
                                    retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,extension,0,%key_query_value,hkey)
                                    retval = regqueryvalueex(hkey,"",0,%reg_sz,printcmd,256)
                                    retval = regclosekey(hkey)
                                    IF LEN(printcmd) = 0 THEN
                                        ? "No Default printing application!"
                                        EXIT FUNCTION
                                    END IF
                                    REPLACE "%1" WITH myfile IN printcmd
                                    ? printcmd
                                    'uncomment next line to print file
                                    'SHELL printcmd
                                END FUNCTION
                                
                                FUNCTION PBMAIN () AS LONG
                                    LOCAL strFilename, strCmd AS  STRING
                                    LOCAL  strDefPrinter,strPrinter AS  STRINGZ * %MAX_PATH
                                    LOCAL lRes,x AS LONG
                                    DISPLAY OPENFILE 0, , , "SelectFile", CURDIR$, CHR$("PDF File", 0, "*.pdf", 0),"", "", %OFN_FILEMUSTEXIST  TO strfilename
                                    strDefPrinter = SPACE$(%MAX_PATH)
                                    x  =LEN(strDefPrinter)
                                    lRes = GetDefaultPrinter(strDefPrinter,x)
                                    strDefPrinter= LEFT$(strDefPrinter,x)
                                    XPRINT ATTACH CHOOSE
                                    strPrinter = XPRINT$
                                    IF LEN(strPrinter) = 0 THEN EXIT FUNCTION
                                    SetDefaultPrinter strPrinter
                                    PrintIt strFileName
                                    setDefaultPrinter strDefPrinter
                                    ? "Done"
                                END FUNCTION
                                '

                                Comment


                                • #17
                                  Thanks for all the advice.
                                  This forum has wise and talented members.
                                  My problem is solved, completely satisfactory to me.
                                  I will use "PDFtoPrinter" for now.
                                  Later I might go for a more sophisticated solution.
                                  Case closed.
                                  /Fim W
                                  Fim Wästberg

                                  Comment

                                  Working...
                                  X