Copy link to clipboard
Copied
Hi All,
I have written a script to automate the conversion of pdf files using Adobe photoshop. However, I am facing an issue while opening a pdf file with PDF Open options (highlighted in bold). I have tried using both vbscript and python. Please find below the error:
vbscript.vbs(39, 4) Adobe Photoshop: Illegal argument - argument 1 - File/Folder expected
Below is the part of the code where I am getting the error.
Private Function getPdfConv(ByVal ifilename, ByVal pdfcount, ByVal iFile)
Dim pdffolder, pdffolderpath, page,awayActiveDoc
pdffolderpath = ifilename
If Not oFso.FolderExists(pdffolderpath) Then
Set pdffolder = oFso.CreateFolder(pdffolderpath)
WScript.Echo("A new folder has been created at: " & pdffolderpath)
End If
For page=1 to pdfcount
pdfOpenOptionsRef.Page = page
'WScript.Echo("FileName: "&iFile)
if oFso.FileExists(iFile) Then
set docref = appRef.Open(iFile,pdfOpenOptionsRef) 'line 39
set awayActiveDoc = appRef.ActiveDocument
awayActiveDoc.ResizeCanvas 8.5,11
awayActiveDoc.SaveAs pdffolderpath, pdfSaveOptionsRef
awayActiveDoc.close
end if
Next
End Function
Copy link to clipboard
Copied
hello @Pramod264896284g6d
Sorry I don't know vbscript, but your syntax doesn't look correct to me. Take a look at the photoshop-vbs-ref-2020 (page 117) from the link below.
Regards,
Mike
Copy link to clipboard
Copied
Hi Mike...I have used the same scripting pdf and getting error only in line 39.
Copy link to clipboard
Copied
Please, post full code with all variables.
Copy link to clipboard
Copied
I have removed the source directory. The same issue is noticed while running with Python code.
Option Explicit
Private Function getPdfPgCnt(ByVal sPath) 'Returns page count of file on passed path
Dim strTStr
With CreateObject("Adodb.Stream")
.Open
.Charset = "x-ansi"
.LoadFromFile sPath
strTStr = .ReadText(-1)
End With
With (New RegExp)
.Pattern = "Type\s*/Page[^s]"
.IgnoreCase = True
.Global = True
getPdfPgCnt = .Execute(strTStr).Count
End With
If getPdfPgCnt = 0 Then getPdfPgCnt = 1
End Function
'---------------------------------
Private Function getPdfConv(ByVal ifilename, ByVal pdfcount, ByVal iFile) 'Returns page count of file on passed path
Dim pdffolder, pdffolderpath, page,awayActiveDoc
pdffolderpath = ifilename
If Not oFso.FolderExists(pdffolderpath) Then
Set pdffolder = oFso.CreateFolder(pdffolderpath)
WScript.Echo("A new folder has been created at: " & pdffolderpath)
End If
For page=1 to pdfcount
pdfOpenOptionsRef.Page = page
if oFso.FileExists(iFile) Then
set docref = appRef.Open(oFso.GetFile(iFile),pdfOpenOptionsRef)
set awayActiveDoc = appRef.ActiveDocument
awayActiveDoc.ResizeCanvas 8.5,11
awayActiveDoc.SaveAs pdffolderpath, pdfSaveOptionsRef
awayActiveDoc.close
end if
Next
End Function
'--------------------------------
Dim oFso, iFile, sDir, appRef, pdfOpenOptionsRef, pdfSaveOptionsRef, docRef, ifilename
sDir = <<Source Directory>>
Set oFso = CreateObject("Scripting.FileSystemObject")
Set appRef = CreateObject("Photoshop.Application.170")
Set pdfOpenOptionsRef = CreateObject("Photoshop.PDFOpenOptions.170")
Set pdfSaveOptionsRef = CreateObject("Photoshop.PDFSaveOptions.170")
For Each iFile In oFso.getFolder(sDir).Files
If LCase(oFso.GetExtensionName(iFile)) = "pdf" Then
ifilename = Left(iFile, len(iFile)-4)
getPdfConv ifilename, getPdfPgCnt(iFile), iFile
End if
Next
Set oFso = Nothing
'--------------------------------
Copy link to clipboard
Copied
For some reason, the answer button does not work on the computer, so I will write briefly from the phone: when iterating over files in a directory, you write to the iFile variable a file object belonging to the Scripting.FileSystemObject class, while the appRef.Open() function expects to receive a string value. Not an object. When you call WScript.Echo("FileName: "& iFile) you think it's a string variable, but it's not (it's just that WScript.Echo is not so critical about type conversion).
That is, to avoid an error, before calling the appRef.Open() function, you need to convert the iFile object to a string:
set docref = appRef.Open(CStr(iFile), pdfOpenOptionsRef)