Announcement

Collapse
No announcement yet.

Print a PDF-file in a PB-program?

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

  • Fim Wästberg
    replied
    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

    Leave a comment:


  • Stuart McLachlan
    replied
    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
    '

    Leave a comment:


  • Michael Mattias
    replied
    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.

    Leave a comment:


  • Anand Kumar
    replied
    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

    Leave a comment:


  • Stuart McLachlan
    replied
    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)

    Leave a comment:


  • Peter Lameijn
    replied
    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)

    Leave a comment:


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

    Leave a comment:


  • Stuart McLachlan
    replied
    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
    '

    Leave a comment:


  • Stuart McLachlan
    replied
    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.

    Leave a comment:


  • Peter Lameijn
    replied
    ??
    To print to a specific printer, add the name of the printer in quotation marks:

    PDFtoPrinter filename.pdf "Name of Printer"

    Leave a comment:


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

    Leave a comment:


  • Peter Lameijn
    replied
    I use PdfToPrinter utility: http://www.columbia.edu/~em36/pdftoprinter.html

    Leave a comment:


  • Fim Wästberg
    replied
    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.

    Leave a comment:


  • Mike Doty
    replied
    More links
    https://forum.powerbasic.com/forum/u...ntly-print-pdf
    (same question) https://forum.powerbasic.com/forum/u...-to-a-pdf-file

    Leave a comment:


  • Stuart McLachlan
    replied
    Not sure what you mean but are you looking for XPRINT ATTACH CHOOSE?

    Leave a comment:


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

    Leave a comment:


  • Fim Wästberg
    started a topic Print a PDF-file in a PB-program?

    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.
Working...
X