12 Replies Latest reply: Sep 25, 2012 10:14 AM by Frank Leijten RSS

    Create PDF via macro works once, then doesn't produce .pdf file again

      I am using QlikView 9. I've tried the following code on a Windows 2008 server and a XP desktop. I'm using the PDF writer from QlikView 7.52. My coworker has used the Xchange 3.0 as well and gets the same results. I got most of this code from Posts on this forum. This is a trigger OnPostReload. Whether I do a reload or a debug, it seems to stop on the statement: ActiveDocument.PrintReport "CH02", "QlikViewPDF".

       

      sub Exports

      set obj = ActiveDocument.GetSheetObject("CH02")

      set val = ActiveDocument.Fields("Mn.wk.ctr_VAPLZ").GetPossibleValues

      for i=1 to val.Count-1

      ActiveDocument.Fields("Mn.wk.ctr_VAPLZ"). Select val.Item(i).Text

      set obj = ActiveDocument.GetSheetObject("CH02")

      Set WSHShell = CreateObject("WScript.Shell")

      fln = "C:\data\myreport"&val.Item(i).Text&".pdf"

      RegKey = "HKEY_CURRENT_USER\Software\QlikViewPDF"

      WSHShell.RegWrite RegKey & "BypassSaveAs", 1

      WSHShell.RegWrite RegKey & "OutputFile", fln

      ActiveDocument.GetApplication.Sleep 2000

      ActiveDocument.PrintReport "CH02", "QlikViewPDF"

      ActiveDocument.GetApplication.Sleep 2000

      WSHShell.RegWrite RegKey & "BypassSaveAs", 0

      WSHShell.RegWrite RegKey & "OutputFile", ""

      Set WSHShell = nothing

      next

      ActiveDocument.Fields("Mn.wk.ctr_VAPLZ").Clear

      end sub



      Thank you,

       

       

      Kathy





        • Create PDF via macro works once, then doesn't produce .pdf file again

          You should use the report variable instead of the chart object here.

            • Create PDF via macro works once, then doesn't produce .pdf file again

              I'm sorry, but I'm kind of new to QlikView. Are you saying that I have to create a report to send to a pdf? How do you send graphs and barcharts to a pdf file?

                • Create PDF via macro works once, then doesn't produce .pdf file again
                  Nicolas MARTIN

                  > How do you send graphs and barcharts to a pdf file?

                   

                  By creating a report with your graphs / charts in it !

                   

                    • Create PDF via macro works once, then doesn't produce .pdf file again

                      I created a report and put 'CH02' on the report. I changed my trigger to use 'RP01' and it still won't save the PDF file.

                      Thanks for your help.

                      Kathy

                        • Create PDF via macro works once, then doesn't produce .pdf file again
                          Nicolas MARTIN

                          Good day Kathy,

                           

                          Use this simplified macro :

                           


                          sub ExportToPDF
                          ActiveDocument.GetApplication.WaitForIdle

                          set WSHShell = CreateObject("WScript.Shell")
                          WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", "C:\tmp\file.pdf", "REG_SZ" 'change the path
                          WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"

                          ActiveDocument.PrintReport "RP01", "QlikViewPDF", false
                          set WSHShell = nothing

                          end sub


                           

                          and make sure your current local security is "allow system access".

                          Also verify that "QlikViewPDF" is an existing printer in your setup.

                           

                          Be aware that this macro will not be triggered when the reload comes from QV server / QV publisher.

                           

                            • Create PDF via macro works once, then doesn't produce .pdf file again

                              I had to add some sleep commands but I got it to work on my laptop which has XP installed. When I run it on our QlikView server (has Windows 2008 installed), it pops up the Save as box, and won't save the file, or if it does, it overwrites the same file over and over. I've read in other posts, that this won't work with Windows 2007, so I'm guessing it won't work for Windows 2008 either. Does QlikView have a solution to this. I can't seem to find any thing about this on the actaul sight.

                              Thanks,

                              Kathy.

                                • Create PDF via macro works once, then doesn't produce .pdf file again
                                  Nicolas MARTIN

                                  The behavior you describe looks like you are using "QlikViewPDF version 9".

                                  I've never succeded to set the parameters with registery keys with this version.

                                   

                                  Try to use the 7.52 version, it should work.

                                   

                                    • Create PDF via macro works once, then doesn't produce .pdf file again

                                      We are using the 7.52 version. The server is a Windows 2008 64-bit OS. We changed the QlikViewPDF preferences to save to a default path and to use the job name and the 'save as' box doesn't pop up, but, it overwrites the file QlikView Printing.pdf each time (doesn't use the file name populated in the registery key). We did have "QlikViewPDF version 9" installed but we uninstalled it. Do you think there is residual files that didn't get cleaned up with the uninstall? If so, do you know what to look for?

                                      Thanks,

                                      Kathy

                                        • Create PDF via macro works once, then doesn't produce .pdf file again
                                          Nicolas MARTIN

                                           

                                          We changed the QlikViewPDF preferences to save to a default path and to use the job name and the 'save as' box doesn't pop up, but, it overwrites the file QlikView Printing.pdf each time


                                           

                                          This looks like to be the behavior of the v9.

                                           

                                          How did you "changed the QlikViewPDF preferences to save to a default path" ?

                                           

                                          Here is the QlikViewPDF v7.52 properties page :

                                          You notice there is no option to change anything usefull...

                                           

                                           

                                          Here is the v9 properties page :

                                           

                                          with the "Save" panel I think you used :

                                           

                                          Here you can change some parameters (default folder, ...)... BUT it's not the printer you want to use !

                                           

                                           

                                          Recap :
                                          - with v9, you can change preferences in your control panel, but I've never succeded to change preferences by modifying the registry
                                          - with v7.52, you don't have many preferences in your control panel, but you can change parameters by modifying the registry

                                           

                                          Be sure that in your code, you are calling the right printer.

                                           


                                          ActiveDocument.PrintReport "RP01", "QlikViewPDF", false


                                           

                                           

                                            • Create PDF via macro works once, then doesn't produce .pdf file again

                                              I can't seem to paste a screen shot in my post so I will try to explain. The 'Preferences' file that I am talking about is located on the server under Program Files (x86) -> QlikView -> QlikViewPDF. If you double click on the 'Preferences' file you will get a screen that has several checkboxes. In the Output Options section, we checked the 'Use default folder location' and filled in the location and we checked 'Use print job name to save PDF file under default folder automatically' and that stopped the pop up 'save as' box, but it overwrites the QlkView Printing.pdf instead of using the name in the registry for the output file.

                                              I looked in the Devices and Printers on the server, and we only have QlikViewPDF installed. We do not have the XChange 3.0 in the list.

                                              Kathy

                            • Create PDF via macro works once, then doesn't produce .pdf file again

                              Hi,

                              In order to automate your PDF printing, please trigger your macro in 'OnOpen' instead of 'OnPostReload' & in this case you need to call your reload command 2 times. 1st time is to reload data, 2nd time is to trigger 'OnOpen' to print pdf.

                              It seems that 'OnPostReload' to print pdf will not work at all for those batch reload.

                              This issue has been reported by someone previously.

                              I am not sure whether this one has been resolved, but 2 time reload & print report on 2nd 'OnOpen' seems to be the only solution.

                              The 'OnPostReload' will never work, if you are trying to trigger it using batch command.

                              best regards

                              mingming

                              • Re: Create PDF via macro works once, then doesn't produce .pdf file again
                                Frank Leijten

                                Hi,

                                 

                                i had the same problem and I use this:

                                 

                                  

                                'Centrale macro
                                sub ReloadExportSend
                                ExportPDF
                                ActiveDocument.Reload

                                 

                                ExportPDF

                                 

                                ActiveDocument.save
                                ActiveDocument.GetApplication.Quit
                                end sub

                                 

                                 

                                sub ExportPDF
                                dim myFSO, myFile, myFileCopy 'Settings for the filecopy
                                Set myFSO = CreateObject("Scripting.FileSystemObject") 'Settings for the filecopy
                                ActiveDocument.PrintReport "RP01" , "PDF-XChange Printer 2012" , false 'Print the report via the PDF-printer
                                Set myFileCopy = myFSO.GetFile("C:\TempPrintQlikView\QlikView Printing.pdf") 'Which document has to be renamed
                                ActiveDocument.GetApplication.Sleep 10000
                                myFileCopy.Copy "L:\Rapportages\Logistics\DeliveryPerformance.pdf" ' recall the PDF file

                                end sub

                                it works fine by me!

                                Frank