<?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>Kushal's Java Blog</title>
	<atom:link href="http://sanjaal.com/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://sanjaal.com/java</link>
	<description>www.sanjaal.com/java</description>
	<lastBuildDate>Sat, 06 Mar 2010 22:16:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Splitting PDF File Using Java iText API Into Multiple PDFs</title>
		<link>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/</link>
		<comments>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 22:16:49 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java PDF]]></category>
		<category><![CDATA[divide pdf into multiple pdfs using java]]></category>
		<category><![CDATA[free pdf splitter source code java]]></category>
		<category><![CDATA[How To Split Pdf File Using Java Code]]></category>
		<category><![CDATA[how to split pdf in java]]></category>
		<category><![CDATA[itext API tutorial split pdf]]></category>
		<category><![CDATA[itext pdf solitter]]></category>
		<category><![CDATA[itext pdf split]]></category>
		<category><![CDATA[itext pdf split example]]></category>
		<category><![CDATA[iText PDFCopy Java Example]]></category>
		<category><![CDATA[iText PDFImportedPage Example Java]]></category>
		<category><![CDATA[java free pdf splitter code]]></category>
		<category><![CDATA[java pdf api tutorial]]></category>
		<category><![CDATA[java pdf break]]></category>
		<category><![CDATA[java pdf cutter example]]></category>
		<category><![CDATA[java pdf cutter tutorial]]></category>
		<category><![CDATA[java pdf tutorial]]></category>
		<category><![CDATA[pdf cut in java]]></category>
		<category><![CDATA[pdf merger splitter]]></category>
		<category><![CDATA[PDF Split]]></category>
		<category><![CDATA[pdf split page from existing pdf]]></category>
		<category><![CDATA[pdf split sample code java]]></category>
		<category><![CDATA[pdf split tutorial java]]></category>
		<category><![CDATA[pdf splitter java]]></category>
		<category><![CDATA[Split PDF file into Multiple PDF Files In Java]]></category>
		<category><![CDATA[split pdf into number of files]]></category>
		<category><![CDATA[splitting pdf files using java]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=448</guid>
		<description><![CDATA[Previously I wrote a tutorial about how to merge two or more PDF files. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using java.util.logging API To Log Records To A Filesystem Log [Example Code]</title>
		<link>http://sanjaal.com/java/2010/02/25/using-java-util-logging-api-to-log-records-to-a-filesystem-log-example-code/</link>
		<comments>http://sanjaal.com/java/2010/02/25/using-java-util-logging-api-to-log-records-to-a-filesystem-log-example-code/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 13:53:15 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Logging]]></category>
		<category><![CDATA[custom formatting of java logging]]></category>
		<category><![CDATA[different levels of java logging]]></category>
		<category><![CDATA[How to log message to a file system in java]]></category>
		<category><![CDATA[how to use java logging.logger]]></category>
		<category><![CDATA[java file logger file appending]]></category>
		<category><![CDATA[java file logger file rotating]]></category>
		<category><![CDATA[java file logger naming]]></category>
		<category><![CDATA[java logging API FileHandler tutorial]]></category>
		<category><![CDATA[java logging API use of entering ( )]]></category>
		<category><![CDATA[java logging API use of exiting ( )]]></category>
		<category><![CDATA[java logging append]]></category>
		<category><![CDATA[java logging control whether the data should be appended to the file or overwritten]]></category>
		<category><![CDATA[java logging Define maximum size of data]]></category>
		<category><![CDATA[java logging defining file size limit]]></category>
		<category><![CDATA[java logging defining max number of log files]]></category>
		<category><![CDATA[java logging framework tutorial]]></category>
		<category><![CDATA[java logging levels severe warning info config fine finer finest]]></category>
		<category><![CDATA[java logging rotating files]]></category>
		<category><![CDATA[Java Standard Logging API Tutorial]]></category>
		<category><![CDATA[Java Standard Logging Framework]]></category>
		<category><![CDATA[java.util.logger Logging API Tutorial]]></category>
		<category><![CDATA[Level.ALL]]></category>
		<category><![CDATA[Level.OFF]]></category>
		<category><![CDATA[log file pattern usage example]]></category>
		<category><![CDATA[logger.entering tutorial]]></category>
		<category><![CDATA[logger.exiting tutorial]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=429</guid>
		<description><![CDATA[The Java Logging APIs, introduced in package java.util.logging, facilitate software servicing and maintenance at customer sites by producing log reports suitable for analysis by end users, system administrators, field service engineers, and software development teams. The Logging APIs capture information such as security failures, configuration errors, performance bottlenecks, and/or bugs in the application or platform. [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Finding Java Image Pixels Information &#8211; ARGB (Alpha, Red, Green Blue)</title>
		<link>http://sanjaal.com/java/2010/02/20/finding-java-image-pixels-information-argb-alpha-red-green-blue/</link>
		<comments>http://sanjaal.com/java/2010/02/20/finding-java-image-pixels-information-argb-alpha-red-green-blue/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 22:31:57 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[JAVA - Graphics 2D]]></category>
		<category><![CDATA[find image ARGB info in java]]></category>
		<category><![CDATA[find image RGB info in java]]></category>
		<category><![CDATA[find java image pixel]]></category>
		<category><![CDATA[get image pixel in java]]></category>
		<category><![CDATA[java 2d image manipulation]]></category>
		<category><![CDATA[java 2d image pixel manipulation]]></category>
		<category><![CDATA[java 2d image tutorial]]></category>
		<category><![CDATA[java get image alpha info]]></category>
		<category><![CDATA[java get image blue color info]]></category>
		<category><![CDATA[java get image green color info]]></category>
		<category><![CDATA[java get image height]]></category>
		<category><![CDATA[java get image red color info]]></category>
		<category><![CDATA[java get image width]]></category>
		<category><![CDATA[java image ARGB info]]></category>
		<category><![CDATA[java image bit shift for pixels]]></category>
		<category><![CDATA[java image calculate pixel values]]></category>
		<category><![CDATA[java image get pixel info]]></category>
		<category><![CDATA[java image get pixel information]]></category>
		<category><![CDATA[java image individual pixel info]]></category>
		<category><![CDATA[java image pixel 32 bit integer]]></category>
		<category><![CDATA[java image pixel 4 bytes integer]]></category>
		<category><![CDATA[java image pixel bit shift]]></category>
		<category><![CDATA[java image pixel bitwise operation]]></category>
		<category><![CDATA[java image pixel calculation]]></category>
		<category><![CDATA[java image pixel color]]></category>
		<category><![CDATA[java image pixel detail]]></category>
		<category><![CDATA[java image pixel representation]]></category>
		<category><![CDATA[java image processing tutorial]]></category>
		<category><![CDATA[java image RGB info]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=423</guid>
		<description><![CDATA[In digital imaging, a pixel(or picture element) is the smallest item of information in an image. Pixels are normally arranged in a 2-dimensional grid, and are often represented using dots or squares. Each pixel is a sample of an original image, where more samples typically provide more-accurate representations of the original. The intensity of each [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sending An Email In Java Using Secured GMAIL SMTP Server [Example Code]</title>
		<link>http://sanjaal.com/java/2010/02/18/sending-an-email-in-java-using-secured-gmail-smtp-server-example-code/</link>
		<comments>http://sanjaal.com/java/2010/02/18/sending-an-email-in-java-using-secured-gmail-smtp-server-example-code/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 08:58:56 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Email]]></category>
		<category><![CDATA[add bcc using java mail]]></category>
		<category><![CDATA[add cc using java mail]]></category>
		<category><![CDATA[gmail ssl email from java]]></category>
		<category><![CDATA[how to attach files to email in java]]></category>
		<category><![CDATA[how to send email using gmail SMTP Server in java]]></category>
		<category><![CDATA[how to send email using java]]></category>
		<category><![CDATA[java activation framework mail tutorial]]></category>
		<category><![CDATA[java autheticate to gmail smtp server]]></category>
		<category><![CDATA[java email API use example]]></category>
		<category><![CDATA[java email attachment code example]]></category>
		<category><![CDATA[java email attachment example]]></category>
		<category><![CDATA[java email example]]></category>
		<category><![CDATA[java email example source code]]></category>
		<category><![CDATA[java email program]]></category>
		<category><![CDATA[java email program source code]]></category>
		<category><![CDATA[java email sending example]]></category>
		<category><![CDATA[java email sending tutorial]]></category>
		<category><![CDATA[java email SMTP Host]]></category>
		<category><![CDATA[java email SMTP Host Port]]></category>
		<category><![CDATA[java email tutorial]]></category>
		<category><![CDATA[java email utility example]]></category>
		<category><![CDATA[java example code to send an email]]></category>
		<category><![CDATA[java gmail email]]></category>
		<category><![CDATA[java gmail message send example]]></category>
		<category><![CDATA[java internet address example]]></category>
		<category><![CDATA[java mail api example]]></category>
		<category><![CDATA[java mail attachment filedatasource example]]></category>
		<category><![CDATA[java send smtp email using secured gmail]]></category>
		<category><![CDATA[java sending email to a list]]></category>
		<category><![CDATA[javamail tutorial]]></category>
		<category><![CDATA[mail.smtps.quitwait]]></category>
		<category><![CDATA[send email using gmail from java]]></category>
		<category><![CDATA[send email using java]]></category>
		<category><![CDATA[send smtp mail from java]]></category>
		<category><![CDATA[sent attachments using java email]]></category>
		<category><![CDATA[set java email properties]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=415</guid>
		<description><![CDATA[The following tutorial will show how you can authenticate to secured Gmail SMTP Server using your gmail credentials and send mail using the Java Mail API.
For this tutorial, you will be requiring the following jar files:

 Mail.jar [Download from http://java.sun.com/products/javamail/]
 Activation.jar [Download from http://java.sun.com/javase/technologies/desktop/javabeans/jaf/]

In the tutorial, we will explore:

 How to authenticate to GMAIL SMTP [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>List of All Available Major MIME Types</title>
		<link>http://sanjaal.com/java/2010/02/17/list-of-all-available-major-mime-types/</link>
		<comments>http://sanjaal.com/java/2010/02/17/list-of-all-available-major-mime-types/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 20:13:57 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Extra News and Resources]]></category>
		<category><![CDATA[all available mime types]]></category>
		<category><![CDATA[comprehensive list of all major MIME Types]]></category>
		<category><![CDATA[list of all mime types]]></category>
		<category><![CDATA[Mime Type - application/EDI-X12]]></category>
		<category><![CDATA[Mime Type - application/EDIFACT]]></category>
		<category><![CDATA[Mime Type - application/javascript]]></category>
		<category><![CDATA[Mime Type - application/json]]></category>
		<category><![CDATA[Mime Type - application/msword]]></category>
		<category><![CDATA[Mime Type - application/octet-stream]]></category>
		<category><![CDATA[Mime Type - application/ogg]]></category>
		<category><![CDATA[Mime Type - application/pdf]]></category>
		<category><![CDATA[Mime Type - application/vnd.mozilla.xul+xml]]></category>
		<category><![CDATA[Mime Type - application/vnd.ms-excel]]></category>
		<category><![CDATA[Mime Type - application/vnd.ms-powerpoint]]></category>
		<category><![CDATA[Mime Type - application/vnd.oasis.opendocument.graphics]]></category>
		<category><![CDATA[Mime Type - application/vnd.oasis.opendocument.presentation]]></category>
		<category><![CDATA[Mime Type - application/vnd.oasis.opendocument.spreadsheet]]></category>
		<category><![CDATA[Mime Type - application/vnd.oasis.opendocument.text]]></category>
		<category><![CDATA[Mime Type - application/x-pkcs12]]></category>
		<category><![CDATA[Mime Type - application/x-pkcs7-certificates]]></category>
		<category><![CDATA[Mime Type - application/x-pkcs7-certreqresp]]></category>
		<category><![CDATA[Mime Type - application/x-pkcs7-mime]]></category>
		<category><![CDATA[Mime Type - application/x-pkcs7-signature]]></category>
		<category><![CDATA[Mime Type - application/x-www-form-urlencoded]]></category>
		<category><![CDATA[Mime Type - application/xhtml+xml]]></category>
		<category><![CDATA[Mime Type - application/xml-dtd]]></category>
		<category><![CDATA[Mime Type - application/zip]]></category>
		<category><![CDATA[Mime Type - audio/basic]]></category>
		<category><![CDATA[Mime Type - audio/mpeg]]></category>
		<category><![CDATA[Mime Type - audio/ogg]]></category>
		<category><![CDATA[Mime Type - audio/vnd.rn-realaudio]]></category>
		<category><![CDATA[Mime Type - audio/vorbis]]></category>
		<category><![CDATA[Mime Type - audio/x-ms-wma]]></category>
		<category><![CDATA[Mime Type - audio/x-wav]]></category>
		<category><![CDATA[Mime Type - image/gif]]></category>
		<category><![CDATA[Mime Type - image/jpeg]]></category>
		<category><![CDATA[Mime Type - image/png]]></category>
		<category><![CDATA[Mime Type - image/svg+xml]]></category>
		<category><![CDATA[Mime Type - image/tiff]]></category>
		<category><![CDATA[Mime Type - image/vnd.microsoft.icon]]></category>
		<category><![CDATA[Mime Type - multipart/alternative]]></category>
		<category><![CDATA[Mime Type - multipart/encrypted]]></category>
		<category><![CDATA[Mime Type - multipart/form-data]]></category>
		<category><![CDATA[Mime Type - multipart/mixed]]></category>
		<category><![CDATA[Mime Type - multipart/related]]></category>
		<category><![CDATA[Mime Type - multipart/signed]]></category>
		<category><![CDATA[Mime Type - text/css]]></category>
		<category><![CDATA[Mime Type - text/csv]]></category>
		<category><![CDATA[Mime Type - text/html]]></category>
		<category><![CDATA[Mime Type - text/javascript (Obsolete)]]></category>
		<category><![CDATA[Mime Type - text/plain]]></category>
		<category><![CDATA[Mime Type - text/xml]]></category>
		<category><![CDATA[Mime Type - video/mp4]]></category>
		<category><![CDATA[Mime Type - video/mpeg]]></category>
		<category><![CDATA[Mime Type - video/ogg]]></category>
		<category><![CDATA[Mime Type - video/quicktime]]></category>
		<category><![CDATA[Mime Type - video/x-ms-wmv]]></category>
		<category><![CDATA[mime type list]]></category>
		<category><![CDATA[mime types list]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=413</guid>
		<description><![CDATA[Multipurpose Internet Mail Extensions (MIME) is an Internet standard that extends the format of e-mail to support:

 Text in character sets other than ASCII
 Non-text attachments
 Message bodies with multiple parts
 Header information in non-ASCII character sets

The following is a comprehensive list of all major MIME Types available as of now.



MIME Type
MIME Description
MIME Category


text/css
Cascading Style [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running External Programs /Commands Using Java Runtime</title>
		<link>http://sanjaal.com/java/2010/02/12/running-external-programs-commands-using-java-runtime/</link>
		<comments>http://sanjaal.com/java/2010/02/12/running-external-programs-commands-using-java-runtime/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 10:00:29 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java - External Commands]]></category>
		<category><![CDATA[execute external command java]]></category>
		<category><![CDATA[invoking external application from java]]></category>
		<category><![CDATA[java exec command tutorial]]></category>
		<category><![CDATA[java external command call]]></category>
		<category><![CDATA[java external runtime Process]]></category>
		<category><![CDATA[java runtime]]></category>
		<category><![CDATA[java runtime example]]></category>
		<category><![CDATA[java runtime sample code]]></category>
		<category><![CDATA[java runtime tutorial]]></category>
		<category><![CDATA[run external application from java]]></category>
		<category><![CDATA[run external commands from java]]></category>
		<category><![CDATA[run operating system command from java]]></category>
		<category><![CDATA[run OS command from java]]></category>
		<category><![CDATA[run shell command from java tutorial]]></category>
		<category><![CDATA[Runtime.exec method example]]></category>
		<category><![CDATA[start external application from java]]></category>
		<category><![CDATA[use java to invoke external applications]]></category>
		<category><![CDATA[use java to invoke external commands]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=408</guid>
		<description><![CDATA[Java Programming language allows the java application to access the operating system runtime and execute commands and get the results back. For instance, you can open a notepad application from the Java code. All you need to know is the location of the external application to run.
For example, if you want to start notepad, the [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Calculating Age In Java From Birth Date</title>
		<link>http://sanjaal.com/java/2010/02/11/calculating-age-in-java-from-birth-date/</link>
		<comments>http://sanjaal.com/java/2010/02/11/calculating-age-in-java-from-birth-date/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 09:32:14 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java - Date Time Calendar]]></category>
		<category><![CDATA[age calculation in java]]></category>
		<category><![CDATA[calcuate age in java]]></category>
		<category><![CDATA[Calculating age]]></category>
		<category><![CDATA[compute age in java]]></category>
		<category><![CDATA[correct age calculation in java]]></category>
		<category><![CDATA[find age in java]]></category>
		<category><![CDATA[java age calculation]]></category>
		<category><![CDATA[java age calculation algorithm]]></category>
		<category><![CDATA[java age calculation example]]></category>
		<category><![CDATA[java age calculation formula]]></category>
		<category><![CDATA[java age calculation from date of birth]]></category>
		<category><![CDATA[java age calculation tutorial]]></category>
		<category><![CDATA[java age calculator]]></category>
		<category><![CDATA[java age computation]]></category>
		<category><![CDATA[java age difference]]></category>
		<category><![CDATA[java age in years]]></category>
		<category><![CDATA[java date examples]]></category>
		<category><![CDATA[Java Date Manipulation]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=404</guid>
		<description><![CDATA[Playing around with dates is tricky and can sometimes make you use your head, specially with the boundary conditions. In this tutorial, I am presenting a code that can take any birth date as the input and then calculates what is his / her age now.
Here is the algorithm:

 Subtract birth year from current year.
 [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Rotating An Image In Java Graphics 2D By Specified Degree</title>
		<link>http://sanjaal.com/java/2010/02/10/rotating-an-image-in-java-graphics-2d-by-specified-degree/</link>
		<comments>http://sanjaal.com/java/2010/02/10/rotating-an-image-in-java-graphics-2d-by-specified-degree/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 08:53:40 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[JAVA - Graphics 2D]]></category>
		<category><![CDATA[Graphics 2D example image rotation]]></category>
		<category><![CDATA[How To Rotate Image In Java]]></category>
		<category><![CDATA[image rotate java. java image rotate script]]></category>
		<category><![CDATA[Image Rotation In Java]]></category>
		<category><![CDATA[Java BufferedImage rotation]]></category>
		<category><![CDATA[Java Example Code Rotate Image]]></category>
		<category><![CDATA[Java Graphics 2D Image Rotation]]></category>
		<category><![CDATA[Java Image Rotation]]></category>
		<category><![CDATA[java image rotation snippet]]></category>
		<category><![CDATA[Java Tutorial To Rotate Images]]></category>
		<category><![CDATA[Picture Rotation In Java]]></category>
		<category><![CDATA[Rotate Image In Degrees Using Java]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=401</guid>
		<description><![CDATA[The following java example will read an input image from the file system, and then it will rotate the image with the angle in degrees provided in the parameter while calling rotateMyImage method from the main method. It will then save the rotated image back to the file system as a new image file.


package com.kushal.graphics;
/**
 [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cropping An Image In Java [Sample/Tutorial With Source Code]</title>
		<link>http://sanjaal.com/java/2010/02/06/cropping-an-image-in-java-sampletutorial-with-source-code/</link>
		<comments>http://sanjaal.com/java/2010/02/06/cropping-an-image-in-java-sampletutorial-with-source-code/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 16:54:23 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Java Graphics]]></category>
		<category><![CDATA[clipped image java]]></category>
		<category><![CDATA[clipped photos java]]></category>
		<category><![CDATA[cropped image java]]></category>
		<category><![CDATA[cropped photos java]]></category>
		<category><![CDATA[cut image in java]]></category>
		<category><![CDATA[java image clipper]]></category>
		<category><![CDATA[java image crop example]]></category>
		<category><![CDATA[java image crop tutorial]]></category>
		<category><![CDATA[java image cropper]]></category>
		<category><![CDATA[java image cropping]]></category>
		<category><![CDATA[java image cropping co-ordinates]]></category>
		<category><![CDATA[java image cropping rectangle]]></category>
		<category><![CDATA[java image cutter]]></category>
		<category><![CDATA[java image processing example]]></category>
		<category><![CDATA[java image processing image crop]]></category>
		<category><![CDATA[java image processing tutorial]]></category>
		<category><![CDATA[java photo clipper]]></category>
		<category><![CDATA[java photo crop example]]></category>
		<category><![CDATA[java photo crop tutorial]]></category>
		<category><![CDATA[java program to clip images]]></category>
		<category><![CDATA[java program to crop images]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=395</guid>
		<description><![CDATA[Cropping refers to the removal of the outer parts of an image to improve framing, accentuate subject matter or change aspect ratio. Depending on the application, this may be performed on a physical photograph, artwork or film footage, or achieved digitally using image editing software. The term is common to the film, broadcasting, photographic, graphic [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Calculating Folder Size Graphically and Generating Directory Size Chart In Java</title>
		<link>http://sanjaal.com/java/2010/02/05/calculating-folder-size-graphically-and-generating-directory-size-chart-in-java/</link>
		<comments>http://sanjaal.com/java/2010/02/05/calculating-folder-size-graphically-and-generating-directory-size-chart-in-java/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 16:19:51 +0000</pubDate>
		<dc:creator>Kushal Paudyal</dc:creator>
				<category><![CDATA[Charts In Java]]></category>
		<category><![CDATA[Java File]]></category>
		<category><![CDATA[Create Graph Of Folder Sizes]]></category>
		<category><![CDATA[find size occupied by a folder in java with graphs]]></category>
		<category><![CDATA[Folder Graph Java]]></category>
		<category><![CDATA[java directory size compare graphical]]></category>
		<category><![CDATA[java folder size graphical]]></category>
		<category><![CDATA[jfree chart folder graph]]></category>
		<category><![CDATA[Rescursively find out folder sizes]]></category>
		<category><![CDATA[total file sizes taken by a folder]]></category>

		<guid isPermaLink="false">http://sanjaal.com/java/?p=391</guid>
		<description><![CDATA[Why I Wrote this Program?
I had a large collection of my personal pictures and videos on many folders on my laptop. I wanted to know which folder is taking lots of spaces. In fact I wanted to compare the total sizes taken by those folders.
What this program does?
This program recurses through a folder, finds the [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p style="text-align: justify;">Previously I wrote a <a href="http://sanjaal.com/java/2009/10/06/merging-two-or-more-pdfs-using-lowagie-itext-api/">tutorial about how to merge two or more PDF files</a>. This tutorial will do the opposite. I will present how to split a PDF with multiple pages into multiple PDFs using the Java iText API from Lowagie. You will be requiring the iText API to run this program and you can download it from <a href="http://www.lowagie.com/iText/">www.lowagie.com/iText/</a></p>
<p style="text-align: justify;">This program will take two parameters as input which are defined inside the main method.</p>
<ul style="text-align: justify;">
<li>First parameter is the full path of PDF file that needs to be split.</li>
<li>Second parameter is the number of pages the each split should have.</li>
</ul>
<p style="text-align: justify;">For example, if you have a PDF of 15 pages, you might want to split into 4 pages each. There will be total 4 splits. First three splits will have 4 pages each, while the last split will have 3 pages (4+4+4+3=15).</p>
<p style="text-align: justify;">Just summarizing what can be learned from the following program:</p>
<ul style="text-align: justify;">
<li>1. Using iText API to read PDF file</li>
<li>2. How to find total number of pages in the PDF</li>
<li>3. How to Use PdfCopy and PDFImportedPage features</li>
<li>4. PDF Splitting Logic</li>
<li>5. How to trigger the PDF file writing using PdfCopy</li>
</ul>
<p style="text-align: justify;"><strong>Fully Compiled and Tested Source Code:</strong><br />
<!--INFOLINKS_OFF--></p>
<pre class="brush: java;">
package com.kushal.pdf;

/**
 * @Author Kushal Paudyal
 * www.sanjaal.com/java
 * Last Modified On: 2009-11-04
 *
 * PDFSplitter.java
 * Split any PDF file into multiple PDFs
 */
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;

public class PDFSplitter {

	public static void main(String[] args) {

		/**
		 * Location of input file which is to be splitted.
		 */
		String fileToSplit = &quot;C:/temp/general/MyWebReport.pdf&quot;;

		/**
		 * Page Size of each splitted files
		 *
		 * e.g. 4 pages each in the split.
		 */
		int splittedPageSize = 4;

		/**Call the split method with filename and page size as params**/
		splitPDFFile(fileToSplit, splittedPageSize);

	}

	/**
	 * @param fileName : PDF file that has to be splitted
	 * @param splittedPageSize : Page size of each splitted files
	 */
	public static void splitPDFFile(String fileName, int splittedPageSize) {
		try {
			/**
			 * Read the input PDF file
			 */
			PdfReader reader = new PdfReader(fileName);
			System.out.println(&quot;Successfully read input file: &quot; + fileName
					+ &quot;\n&quot;);
			int totalPages = reader.getNumberOfPages();
			System.out.println(&quot;There are total &quot; + totalPages
					+ &quot; pages in this input file\n&quot;);
			int split = 0;

			/**
			 * Note: Page numbers start from 1 to n (not 0 to n-1)
			 */
			for (int pageNum = 1; pageNum &lt;= totalPages; pageNum += splittedPageSize) {
				split++;
				String outFile = fileName
						.substring(0, fileName.indexOf(&quot;.pdf&quot;))
						+ &quot;-split-&quot; + split + &quot;.pdf&quot;;
				Document document = new Document(reader
						.getPageSizeWithRotation(1));
				PdfCopy writer = new PdfCopy(document, new FileOutputStream(
						outFile));
				document.open();
				/**
				 * Each split might contain one or more pages defined by splittedPageSize
				 *
				 * E.g. We are splitting a 15 pages pdf to 4 page each.
				 * In this example, the last split will have only 3 pages (4+4+4+3 =15)
				 *
				 * Note the following condition that handles the scenario where total
				 * number of pages in the splitted file is less that splittedpageSize
				 *
				 * It will always be the last split.
				 *
				 * splittedPageSize &amp;&amp; (pageNum+offset) &lt;=totalPages
				 */
				int tempPageCount = 0;
				for (int offset = 0; offset &lt; splittedPageSize
						&amp;&amp; (pageNum + offset) &lt;= totalPages; offset++) {
					PdfImportedPage page = writer.getImportedPage(reader,
							pageNum + offset);
					writer.addPage(page);
					tempPageCount++;
				}

				document.close();
				/**The following will trigger the PDF file being written to the system**/
				writer.close();

				System.out.println(&quot;Split: [&quot; + tempPageCount + &quot; page]: &quot;
						+ outFile);

			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
/*
	 * SANJAAL CORPS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
	 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
	 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
	 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SANJAAL CORPS SHALL NOT BE LIABLE FOR
	 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
	 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
	 *
	 * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
	 * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
	 * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
	 * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
	 * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
	 * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
	 * PHYSICAL OR ENVIRONMENTAL DAMAGE (&quot;HIGH RISK ACTIVITIES&quot;). SANJAAL CORPS
	 * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
	 * HIGH RISK ACTIVITIES.
	 */
}
</pre>
<p><!--INFOLINKS_ON--><strong>Output of this program:</strong></p>
<pre class="brush: plain;">
Successfully read input file: C:/temp/general/MyWebReport.pdf

There are total 15 pages in this input file

Split: [4 page]: C:/temp/general/MyWebReport-split-1.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-2.pdf
Split: [4 page]: C:/temp/general/MyWebReport-split-3.pdf
Split: [3 page]: C:/temp/general/MyWebReport-split-4.pdf
</pre>
<p><strong>Original And Splitted PDFs In File Explorer:</strong></p>
<p><a href="http://sanjaal.com/imagehost/share-D90B_4AF323CE.html"><img src="http://sanjaal.com/imagehost/image-D90B_4AF323CE.jpg" border="0" alt="" width="596" height="421" /></a>
<div id="apf_post_footer">
<h4>Related Tutorials</h4>
<ul>
<li class="apf_footer"><a href="http://sanjaal.com/java/?p=384">Merging Two Or More PDFs Using Lowagie iText API</a></li>
</ul>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-5662670263255460";
/* 728x90, created 8/30/08 Sanjaal Java [ Comments Section] */
google_ad_slot = "4248240035";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
<font size="-2" color = "green"><br />
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing &#8211; our website does not ask for your credit card and banking information. Happy Surfing!<br />
</font></p>
<!--INFOLINKS_OFF--><p id="bte_opp"><small>Originally posted 2009-11-05 12:15:22. </small></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsanjaal.com%2Fjava%2F2010%2F03%2F06%2Fsplitting-pdf-file-using-java-itext-api-into-multiple-pdfs%2F&amp;linkname=Splitting%20PDF%20File%20Using%20Java%20iText%20API%20Into%20Multiple%20PDFs"><img src="http://sanjaal.com/java/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://sanjaal.com/java/2010/03/06/splitting-pdf-file-using-java-itext-api-into-multiple-pdfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
