Java 按顺序读取多个PDF文件
我将PDF文件拆分为多个PDF文件,然后尝试从文件夹中读取多个PDF文件并打印文件名Java 按顺序读取多个PDF文件,java,multithreading,pdf,import,pdfbox,Java,Multithreading,Pdf,Import,Pdfbox,我将PDF文件拆分为多个PDF文件,然后尝试从文件夹中读取多个PDF文件并打印文件名 int l=1; File file = new File(userInputFile); try (PDDocument document = PDDocument.load(file)) { Splitter splitter = new Splitter(); List<PDDocument> Pages = splitter.split(document); Ite
int l=1;
File file = new File(userInputFile);
try (PDDocument document = PDDocument.load(file)) {
Splitter splitter = new Splitter();
List<PDDocument> Pages = splitter.split(document);
Iterator<PDDocument> iterator = Pages.listIterator();
while (iterator.hasNext()) {
PDDocument pd = iterator.next();
pd.save("C:\\Users\\Public\\Documents\\FolderForCheckListTest_000\\"+"Page "+l++);
}
document.close();
}
你知道怎么修吗?
提前感谢:)正在对字符串进行默认排序,因此10将位于1之后,后面紧跟2,以此类推
实现自定义排序()并在文件名集合列表()上使用,并适当处理排序,即将结束数字视为数字。正在对字符串进行默认排序,因此10将位于1之后,然后是2等
实现自定义排序()并在文件名列表集合()上使用,并适当处理排序,即将结尾数字视为数字。要创建固定的文件名长度,请更改此选项
pd.save("C:\\Users\\Public\\Documents\\FolderForCheckListTest_000\\"+"Page "+l++);
对此
pd.save("C:\\Users\\Public\\Documents\\FolderForCheckListTest_000\\"+"Page "+String.format("%02d",l++));
(为了清楚起见,我建议将“+”放在外面,但那是另一回事)要创建固定的文件名长度,请更改此选项
pd.save("C:\\Users\\Public\\Documents\\FolderForCheckListTest_000\\"+"Page "+l++);
对此
pd.save("C:\\Users\\Public\\Documents\\FolderForCheckListTest_000\\"+"Page "+String.format("%02d",l++));
(为了清楚起见,我建议将“+”放在外面,但那是另一回事)或使用
String.format(“%02d”,l)
而不是l
@Tilman Hausherr将文件命名为“01”、“02”您的意思是这样的吗<代码>pd.save(“C:\\Users\\Public\\Documents\\FolderForCheckListTest\u 000\\”+字符串.format(“%02d”,l))代码>?或使用String.format(“%02d”,l)
而不是l
@Tilman Hausherr将文件命名为“01”、“02”您的意思是这样的吗<代码>pd.save(“C:\\Users\\Public\\Documents\\FolderForCheckListTest\u 000\\”+字符串.format(“%02d”,l))代码>?