Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Save a PDF loop with different filenames

Dear All,

I am trying to automatically save various reports as PDF. I need them to have different file names.

I have a field called ID, and i need to make a loop in that field and save each report in the same folder but with different name.

CustomerIDOutput file name
Mickey

1

1-Mickey.pdf
Pluto22-Pluto.pdf
Daisy33-Daisy.pdf
Daisy44-Daisy.pdf
Donald55-Donald.pdf
Goofy66-Goofy.pdf

So, I need a macro to do a loop in the ID field that generates each report for each customer and save them in the same folder with the output file name.

Regards,

Alazne.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

SOLVED

Sub Print_PDF

    ' Designed for early bind, set reference to PDFCreator

    Dim pdfjob

    Dim sPDFName

    Dim sPDFPath

    '/// Change the output file name here! ///

  

  set fo = ActiveDocument.Fields("CUUID")

  set selo = fo.GetSelectedValues

  for i = 0 to selo.Count-1

  fo.Select selo.Item(i).text

    sPDFName = selo.Item(i).text

    sPDFPath = "C:\Users\"

    Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")

    With pdfjob

      If .cStart("/NoProcessingAtStartup") = False Then

         If .cStart("/NoProcessingAtStartup", True) = False Then

          Exit Sub

         End if

         .cVisible = True

      End If

      .cOption("UseAutosave") = 1

      .cOption("UseAutosaveDirectory") = 1

      .cOption("AutosaveDirectory") = sPDFPath

      .cOption("AutosaveFilename") = sPDFName

      .cOption("AutosaveFormat") = 0 ' 0 = PDF

      .cClearCache

    End With

   ' Print the QlikView Report

    ActiveDocument.PrintDocReport "RP05", "PDFCreator"

    'Wait until the print job has entered the print queue

    Do Until pdfjob.cCountOfPrintjobs = 1

     ActiveDocument.GetApplication.Sleep 20

        ' in VBScript use WScript.Sleep(20)

    Loop

    pdfjob.cPrinterStop = False

    'Wait until PDF creator is finished then release the objects

    Do Until pdfjob.cCountOfPrintjobs = 0

     ActiveDocument.GetApplication.Sleep 20

        ' in VBScript use WScript.Sleep(20)

    Loop

    pdfjob.cClose

    Set pdfjob = Nothing

    next

  

End Sub

View solution in original post

2 Replies
Anonymous
Not applicable
Author

I have a similar problem and the macros I have found so far in community does not work. QV does not report any problem with the macro but the macro is still asking me to introduce the filename.

Anonymous
Not applicable
Author

SOLVED

Sub Print_PDF

    ' Designed for early bind, set reference to PDFCreator

    Dim pdfjob

    Dim sPDFName

    Dim sPDFPath

    '/// Change the output file name here! ///

  

  set fo = ActiveDocument.Fields("CUUID")

  set selo = fo.GetSelectedValues

  for i = 0 to selo.Count-1

  fo.Select selo.Item(i).text

    sPDFName = selo.Item(i).text

    sPDFPath = "C:\Users\"

    Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")

    With pdfjob

      If .cStart("/NoProcessingAtStartup") = False Then

         If .cStart("/NoProcessingAtStartup", True) = False Then

          Exit Sub

         End if

         .cVisible = True

      End If

      .cOption("UseAutosave") = 1

      .cOption("UseAutosaveDirectory") = 1

      .cOption("AutosaveDirectory") = sPDFPath

      .cOption("AutosaveFilename") = sPDFName

      .cOption("AutosaveFormat") = 0 ' 0 = PDF

      .cClearCache

    End With

   ' Print the QlikView Report

    ActiveDocument.PrintDocReport "RP05", "PDFCreator"

    'Wait until the print job has entered the print queue

    Do Until pdfjob.cCountOfPrintjobs = 1

     ActiveDocument.GetApplication.Sleep 20

        ' in VBScript use WScript.Sleep(20)

    Loop

    pdfjob.cPrinterStop = False

    'Wait until PDF creator is finished then release the objects

    Do Until pdfjob.cCountOfPrintjobs = 0

     ActiveDocument.GetApplication.Sleep 20

        ' in VBScript use WScript.Sleep(20)

    Loop

    pdfjob.cClose

    Set pdfjob = Nothing

    next

  

End Sub