Announcement

Collapse
No announcement yet.

How to set filenamn when printing to a PDF-file?

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

  • How to set filenamn when printing to a PDF-file?

    Is it possible to put file names from a PB program when you choose to print to a PDF file?
    Google gave me no help.
    Fim Wästberg

  • #2
    How are you printing to a PDF file? Many PDF print drivers will use the optional JobName parameter of XPRINT ATTACH.

    Comment


    • #3
      Stuart, I will test JobName parameter of XPRINT ATTACH.
      Fim Wästberg

      Comment


      • #4
        No, it does not work with JobName parameter of XPRINT ATTACH when using "Microsoft Print to PDF"
        Fim Wästberg

        Comment


        • #5
          Fim,
          What about:
          XPRINT ATTACH CHOOSE USING %PD_PRINTTOFILE, JobName$

          Comment


          • #6
            Jim, no it does not work.
            Fim Wästberg

            Comment


            • #7
              What about converting a text file directly to pdf ?

              Try this program
              https://powerbasic.com/support/pbfor...ad.php?t=24199

              Comment


              • #8
                Anne, thanks, but there are grapics in the print file
                Fim Wästberg

                Comment


                • #9
                  I have used simple ShellExecute to print PDF files, like (adjust filepath and PDFilename)
                  Code:
                      ShellExecute(0, "print", "C:\PathToFile\FileName.pdf", "", "", 0)
                  Probably exist other ways, but being a lazy programmer I like easy ways..

                  Comment


                  • #10
                    Hmm,
                    I'm a thinking he is trying to create the name of the file to print to when he selects print as PDF. Just saying...

                    If CHOOSE is specified, the Choose Printer common dialog is opened, allowing the user to select from the list of installed printers.
                    He must not be seeing the Print Dialog. With this flag %PD_PRINTTOFILE selected you should be allowed to name the file.

                    Fim, if everything is programmed correctly you should see this dialog Save Print Output As.

                    I'd suggest not using XPRINT ATTACH DEFAULT in this situation.
                    Last edited by Jim Fritts; 29 Oct 2017, 05:12 PM.

                    Comment


                    • #11
                      As far as I can tell JobName$ simply replaces "Printjob" when getting the status of the printer. Like Printjob1 printing | Printjob2 queued.

                      If a pdf converter is attached (XPRINT ATTACH), then that software gets the file name to save the pdf as. Then you would use XPRINT PRINT or XPRINT RENDER, or something to send text and/or images to the converter attached like a hardware printer.
                      Dale

                      Comment


                      • #12
                        Fim,
                        This is what I am talking about:
                        Make sure to use a BMP photo at least 800 by 600 to make it very easy to see in the PDF.
                        The file that is created will be located in the location you assign it in the Print Dialog.
                        Once you select the printer and click OK you must manually name the file in the next dialog that pops up Save Print Output As.

                        Is there an automated way of naming the file? IDK
                        Here is some insightful info to use other methods:
                        https://forum.powerbasic.com/forum/u...ntly-print-pdf

                        Code:
                        #COMPILE EXE
                        #DIM ALL
                        
                        FUNCTION PBMAIN()
                         LOCAL JobName AS STRING
                        
                         JobName = "MyJob"    'this is the name of the print job
                        
                            ' Print to printer
                            XPRINT ATTACH CHOOSE USING %PD_PRINTTOFILE, JobName
                            XPRINT SET ORIENTATION 2
                            XPRINT RENDER "photo.bmp", (0, 0) - (2422 * 2, 1864 * 2)
                            XPRINT CLOSE
                        
                        END FUNCTION
                        I'm thinking that Jose' cPDF would be the way to go.
                        Last edited by Jim Fritts; 29 Oct 2017, 11:46 PM.

                        Comment


                        • #13
                          I use PDFCreator from http://www.pdfforge.org/pdfcreator That uses the JobName as the filename.

                          Comment


                          • #14
                            I use CutePDF Writer which also respects the JobName$. Unfortunately Windows 10 'Microsoft Print To PDF' print driver does not.

                            Hooking the 'Save Print Output As' Dialog might offer a way out but that Dialog is complex - not easy to identify the control to use WM_SETTEXT.
                            Another option could be to use a timer, wait until the Dialog is displayed and then send the text with SendInput()..
                            Ugly Example..
                            Code:
                            ' Windows 10
                            #Compile Exe
                            #Dim All
                            #Include "win32api.inc"
                            
                             Declare Function PostThreadMessage Lib "USER32.DLL" Alias "PostThreadMessageA" (ByVal idThread As Dword, ByVal uMsg As Dword, ByVal wParam As Dword, ByVal lParam As Long) As Long
                            
                            Sub SendText(hWnd As Dword, sText As WString)
                             Local tinp     As INPUTAPI
                             Local i        As Long
                             Local wszText  As WStringZ * %Max_Path
                            
                               SetForegroundWindow hWnd
                               Sleep 20
                                wszText = sText
                                tinp.dtype   = %INPUT_KEYBOARD
                                tinp.iki.wVk = 0
                            
                                For i = 1 To Len(wszText)
                                  tinp.iki.dwFlags = %KEYEVENTF_UNICODE
                                  tinp.iki.wScan   = Asc(Mid$(wszText, i, 1))
                                  SendInput 1, ByVal VarPtr(tinp), SizeOf(tinp)
                            
                                  tinp.iki.dwFlags = %KEYEVENTF_UNICODE Or %KEYEVENTF_KEYUP
                                  SendInput 1, ByVal VarPtr(tinp), SizeOf(tinp)
                                Next i
                            
                            End Sub
                            '------------------/SendText
                            
                            Thread Function TimerThread(ByVal dwVar As Dword) As Long
                             Static TimerID As Dword
                             Local Msg      As TAGMSG
                                ' Start the timer
                                TimerID = SetTimer(%NULL, %NULL, 500, CodePtr(TimerProc))  ' Post %WM_TIMER msg to TimerProc every 500 msec
                                                                                            ' Loop passes msg on to TimerProc until..
                                While GetMessage(Msg, %NULL, %NULL, %NULL) <> 0             ' %WM_QUIT causes  GetMessage to return '0'
                                  DispatchMessage Msg                                       ' DispatchMessage passes %WM_TIMER on to TimerProc.
                                Wend
                            
                              KillTimer %NULL, TimerID                                      ' Kill the timer
                              WinBeep 300,500
                            End Function
                            '------------------/TimerThread
                            
                            Sub TimerProc(ByVal hWnd As Dword, ByVal uMsg As Long, ByVal TimerID As Long, ByVal dwTime As Dword)
                              Static TimerCount As Long
                              Local hMSPDF As Dword
                              Select Case uMsg
                                Case %WM_Timer                                              ' Timer has 'fired'
                                  Incr TimerCount
                             '      WinBeep 500,200
                                  If hMSPDF = 0 Then
                                    hMSPDF = FindWindow("#32770", "Save Print Output As")
                                    If hMSPDF Then
                                      SendText hMSPDF, "NewPrintJob" ' + $CRLF
                                      PostThreadMessage GetCurrentThreadID, %WM_Quit, 0, 0
                                    End If
                                  End If
                                  If TimerCount = 10 Then                                    ' Bail out after n intervals
                                    PostThreadMessage (GetCurrentThreadID, %WM_Quit, 0, 0)    ' Signal Quit to Msg Loop
                                  End If
                              End Select
                            End Sub
                            '------------------/TimerProc
                            
                            Function PBMain
                             Local sTemp As String
                             Local hThread, dwVar As Dword
                            
                              Thread Create TimerThread(dwVar) To hThread                ' Create monitor thread just before XPRINT Statements
                              Thread Close hThread To hThread                            ' Release thread handle - not used here
                            
                              XPrint Attach "Microsoft Print To PDF", "JobName2"         ' JobName$ not recieved by MS Prnt 2 PDF Dialog
                             '  XPRINT ATTACH "CutePDF Writer" ', "JobName2"             ' Ok with PDFCreator and CutePDF Writer
                              XPrint "hi there gang"
                              XPrint Close
                            
                                Do: Sleep 50: Loop Until ThreadCount = 1
                             '  ? "Done"
                            End Function
                            '------------------/PBMain
                            Rgds, Dave

                            Comment


                            • #15
                              CutePDF will let you avoid the "Save As" panel, but requires the 'Custom' (edit: was ''Professional') version. You control the filename automation in a registry key.(s). Just from a quick glance at their web page, PDF Creator appears to do that in the free version.
                              Last edited by Raymond Leech; 30 Oct 2017, 10:51 AM.

                              Comment


                              • #16
                                Raymond: Thanks, but I will use the Windows print to PDF
                                Fim Wästberg

                                Comment


                                • #17
                                  If you use an API like the Adobe API, or even a print library like Haru (which I have used), you have total absolute control of the output file name...

                                  Code:
                                    OPEN  any_file_name  FOR OUTPUT as hFile
                                    {programming library commands to create a PDF file go here }
                                    CLOSE hFile
                                  It's a thought.

                                  Surprised I didn't see that mentioned in this thread.

                                  MCM
                                  Michael Mattias
                                  Tal Systems Inc. (retired)
                                  Racine WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    Originally posted by Michael Mattias View Post
                                    If you use an API like the Adobe API, or even a print library like Haru (which I have used), you have total absolute control of the output file name...
                                    Our tool of choice at work is Virtual Print Engine (VPE). A little on the pricey side, but fast, flexible, and easy to use. PDFs, Barcodes and graphs all in the same DLL.

                                    Real programmers use a magnetized needle and a steady hand

                                    Comment


                                    • #19
                                      Print a PDF-file (same subject): https://forum.powerbasic.com/forum/u...ram#post797367
                                      How long is an idea? Write it down.

                                      Comment


                                      • #20
                                        Originally posted by Mike Doty View Post
                                        Not the same subject. This thread is about printing a PDF file you are creating. The linked thread is about sending a pre-existing PDf to a selected printer.

                                        Comment

                                        Working...
                                        X