Page 1 of 1

PDFPrinterSettings are not set

Posted: Wed Feb 14, 2018 6:23 pm
by eleng
I use bullzip to create protected PDF file from MS Access Report.
My settings :
- code is in VBA
- MS Access 2013
- Bullzip PDF printer 11.5

I am not able to set the desired security setting. I have no error and PDF is generated with password but when I check the security setting of the file they are not set as I wanted (for exemple for AllowCopy).

I tried several setting :
.SetValue "AllowCopy", IIf(bAllowCopy, "yes", "no")
.SetValue "AllowCopy", IIf(bAllowCopy, "true", "false")

I am not able to put AllowCopy setting to False

Do you have any idea ?

The complete code is :

Function PrintReportAsPDFwithBullZip(ByVal rptName As String, _
Optional sWhereCondition As String = "", _
Optional sDirectory As String = "", _
Optional sFileName As String = "", _
Optional sTitle As String = "", _
Optional sOwnerPassword As String, _
Optional sUserPassword As String, _
Optional bOpenViewer As Boolean = True, _
Optional bConfirmOverwrite As Boolean = True, _
Optional bAllowAssembly As Boolean = False, _
Optional bAllowCopy As Boolean = False, _
Optional bAllowModifyAnnotations As Boolean = False, _
Optional bAllowModifyContents As Boolean = False) _
As Boolean

On Error GoTo err_Error

Dim oBullzipPDF As Object, oBullzipUtil As Object
Dim strSavePath As String, strFileName As String
Dim strDefaultPrinter As String
Dim blnPrinterChanged As Boolean

Set oBullzipPDF = CreateObject("Bullzip.PDFPrinterSettings") 'Initialize the PDF class

'set the success flag to true here but it will be set to
'false if the function fails at any point
PrintReportAsPDFwithBullZip = True

If sDirectory = "" Then
sDirectory = CurrentProject.Path & "\"
Else
sDirectory = sDirectory
End If

If sFileName = "" Then
sFileName = Split(CurrentProject.Path, "\")(UBound(Split(CurrentProject.Path, "\")))
Else
sFileName = sFileName
End If

If LCase(Right(sFileName, 4)) <> ".pdf" Then
sFileName = sFileName & ".pdf"
End If

With oBullzipPDF
.Init
.SetValue "Output", sDirectory & sFileName
.SetValue "ShowSettings", "never"

''''''''''''''''''''''''''''''''''''''''''''''''''''
' Here you have to set the desired security settings
''''''''''''''''''''''''''''''''''''''''''''''''''''
.SetValue "OwnerPassword", sOwnerPassword
.SetValue "UserPassword", sUserPassword
.SetValue "EncryptionType", "Standard128bit" ' AES 128 bit and AES 256 bit encryption are supported but you must purchase a license to use it
.SetValue "AllowAssembly", IIf(bAllowAssembly, "yes", "no")
.SetValue "AllowCopy", IIf(bAllowCopy, "yes", "no")
.SetValue "AllowDegradedPrinting", "True"
.SetValue "AllowFillIn", "True"
.SetValue "AllowModifyAnnotations", IIf(bAllowModifyAnnotations, "yes", "no")
.SetValue "AllowModifyContents", IIf(bAllowModifyContents, "yes", "no")
.SetValue "AllowPrinting", "True"
.SetValue "AllowScreenReaders", "True"
''''''''''''''''''''''''''''''''''''''''''''''''''''
' End of security settings
''''''''''''''''''''''''''''''''''''''''''''''''''''

.SetValue "ShowPDF", IIf(bOpenViewer, "yes", "no")
.SetValue "ConfirmOverwrite", IIf(bConfirmOverwrite, "yes", "no")
.SetValue "SuppressErrors", "yes"
.SetValue "ShowProgress", "no"
.SetValue "ShowProgressFinished", "no"
.SetValue "Author", MAIN_DEFAULT_AUTHOR
.SetValue "Title", sTitle
.SetValue "Subject", ""
.WriteSettings (True) 'writes the settings in a runonce.ini that is immediately deleted after being used.
End With

If InStr(Application.Printer.DeviceName, "BullZip") = 0 Then ' If BullZip isn't the default printer
blnPrinterChanged = True ' Set the printer changed flag to true
strDefaultPrinter = Application.Printer.DeviceName ' Save name of current printer
SetDefaultPrinter "Bullzip PDF Printer" ' Use API to set the Current printer to Bullzip
End If

DoEvents
DoCmd.OpenReport rptName, acViewNormal, , sWhereCondition
DoEvents

If blnPrinterChanged Then SetDefaultPrinter strDefaultPrinter

'error handler and exit
err_Exit:
Set oBullzipPDF = Nothing
Exit Function
err_Error:
PrintReportAsPDFwithBullZip = False
MsgBox Err.Description
Resume err_Exit
Resume

End Function