You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2015/02/17 20:59:39 UTC
svn commit: r1660482 -
/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/PDFSplit.java
Author: tilman
Date: Tue Feb 17 19:59:38 2015
New Revision: 1660482
URL: http://svn.apache.org/r1660482
Log:
PDFBOX-2673: Add output path prefix param, as suggested by Arsen Borovinskiy
Modified:
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/PDFSplit.java
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/PDFSplit.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/PDFSplit.java?rev=1660482&r1=1660481&r2=1660482&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/PDFSplit.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/PDFSplit.java Tue Feb 17 19:59:38 2015
@@ -44,6 +44,7 @@ public class PDFSplit
private static final String START_PAGE = "-startPage";
private static final String END_PAGE = "-endPage";
private static final String NONSEQ = "-nonSeq";
+ private static final String OUTPUT_PREFIX = "-outputPrefix";
private PDFSplit()
{
@@ -70,6 +71,7 @@ public class PDFSplit
boolean useNonSeqParser = false;
Splitter splitter = new Splitter();
String pdfFile = null;
+ String outputPrefix = null;
for( int i=0; i<args.length; i++ )
{
if( args[i].equals( PASSWORD ) )
@@ -108,6 +110,11 @@ public class PDFSplit
}
endPage = args[i];
}
+ else if( args[i].equals( OUTPUT_PREFIX ) )
+ {
+ i++;
+ outputPrefix = args[i];
+ }
else if( args[i].equals( NONSEQ ) )
{
useNonSeqParser = true;
@@ -126,7 +133,11 @@ public class PDFSplit
usage();
}
else
- {
+ {
+ if (outputPrefix == null)
+ {
+ outputPrefix = pdfFile.substring(0, pdfFile.lastIndexOf('.'));
+ }
PDDocument document = null;
List<PDDocument> documents = null;
try
@@ -180,7 +191,7 @@ public class PDFSplit
for( int i=0; i<documents.size(); i++ )
{
PDDocument doc = documents.get( i );
- String fileName = pdfFile.substring(0, pdfFile.length()-4 ) + "-" + i + ".pdf";
+ String fileName = outputPrefix + "-" + i + ".pdf";
writeDocument( doc, fileName );
doc.close();
}
@@ -201,7 +212,7 @@ public class PDFSplit
}
}
- private static final void writeDocument( PDDocument doc, String fileName ) throws IOException, COSVisitorException
+ private static void writeDocument( PDDocument doc, String fileName ) throws IOException, COSVisitorException
{
FileOutputStream output = null;
COSWriter writer = null;
@@ -235,8 +246,9 @@ public class PDFSplit
" -startPage <integer> start page\n" +
" -endPage <integer> end page\n" +
" -nonSeq Enables the new non-sequential parser\n" +
+ " -outputPrefix <output prefix> Filename prefix for image files\n" +
" <PDF file> The PDF document to use\n"
);
System.exit( 1 );
}
-}
+}
\ No newline at end of file