PDF
すべてのページの合計値をフォルダに入れるにはどうすればよいですか?また、出力は.txt
ファイルに書き込まれます。
したがって、すべてのページ数を取得する方法と、すべてのページ番号と名前PDF
を列に入れる方法を知る必要があります。PDF
私はこのような出力をします:
PDF file name Number of page
-------------------------------------
firstpdffile 30 pages
secondpdffile 25 pages
thirdpdffile 10 pages
fourthpdffile 5 pages
-------------------------------------
Total 70 pages
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
'--------------------------------
Dim oFso, iFile
Set oFso = CreateObject("Scripting.FileSystemObject")
'enumerating pdf files in vbs's base directory
For Each iFile In oFso.getFolder(oFso.GetParentFolderName(WScript.ScriptFullName)).Files
If LCase(oFso.GetExtensionName(iFile)) = "pdf" Then WScript.Echo iFile & " has "& getPdfPgCnt(iFile)&" pages."
Next
Set oFso = Nothing
'--------------------------------
この.bat
ファイルを使用してスクリプトを実行します
@echo off
color 0A
@set currentdir="%cd%"
title PDF page counter
del temp1.txt
del temp2.txt
del temp3.txt
del output.txt
cscript pdfpagecount.vbs > temp1.txt
BatchSubstitute.bat "%cd%" "" temp1.txt > temp2.txt & BatchSubstitute.bat "\" "" temp2.txt > temp3.txt & Type temp3.txt | findstr /I /V /C:"Microsoft" >>output.txt & del temp1.txt & del temp2.txt & del temp3.txt
exit
@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
:: OldStr [in] - string to be replaced
:: NewStr [in] - string to replace with
:: File [in] - file to be parsed
:$changed 20100115
:$source http://www.dostips.com
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)