Skip secured PDF "This operation is not permitted"

Using OLE Automation API
Post Reply
mofoster
Posts:3
Joined:Mon Apr 02, 2012 1:38 am
Skip secured PDF "This operation is not permitted"

Post by mofoster » Mon Apr 02, 2012 1:41 am

Hi,

I've try to write a vbscript using P2F.ConvertDir to convert entire directory. However, every time if my process encoutered secured PDF it will prompt "This operation is not permitted" dialog box waiting for manual interaction.

Is there anyway for the process to automatically skip those files and save to the log for further process?

THanks

Michael

mofoster
Posts:3
Joined:Mon Apr 02, 2012 1:38 am

Re: Skip secured PDF "This operation is not permitted"

Post by mofoster » Mon Apr 02, 2012 1:43 am

Here's my code snipp
' Clean up all Flash files generated previously
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd /c del C:\temp\swf\*.swf /s", , True

Set P2F = CreateObject("P2F.Server") ' Create Server object
Set DefBPOpt=P2F.DefaultBatchProcessingOptions
DefBPOpt.CreateLogFile = True
DefBPOpt.LoggingLevel = 1
DefBPOpt.ApplyChanges

DefBPOpt.LogFileName = "C:\temp\Print2FlashConv.log"
P2F.ConvertDir "C:\temp\DocumentAnnex",,"C:\temp\swf"

MsgBox "All documents have been converted"

staff
Posts:267
Joined:Sat Dec 15, 2007 4:48 pm

Re: Skip secured PDF "This operation is not permitted"

Post by staff » Tue Apr 03, 2012 5:40 am

You have two ways:
1. Use ConvertDir as you do it currently and later analyze the created log file for documents which caused an error
2. Convert files one by one using ConvertFile method. You may write the name of each file for which you encountered a problem to your own log file. To process errors in VBScript you need to execute this code once:

Code: Select all

on error resume next
and then you may check for errors after conversion in this way:

Code: Select all

P2F.ConvertFile SourceFIle, OutputFile
if Err.Number<>0 then ProcessError(SourceFIle, Err.Description)
ProcessError is assumed to be your function for processing error messages. To scan all files in a directory you may use FileSystemObject.

mofoster
Posts:3
Joined:Mon Apr 02, 2012 1:38 am

Re: Skip secured PDF "This operation is not permitted"

Post by mofoster » Tue Apr 03, 2012 11:01 pm

I've written a small vbs script to perform batch converting, and save error into a seperate log file, hope it'll help someone :)

Path = Left(WScript.ScriptFullName, Len(WScript.ScriptFullName)-Len(WScript.ScriptName)) ' Obtain path to this script directory
' Clean up all Flash files generated previously
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "cmd /c del *.swf /s", , True

set P2F = CreateObject("P2F.Server") ' Create Server object
set MyBPOpt=CreateObject("Print2Flash3.BatchProcessingOptions")

Dim FSO, FLD, FIL
Dim strSourceFolder, strDestFolder, strFilename, strErrorLog
Dim wkNow

strSourceFolder = Path & "\DocumentAnnex"
strDestFolder = Path & "\SWF"
'Create the filesystem object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Get a reference to the folder you want to search
set FLD = FSO.GetFolder(strSourceFolder)

IF Not FSO.FolderExists(Path & "\Log") Then
Set objFolder = FSO.CreateFolder(Path & "\Log")
END IF

'Generate YYYYMMDDMMSS serial for log filename
wkNow= Year(Now())
wkNow= wkNow & Right("0" & Month(Now()) , 2)
wkNow= wkNow & Right("0" & Day(Now()) , 2)
wkNow= wkNow & "_" & Right("0" & Hour(Now()) , 2)
wkNow= wkNow & Right("0" & Minute(Now()) , 2)
wkNow= wkNow & Right("0" & Second(Now()) , 2)

'ErrorLog Filename
strErrorLog = Path & "Log\ErrorLog_" & wkNow & ".txt"

'Settings
MyBPOpt.CreateLogFile = true
MyBPOpt.LogFileName = Path & "Log\Log_" & wkNow & ".txt"
MyBPOpt.PrintingTimeout = 1000000000
MyBPOpt.BeforePrintingTimeout = 25000
MyBPOpt.KillProcessIfTimeout = 1

'loop through the folder and get the file names
For Each Fil In FLD.Files
On Error Resume Next
strFilename = strSourceFolder + "\" + Fil.Name
P2F.ConvertFile strFilename, strDestFolder + "\" + Fil.Name + ".swf",, MyBPOpt
IF Err.Number <> 0 THEN
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = FSO.OpenTextFile(strErrorLog, 8, True)
WriteStuff.WriteLine(strFilename & "," & FSO.GetFileName(strFilename) & "," & FSO.GetExtensionName(strFilename) & "," & Err.Description)
WriteStuff.Close
SET WriteStuff = NOTHING
END IF
Next

Post Reply