Problem printing multiple documents (vb5, demo v1.50d)

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
CraigBennett
Posts: 5
Joined: Thu Mar 11 2004
Location: Winnipeg, MB Canada

Problem printing multiple documents (vb5, demo v1.50d)

Post by CraigBennett »

I am trying to print multiple documents (paths stored in one dimensional array PDFArray). The first document will print, but the second always fails with a runtime error Method 'Print' of object 'IPDFCreativeX' failed. This is using the demo of 1.50d I downloaded the other day.

Here is the code snipped that is printing...

For iDocument = 0 To UBound(PDFArray)
With pdf
.Open PDFArray(iDocument), ""
.Print "", False
End With
Next
CraigBennett
Posts: 5
Joined: Thu Mar 11 2004
Location: Winnipeg, MB Canada

Post by CraigBennett »

I think I have it working now. The documentation could really use a bit of work. What I found was I had to create a new object for each time I wanted to print. I don't know if it is right, but it seems to run.

Code: Select all

 
  Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX
  Const pdfLicenseTo As String = "Suite Evaluation ...
  Const pdfLicenseCode As String = "07EFCD ...
  
  For iDocument = 0 To UBound(PDFArray)
    Set pdf = New ACPDFCREACTIVEX.PDFCreactiveX
    With pdf
      .SetLicenseKey pdfLicenseTo, pdfLicenseCode
      .Open PDFArray(iDocument), ""
      .Print "", False
    End With
    Set pdf = Nothing
  Next
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello,

I didn't try your below code, but I think that creating a new instance of the PDFCreactiveX each time you want to print is not really needed. You just need to call SetLicenseKey before printing.

Thanks.
CraigBennett
Posts: 5
Joined: Thu Mar 11 2004
Location: Winnipeg, MB Canada

Post by CraigBennett »

Hi Joan,

I dropped my files and installed again from the link you provided. Seemed to install the same version numbers that were currently installed. Still having the same problem. It will print the first document, but fail on the second document.

Also, I am finding I cannot open a file if Acrobat Reader has it open, which could pose a major problem.

Craig
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan »

Hello Graig,

Please send this issue to support@amyuni.com so we can check it closer and see what is really happening.

A sample of your application or of the documents you are trying to print will be helpfull.

Thanks.
durban
Posts: 26
Joined: Tue Oct 01 2002
Contact:

Hello,

Post by durban »

Just create the pdf component on a second blank form, at any print from the first form load the second form with the setlicence in create, load the print, close and destroy the second form, etc ...

Didier
CraigBennett
Posts: 5
Joined: Thu Mar 11 2004
Location: Winnipeg, MB Canada

Post by CraigBennett »

This is what I ended up with....

Code: Select all

Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Private Sub cmdTest_Click()
  '' SAVE TREES. SET YOUR PRINTER TO PAUSED WHEN YOU ARE TESTING
  
  Dim pdfarray As Variant
  Dim n As Integer
  Dim iResult As Integer
  
  ReDim pdfarray(2)
  pdfarray(0) = "C:\testpdf1.pdf"
  pdfarray(1) = "C:\testpdf2.pdf"
  pdfarray(2) = "C:\testpdf3.pdf"
  
  '' Print entire array
  For n = 0 To UBound(pdfarray)
   iResult = PrintPDF(CStr(pdfarray(n)), CStr(pdfarray(n)))
  Next
  
End Sub


Private Function PrintPDF(sPDFPath As String, Optional sPDFTitle As String, Optional sPrinter As String) As Integer
On Error GoTo ErrHandler
  '' Prints a PDF using ther Amyuni PDF Creator
  ''
  '' Requires
  ''  - a reference to "Amyuni PDFCreativeX Component"
  ''  - Declaration of Windows API function GetTempPath
  ''
  '' sPDFPath  - Valid path to a PDF. Can be drive letter or UNC.
  ''             This routine does not check to see if the file actually exists
  '' sPDFTitle - Title to display in the printer status window.  If we omit this, sPDFPath will be used
  '' sPrinter  - printer to send PDF to. if we omit this, the default printer will be used.
  ''
  '' Return: 1 - Success, 0 - Failure
  
  '' ****** THIS IS THE EVALUATION LICENSE. IT WILL WATERMARK THE PRINTOUTS *******
  Const pdfLicenseTo As String = "Suite Evaluation Developer Pro"
  Const pdfLicenseCode As String = "07EFCDAB01000100004D402BB682EE8F2F5FD15C4CA2E326DA8D53D98E391DB5CCC674EE34D6149B6C3F9C94E116C9E48105E9A1D23B016E0A8D1B0EA74C099D7F7E61916711D6397354A164977BD507168ED24F80DAFA04E32710CE9F03D0"
  
  Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX
  Dim lResult As Long       '' Holds result of Open function
  Dim sTempPath As String   '' Holds temp path when first opening of pdf fails
  
  sTempPath = ""
  PrintPDF = 0    '' We will set this to 1 after we print
  
  If IsMissing(sPDFTitle) Then sPDFTitle = sPDFPath '' If we did not specify a title, use the filename
  If IsMissing(sPrinter) Then sPrinter = "" '' No printer = default printer

  
  Set pdf = New ACPDFCREACTIVEX.PDFCreactiveX
  With pdf
    '' Each time the object is created, we need to activate it with the license information
    .SetLicenseKey pdfLicenseTo, pdfLicenseCode
    
    '' Try to open the PDF.
    lResult = .Open(sPDFPath, "")
    
    '' If the file is opened by Acrobat Reader, it may have a
    '' lock on it. If this is the case, we should be able to copy
    '' the file to the temp directory and open it from there.
    If lResult = 0 Then
      '' Get the temp folder from the Windows API
      sTempPath = Space(260)
      If GetTempPath(260, sTempPath) <> 0 Then
        sTempPath = Trim$(Left$(sTempPath, InStr(sTempPath, Chr$(0)) - 1)) & "_amyuni" & (Timer * 100) & ".pdf"
        FileCopy sPDFPath, sTempPath
        lResult = .Open(sTempPath, "")
      End If
    End If
      
    '' If we were able to open the document (or the copy), print it out
    If lResult = 1 Then
      .ObjectAttribute("Document", "Title") = sPDFTitle '' Set printer status title
      .ScaleToPrinter = acScaleBoth '' Scale to page hoizontal and vertical
      .Print sPrinter, False  '' print to sPrinter with no dialog box
      PrintPDF = 1
      
      '''' If we want to have a dialog box, then we need to trap the error
      '''' because we will get one if we press cancel
      ''On Error Resume Next
      ''.Print sPrinter, True  '' print to sPrinter with a dialog box
      ''If Err = 0 Then PrintPDF = 1  '' if we didnt cancel, we should nto have an error
      ''On Error GoTo ErrHandler
    End If
  End With
  Set pdf = Nothing
  
  '' if we created the temp file and it is there, clean it up
  If sTempPath > "" Then
    If Dir(sTempPath) > "" Then
      Kill sTempPath
    End If
  End If

Exit Function
ErrHandler:
  Set pdf = Nothing
  MsgBox "Error in PrintPDF function of " & Me.Name & " form. Error # " & Err.Number & " " & Err.Description
End Function
[/code]
durban
Posts: 26
Joined: Tue Oct 01 2002
Contact:

Print error

Post by durban »

Last month i do the same code with a function and i create a object and free it, but it's not working, i create a VB FORM with the activex component (not in COM) and now it's working.

Didier
Post Reply