Reputation: 307
Trying to use ITEXTSHARP/VB.NET to cycle through PDF's and check for portfolios. Not had much luck finding any specific documentation to deal with this, and came to a rather round-a-bout way (that ended up failing and giving a false positive on at least some PDFs with Bookmarks). So clearly the attribute I'm checking is not the correct one!
Here's my (failed) code as a starting point:
PDFDoc = New PdfReader(PDFToCount)
Dim Cat As PdfDictionary = PDFDoc.Catalog
Dim PDFNames As PdfDictionary = Cat.GetAsDict(PdfName.NAMES)
If PDFNames IsNot Nothing Then
'this seems to catch portfolios, but it also caught at least a few bookmarked PDF's
end if
Any ideas? Thanks!
Upvotes: 1
Views: 857
Reputation: 11731
If you wish to "Roughly" test a bunch of files in Windows you can run this command.
It is not a robust test as can false negative on some names but reduces (fast filters out) the files for a more thorough manual / iText / or other programmable test.
Remember to double up on %f (%%f) when using in a .cmd or .bat file
for /f "delims=" %f in ('dir /b *.pdf') do @(echo/ && find "/Collection" "%f" >nul && echo PORTFOLIO= "%f"|| echo NOT Portfolio or Error "%f")
Upvotes: 0
Reputation: 307
I think I ended up finding the solution. At least it's now working correctly in my small sample set. My original code was close, but I changed
Dim PDFNames As PdfDictionary = Cat.GetAsDict(PdfName.NAMES)
to
Dim PDFNames As PdfDictionary = Cat.GetAsDict(PdfName.COLLECTION)
otherwise the code remains the same and it looks like I'm getting the results I wanted. Hopefully that helps someone in the future... and hopefully I am correct.
Upvotes: 2