Random crashing with Windows 7 and AMyuni 4.5

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
andyjadams
Posts: 3
Joined: Thu Oct 03 2013

Random crashing with Windows 7 and AMyuni 4.5

Post by andyjadams »

I have been working with Amyuni PDF converter and Miscrosoft Access for at least five years now. I have been able to program Amyuni to print reports directly to PDFs and also to use Amyuni to combine multiple reports together.

Just recently my company has migrated everyone from Windows XP to Windows7. We are now noticing random crashes when printing reports to PDF. There does not seem to be any pattern to the crashing. I can run a process a dozen times successfully and then later on it will crash. Every time is craches it seems to crash on a different report, or when I'm combining 2 PDFs together.

I have tried a number of ways or re-writing the code, but due to the randomness of the crashing it is very difficult to establish if the changes work.

Has anyone else experinced the same thing with Windows7?

Here is an example of the code

Code: Select all

Function PackageOutput(arrayOutput As Variant, strPDFFileName As String, rptBlankPage As String, Optional booReplace As Boolean = False, Optional booEmbedFont As Boolean = True) As Integer
' --- arrayOutput is the list of documents/reports in the correct order
'     The first part is the document type
'     The second part is the name
'     This sub-routine only handles Access reports and PDF files
'        (but could be adjusted to Word docs as well)
    On Error GoTo PackageOutput_Errors
    PackageOutput = 3 'Set the output to show a Fail - A successful run through will change this to Success
    
' --- Initialize the PDF printer
    Dim pdfPrinter As Object ', strPwd As String, strUsr As String
    Dim pdfDoc As Object
    Dim d As Integer, booAbort As Boolean, numPGs As Integer
    Dim PDFset As PDF_Settings
    Dim strFileName As String
    Dim FSO As Object
    Dim fnOptions As Variant, strLockName As String
    Dim booCont As Boolean
    
    strFileName = "m:\PDFTemp.pdf"
    booCont = False
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set pdfPrinter = MyAmyuni  'AmyuniPrinter 'CreateObject("CDIntfEx.CDIntfEx.4.5")
    Set pdfDoc = AmyuniDocument 'CreateObject("CDIntfEx.document.4.5")
        
' --- Store current settings
    PDFset.PwdOwner = pdfPrinter.OwnerPassword
    PDFset.PwdUser = pdfPrinter.UserPassword
    PDFset.Encrypt = pdfPrinter.encryption
    PDFset.Encrypt_Permissions = pdfPrinter.Permissions

' --- Configures printer
    ' Embed Fonts - if required
    If booEmbedFont Then
        pdfPrinter.fontembedding = True
        pdfPrinter.FileNameOptionsEx = NoPrompt + UseFileName + Concatenate + EmbedFonts + EmbedStandardFonts + FullEmbed
        fnOptions = NoPrompt + UseFileName + Concatenate + EmbedFonts + EmbedStandardFonts + FullEmbed
    Else
        pdfPrinter.FileNameOptionsEx = NoPrompt + UseFileName + Concatenate
        fnOptions = NoPrompt + UseFileName + Concatenate
    End If
    
    ' Remove encryption
    pdfPrinter.Permissions = 0
    pdfPrinter.OwnerPassword = ""
    pdfPrinter.UserPassword = ""
    pdfPrinter.encryption = False

'<<<   Now moved outside this sub routine   >>>    
'' --- Make Amyuni the default printer
'    pdfPrinter.SetDefaultPrinter

' --- Delete the temp PDF file if it already exists
    If FSO.FileExists(strFileName) Then
        Kill strFileName
    End If

