|
|
@@ -19,11 +19,12 @@ public class PdfUtils {
|
|
|
/**
|
|
|
* @Param:
|
|
|
* inFile 需要拆分的Pdf文件
|
|
|
+ * outName 需要输出文件模板名称
|
|
|
* @return: 输出拆分的文件名称
|
|
|
* @Author: guq
|
|
|
* @Date: 2018/9/21
|
|
|
*/
|
|
|
- public static String[] splitByPage(String inFile) {
|
|
|
+ public static String[] splitByPage(String inFile, String outName) {
|
|
|
File file = new File(inFile);
|
|
|
String[] ourFiles = null;
|
|
|
if (!file.exists() && !file.isFile())
|
|
|
@@ -34,8 +35,9 @@ public class PdfUtils {
|
|
|
ourFiles = new String[n];
|
|
|
int i = 0;
|
|
|
while ( i < n ) {
|
|
|
- String outFile = inFile.substring(0, inFile.indexOf(".pdf"))
|
|
|
- + "_" + String.format("%0" + n.toString().length() + "d", i + 1) + ".pdf";
|
|
|
+ String path = inFile.substring(0, inFile.lastIndexOf(File.separator) + 1);
|
|
|
+ String outFile = path + outName + "_"
|
|
|
+ + String.format("%0" + n.toString().length() + "d", i + 1) + ".pdf";
|
|
|
ourFiles[i] = outFile;
|
|
|
Document document = new Document(reader.getPageSizeWithRotation(1));
|
|
|
PdfCopy writer = new PdfCopy(document, new FileOutputStream(outFile));
|