I have huge number of PDF documents, they are being manually checked for watermarks in all pages. Is it possible for this to be automated through scripts. Each page contains only one watermark. It will also be better to return the list of filenames or documents that are not having watermarks in all pages.
Watermarks in a pdf will be stored in the OCG object. So you have to ask acrobat if this object is in the pdf and whether it keeps watermarks.
Attach you will find VBS/VBA code which can do that. The Code you can copy over to Notepad and then save it as "FindWatermarks.vbs" on the desktop. Then drag&drop some pdfs on it and the script will tell you if the pdf include watermarks or not. Good luck, Reinhard
PS.: The script works only with Adobe Acrobat $$$ version, not with only Reader!
'// test dropped files for included watermarks
set WshShell = CreateObject ("Wscript.Shell")
set fs = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
'// check if files has been dropped on the script
if objArgs.Count < 1 then
msgbox("Please drag a file on the script")
WScript.quit
else
msgbox("Files Count: "& objArgs.Count &vblf &"Start with file: " & ObjArgs(0))
end if
'//contact Acrobat
Set App = CreateObject("AcroExch.App")
App.show 'comment or take out to work in hidden mode
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
'// write needed js code into vbs variable
js = "var found "&vblf _
& "var ocgArray = this.getOCGs();" &vblf _
& "if (ocgArray == null) { " &vblf _
& " found = 0; " &vblf _
& " }else{ " &vblf _
& " for (var i=0; i < ocgArray.length; i++) { " &vblf _
& " if (ocgArray[i].name == 'Watermark') { " &vblf _
& " found= 1; " &vblf _
& " }else{ " &vblf _
& " found = 0; " &vblf _
& " } " &vblf _
& " } " &vblf _
& " }"
filesWithWm = ""
filesExWm =""
'//open files via Avdoc and check for watermarks
for i=0 to objArgs.Count - 1
FileIn = ObjArgs(i)
If AVDoc.Open(FileIn, "") Then
'msgbox(FileIn)
Set PDDoc = AVDoc.GetPDDoc()
Set jso = PDDoc.GetJSObject
AForm.Fields.ExecuteThisJavaScript js
if jso.found = 1 then
filesWithWm = filesWithWm &FileIn &vblf
else
filesExWm = filesExWm &FileIn &vblf
end if
end if
next
'// report found files
if InStr(filesWithWm,":\")>0 then msgbox("Watermarks found:" &vblf & filesWithWm)
if InStr(filesExWm,":\")>0 then msgbox("No Watermarks found:" &vblf & filesExWm)
'// exit application
App.CloseAllDocs
App.Exit
Set AForm = Nothing
Set JSO = Nothing
Set PDDoc = Nothing
Set AVDoc = Nothing
Set App = Nothing
If you need small code changes let me know.
Related
I have this code, my objective is to copy and paste a folder (with all its content) from a current template folder to paste onto a destination file path that is based on the field values as a condition to the new file destination name.
I am receiving an error:
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
Not sure why, can you please help. Thank you.
Private Sub Command83_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "C:\Database Test Center\Master" '<< Change
ToPath = "C:\Database Test Center\Projects\" & Me.ProjectName.Value & "-" &
Me.Lead.Value & "\MasterTemplate"
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
End Sub
I am using FilesystemWatcher to look for newfile in the directory.
The file type of investigation is .blf. It is being created of size almost 10MB (not constant but around/almost figure)
Once the file is created and being written completely, i want to copy the file into someother folder.
But the program immediately starts to copy even when the file is in process of being written and i get the error of
"The Process cannot access the file because it is being created by another process"
i want to make a condition to check if the file is completly created and then do the copy;
Below is my code:
Private Sub Fsw1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles Fsw1.Created
ListBox2.Items.Add("File- " & e.FullPath.ToString & " created at: " & System.DateTime.Now)
Dim blffolder As String = String.Format("C:\Users\nha4abt\Desktop\Main\blf_files" + "\{0}", DateTime.Today.ToString("dd-MMM-yyyy"))
'Check if subfolders exists or not
If (Not System.IO.Directory.Exists(blffolder)) Then
System.IO.Directory.CreateDirectory(blffolder)
End If
'Repeat steps 1-6
Dim destPath As String = Path.Combine(blffolder, Path.GetFileName(e.FullPath))
'System.Threading.Thread.Sleep(1000)
File.Copy(e.FullPath, destPath, True) 'copy all the files in destination folder
' Compare the two files that are referenced in the textbox controls.
If (FileCompare(e.FullPath, destPath)) Then
ListBox1.Items.Add(e.FullPath & "- is correctly copied :) ") ' put all the names in listbox; Not necessary
'To Add: make a log file .txt to put the record of all the files that are copied during the process
Dim strFile As String = String.Format(DestinationDirectory + "\Log_{0}.txt", DateTime.Today.ToString("dd-MMM-yyyy")) 'create a .txt file for log
Dim texttoappend As String
Dim timedate As String
timedate = DateTime.Now
texttoappend = e.FullPath + vbCrLf + "copied to" & vbCrLf & destPath & vbCrLf & "at" & timedate + vbNewLine & vbCrLf
File.AppendAllText(strFile, String.Format(texttoappend, Environment.NewLine))
Else
MessageBox.Show("Files are not equal.")
File.Copy(e.FullPath, destPath, True) 'copy again
End If
End Sub
I tried to use System.Threading.Thread.Sleep(1000) but couldn't run the program. please guide
I would suggest implementing a Function which checks if the file is still being used by another process and avoid System.Threading.Thread.Sleep(1000).
Original function here
protected virtual bool IsFileLocked(FileInfo file)
{
FileStream stream = null;
try
{
stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
}
catch (IOException)
{
//the file is unavailable because it is:
//still being written to
//or being processed by another thread
//or does not exist (has already been processed)
return true;
}
finally
{
if (stream != null)
stream.Close();
}
//file is not locked
return false;
}
I'm working on a rss feed reader and seems so work great.
The only thing that I seem not to get working is to read the image in the feed.
<itunes:image href="http://www.itunes.com/image.jpg"/>
Can anyone help?
This is a part of my code.
For Each objItem in objItems
On Error Resume Next
TheTitle = objItem.selectSingleNode("title").Text
TheLink = objItem.selectSingleNode("image").Text
Theimg = objItem.SelectSingleNode("itunes").Attributes(":image").InnerText
Response.Write "<div class='article'>" &_
"<a href=" & TheLink & ">" & _
"<span>" & Theimg & TheTitle & "</span>" & _
"</a>" & _
"</div>"
Next
Your image address needs to go inside an image tag
Response.Write "<div class=""article"">" &_
"<a href=""" & TheLink & """>" & _
"<img src=""" & Theimg & """ alt=""" & TheTitle & """ />" & _
"</a>" & _
"</div>"
If you're wondering why all the double quotes, see this question
Adding quotes to a string in VBScript
As an aside, if you understand XSL then I find that the best way to handle RSS feeds in Classic ASP is to do a server side XSLT transformation. The ASP looks like this
set xml = Server.CreateObject("Msxml2.DomDocument.6.0")
xml.setProperty "ServerHTTPRequest", true
xml.async = false
xml.validateOnParse = false
xml.load("http://your-rss-feed")
set xsl = Server.CreateObject("Msxml2.DomDocument.6.0")
xsl.load(Server.Mappath("yourxslfile.xsl"))
Response.Write(xml.transformNode(xsl))
set xsl = nothing
set xml = nothing
`Here I have converted one string to XML:
xmlString =
" <?xml version='1.0' encoding='UTF-8' standalone='yes'?>" & _
" <hub:notifications>" & _
" <hub:notificationId>728dc361-8b4f-4acc-ad2d-9a63125c5114</hub:notificationId>" & _
" <hub:notificationId>5b7c6989-ee27-422c-bbed-2f2c36136c5b</hub:notificationId>" & _
" <hub:notificationId>67d1fffe-ab3f-43e3-bb03-24926debe2dc</hub:notificationId>" & _
" </hub:notifications>"
objXML.LoadXml(xmlString)
set Node = objXML.selectSingleNode("hub:notifications/hub:notificationId")
i = 0
Count = 0
For Each Node In objXML.selectNodes("hub:notifications")
ReDim Preserve aryNotificationIDs (i + 1)
aryNotificationIDs(i) = Node.selectSingleNode("hub:notificationId").text
Count++
Next
Response.write Count
In above, I am not getting Count of Child nodes
and How to get the child node values.
Can any one help me?
Thanks,
Jagadi`
There are many problems with your posted code.
FirstWhat language are you using? There seems to be styles from VBScript and JScript. It is predominately VBScript so I'm going to assume that is what you meant to use throughout.
Second
The XML declaration needs to be the first characters in the string.
That is:
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" & _
not
" <?xml version='1.0' encoding='UTF-8' standalone='yes'?>" & _
Third
XML with namespaces requires an xml namespace declaration in the top-level node that use the namespace.
For example the root node.
<hub:notifications>
would become
<hub:notifications xmlns:hub='http://stackoverflow.com'>
But you would replace the stackoverflow URL with one appropriate to you.
Fourth
If you want to iterate through the child nodes of hub:notifications then you need to change the FOR deceleration to:
For Each Node In objXML.selectSingleNode("hub:notifications").childNodes
Fifth
i is not increasing in your loop, so you are setting aryNotificationIDs(1) to the different values of the nodes.
Sixth
Related to the first. There is no ++ operator in VBScript. And you don't need both i and Count in the For loop.
Additionally
You don't need to cycle through the nodes to get a count. You can use an xpath selector, and the length property. E.g. objXML.selectNodes("hub:notifications/hub:notificationId").length
Finally
I have taken you code and applied the above suggestions, I've also included an error checking part that checks that the xml has correctly loaded. The code below will output the count of hub:notificationId nodes, and list all the values in the array aryNotificationIDs. I've removed other superfluous code.
xmlString = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" & _
" <hub:notifications xmlns:hub='http://stackoverflow.com'>" & _
" <hub:notificationId>728dc361-8b4f-4acc-ad2d-9a63125c5114</hub:notificationId>" & _
" <hub:notificationId>5b7c6989-ee27-422c-bbed-2f2c36136c5b</hub:notificationId>" & _
" <hub:notificationId>67d1fffe-ab3f-43e3-bb03-24926debe2dc</hub:notificationId>" & _
" </hub:notifications>"
Set objXML = Server.CreateObject("Msxml2.DOMDocument")
objXML.LoadXml(xmlString)
If objXML.parseError.errorCode <> 0 Then
Response.Write "<p>Parse Error Reason: " & objXML.parseError.reason & "</p>"
Else
For Each node In objXML.selectSingleNode("hub:notifications").childNodes
ReDim Preserve aryNotificationIDs(i)
aryNotificationIDs(i) = node.text
i = i + 1
Next
Response.Write "<p>Count: " & i & "</p>"
For j = 0 to i - 1
Response.Write "<p>aryNotificationIDs(" & j & ") = " & aryNotificationIDs(j) & "</p>"
Next
End If
I am trying to maintain a log field (fldUserLog ) of my database table so that when updating each raw, the log field will be amended with given log string.
Log string
strUserLog = "Added by : " & Session("auth_Id") & " at " & Now() & " from IP " &
Request.ServerVariables("REMOTE_ADDR") & vbCrLf
and I am using SQL command parameters to UPDATE query. as follows
strSQLQuery = "UPDATE myTable SET " _
& "fldTitle = #xTitle, " _
& "fldDesc = #xDesc, " _
& "fldUserLog = fldUserLog + #xUserLog " _
& "WHERE fldId = #xId ;"
strMessage = "updated"
ObjAddDB.setCommand(strSQLQuery)
With ObjAddDB
.setParameters("#xTitle", frmTitle.Text)
.setParameters("#xDesc", frmDesc.Text)
.setParameters("#xUserLog", strUserLog)
.setParameters("#xId", MyItemId)
End With
Please note that setCommand and setParameters are my own methods I am using in my database.vb class file.
I get following error when its executed
Exception Details:
System.Data.SqlClient.SqlException:
Incorrect syntax near 'fldUserLog'.
please help me to use my UPDATE query to amend existing data with command parameters.
If the format of the fldUserLog field value contains spaces, you need to embrace the value with [ ] ..
& "fldUserLog = [fldUserLog #xUserLog] " _
I guess what you may want to write is the following:
& "fldUserLog = #xUserLog " _