<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pdf | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/pdf/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 18:21:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>pdf | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>How To Get the Page Count for Each PDF File in A Folder</title>
		<link>https://www.kjctech.net/how-to-get-the-page-count-for-each-pdf-file-in-a-folder/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-get-the-page-count-for-each-pdf-file-in-a-folder</link>
					<comments>https://www.kjctech.net/how-to-get-the-page-count-for-each-pdf-file-in-a-folder/#comments</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Mon, 13 Apr 2015 22:51:04 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[powershell]]></category>
		<guid isPermaLink="false">http://www.kjctech.net/?p=2705</guid>

					<description><![CDATA[<p>I was in the middle of setting up an Excel template based on the page count of each scanned PDF files in a particular folder. Manually filling the info in is fine if there are only handful scanned documents but it would take too much time with many errors along the way if there are 50 or even 100 of [&#8230;]</p>
The post <a href="https://www.kjctech.net/how-to-get-the-page-count-for-each-pdf-file-in-a-folder/">How To Get the Page Count for Each PDF File in A Folder</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>I was in the middle of setting up an Excel template based on the page count of each scanned PDF files in a particular folder. Manually filling the info in is fine if there are only handful scanned documents but it would take too much time with many errors along the way if there are 50 or even 100 of them.</p>
<p>So what I need is a simple easy way to have a tool to count each PDF files in a folder and export the page count in a CSV file that I can use later on.</p>
<p>There is an Open Source tool called <a href="http://sourceforge.net/projects/pdfpagecount/" target="_blank" rel="noopener">PDF Page Count</a> that I could use. It&#8217;s free and very easy to use. The export isn&#8217;t CSV based but is easy to manage to get the right format of data I can use to my template.</p>
<p><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="alignnone size-large wp-image-2706" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51-600x277.png?resize=600%2C277" alt="PDF Count - 2015-04-13 15_02_51" width="600" height="277" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=600%2C277&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=250%2C115&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=450%2C207&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=700%2C323&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=520%2C240&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=360%2C166&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?resize=100%2C46&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/PDF-Count-2015-04-13-15_02_51.png?w=757&amp;ssl=1 757w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p>But what I like more is a combination use of PowerShell and a small free utility <a href="https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/" target="_blank" rel="noopener">PDFtk free</a> that comes with a command-line.</p>
<p>Install the free utility PDFtk and then prepare a PowerShell script like below:</p>
<pre class="">$result = @()
$path = [string]$args[0]
dir $path\*.pdf | foreach-object{
 $pdf = pdftk.exe $_.FullName dump_data
 $NumberOfPages = [regex]::match($pdf,'NumberOfPages: (\d+)').Groups[1].Value
 $details = @{
 NumberOfPages = $NumberOfPages 
 Name = $_.Name
 }
 $result += New-Object PSObject -Property $details 
}
$result
$result | export-csv -Path $path\pdf.csv
echo "Th result has been saved in $path\pdf.csv file"</pre>
<p>The script takes the directory as the argument from the command line to identify which folder you want to scan the PDF files. For example, to scan all PDF files in H: drive to find the page count for each files in that directory, I run:</p>
<pre class="">.\pdf.ps1 H:</pre>
<p><img data-recalc-dims="1" decoding="async" class="alignnone size-large wp-image-2707" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43-600x287.png?resize=600%2C287" alt="Windows PowerShell - 2015-04-13 15_49_43" width="600" height="287" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43.png?resize=600%2C287&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43.png?resize=250%2C120&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43.png?resize=450%2C215&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43.png?resize=700%2C335&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43.png?resize=332%2C159&amp;ssl=1 332w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2015/04/Windows-PowerShell-2015-04-13-15_49_43.png?w=997&amp;ssl=1 997w" sizes="(max-width: 600px) 100vw, 600px" /></p>The post <a href="https://www.kjctech.net/how-to-get-the-page-count-for-each-pdf-file-in-a-folder/">How To Get the Page Count for Each PDF File in A Folder</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/how-to-get-the-page-count-for-each-pdf-file-in-a-folder/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2705</post-id>	</item>
	</channel>
</rss>