' --- Send documents/reports to the PDF output file
    For d = LBound(arrayOutput, 2) To UBound(arrayOutput, 2)
        Select Case arrayOutput(LBound(arrayOutput, 1), d)
            Case "pdf", "doc"
                Call pcProgress(CLng(d), UBound(arrayOutput, 2), "Adding insert: " & getFileName(CStr(arrayOutput(UBound(arrayOutput, 1), d))))
            Case Else
                Call pcProgress(CLng(d), UBound(arrayOutput, 2), "         Compiling disclosure")
        End Select
        'First add Blank page if PDF has Odd number of pages
        If FileExists(strFileName) Then
            pdfDoc.Open strFileName
            
            If numPGs < pdfDoc.pagecount Then
                'Last print was added to the file - so OK to continue
                numPGs = pdfDoc.pagecount
            Else
                'Last print failed - so fail the process
                If booCont Then
                    booCont = False
                Else
                    GoTo PackageOutput_Exit
                End If
            End If
            
            If numPGs Mod 2 = 1 Then 'pdfDoc.pagecount Mod 2 = 1 Then
            ' --- Lock the PDF printer before printing - allows for file name and file name options to be passed at this point
                strLockName = rptBlankPage
                pdfPrinter.lock strLockName
                pdfPrinter.SetDocFileProps strLockName, fnOptions, "", strFileName
            ' --- Print the report to the PDF
                DoCmd.OpenReport rptBlankPage, acViewNormal
                
                numPGs = numPGs + 1
            End If
        End If
    ' --- Now add the reports or PDF
        On Error GoTo PackageOutput_Exit 
        Select Case arrayOutput(LBound(arrayOutput, 1), d)
            Case "pdf"
            ' --- Do a check to see if file exists
                If FileExists(CStr(arrayOutput(UBound(arrayOutput, 1), d))) Then
                    DoEvents
                    Call Append_2_PDF_docs(strFileName, CStr(arrayOutput(UBound(arrayOutput, 1), d)))
                Else
                    If MsgBox("Cannot find: " & CStr(arrayOutput(UBound(arrayOutput, 1), d)) & vbCrLf & "Do you wish to continue? ", vbYesNo + vbExclamation, " !!! Missing PDF insert !!!") = vbNo Then
                        GoTo PackageOutput_Exit
                    End If
                    booCont = True
                End If
            Case "rpt"
            ' --- Lock the PDF printer before printing - allows for file name and file name options to be passed at this point
                strLockName = arrayOutput(UBound(arrayOutput, 1), d)
                pdfPrinter.lock strLockName
                pdfPrinter.SetDocFileProps strLockName, fnOptions, "", strFileName
                
            ' --- Print the report to the PDF
                DoCmd.OpenReport arrayOutput(UBound(arrayOutput, 1), d), acViewNormal
                DoEvents
                
        End Select
        DoEvents
    Next d
    
    ' --- Check to see if the output has completed correctly - a CAT file will remain if there was a problem
    If Not FSO.FileExists(strFileName & ".cat") Then
        Call pcProgress(1, 2, "  Removing temporary file ... ")
        If FSO.FileExists(strPDFFileName) Then
            Kill strPDFFileName
        End If
        Call pcProgress(2, 2, "    Creating output file ... ")
    ' --- Move the temporary file to the correct output location once it is complete
        FSO.moveFile strFileName, strPDFFileName
        ' Process successful - can show the check mark on the form
        PackageOutput = 2
    End If
    
    DoEvents
    
PackageOutput_Exit:

' --- Unlock in case the printing fails
    pdfPrinter.unlock strLockName, 1000 

' --- Restore pervious configuration
    pdfPrinter.encryption = PDFset.Encrypt
    pdfPrinter.OwnerPassword = PDFset.PwdOwner
    pdfPrinter.UserPassword = PDFset.PwdUser
    pdfPrinter.Permissions = PDFset.Encrypt_Permissions
    pdfPrinter.DefaultFileName = "" 
    
    ' Remove Font embedding if added
    If booEmbedFont Then
        pdfPrinter.fontembedding = False
    End If
    
'<<<   Now moved outside this sub routine   >>>
'' --- Restore the previous default printer
'    Call pcProgress(1, 2, "    Restoring default printer ")
'    pdfPrinter.RestoreDefaultPrinter
    
' --- Finish the job and tidy up
'    pdfPrinter.DriverEnd
'<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>

    Call pcProgress(0, 0)
    Set FSO = Nothing
    Set pdfPrinter = Nothing
    Set pdfDoc = Nothing
    
    Exit Function

PackageOutput_Errors:
    Select Case Err.Number
        Case 70 'Permission denied - when trying to delete the PDF
            MsgBox "The temporary compilation file is open or locked.  Please close down and try to delete the file manually", vbInformation + vbOKOnly, " !!! Cannot delete file !!!"
        Case Else
            Call OpenMessage("sub: PackageOutput")
    End Select
    'Resume
    GoTo PackageOutput_Exit
End Function
andyjadams
Posts: 3
Joined: Thu Oct 03 2013

Re: Random crashing with Windows 7 and AMyuni 4.5

Post by andyjadams »

Sorry I should have mentioned where the crash occurs. It crahses at the line "DoCmd.OpenReport " which is when Amyuni prints the report.

Crashing at this point also means that I am unable to trap it.
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Re: Random crashing with Windows 7 and AMyuni 4.5

Post by Jose »

Hello,

Based on your comment “Every time is craches it seems to crash on a different report, or when I'm combining 2 PDFs together.” I would suspect that you are trying to append PDF documents that have not completely been generated.

One way to verify if this is the case, is to put a sleep() state of 5 seconds right before you process the PDF documents.

If adding the sleep()resolves your issue, then you would need to look the handling the events fired the Amyuni PDF Converter. You can handle the EndDocPost() event which is fired by the PDF Converter at the end of a print job. When the event is fired you know that you can safely append the PDF document that has just be generated.

This described in our online documentation which you can get to from the link below:
http://www.amyuni.com/WebHelp/Amyuni_Do ... ndling.htm
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite
andyjadams
Posts: 3
Joined: Thu Oct 03 2013

Re: Random crashing with Windows 7 and AMyuni 4.5

Post by andyjadams »

Thank for the reply. I had already tried to pause the process in between printing each report to the PDF, but it had no effect.

I will have to look at what is happen to th ecoverter as per your other suggestion.
Post Reply