使用java代码对pdf进行切割
起因,pdf下载的太大了,无法上传有道云笔记,切割成上下两部分
代码
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfImportedPage;
i服务器托管网mport com.lowagie.text.pdf.PdfReader;
public class PDF {
publ服务器托管网ic static void main(String[] args) {
partitionPdfFile("D:/Java 8编程官方参考教程(第9版).pdf","D:/Java 8编程官方参考教程(第9版).pdf)下.pdf", 700,1281);
}
/**
* 截取pdfFile的第from页至第end页,组成一个新的文件名
* @param pdfFile
* @param subfileName
* @param from
* @param end
*/
public static void partitionPdfFile(String pdfFile,
String newFile, int from, int end) {
Document document = null;
PdfCopy copy = null;
try {
PdfReader reader = new PdfReader(pdfFile);
int n = reader.getNumberOfPages();
if(end==0){
end = n;
}
ArrayListString> savepaths = new ArrayListString>();
String staticpath = pdfFile.substring(0, pdfFile.lastIndexOf("")+1);
String savepath = staticpath+ newFile;
savepaths.add(savepath);
document = new Document(reader.getPageSize(1));
copy = new PdfCopy(document, new FileOutputStream(savepaths.get(0)));
document.open();
for(int j=from; jend; j++) {
document.newPage();
PdfImportedPage page = copy.getImportedPage(reader, j);
copy.addPage(page);
}
document.close();
} catch (IOException e) {
e.printStackTrace();
} catch(DocumentException e) {
e.printStackTrace();
}
}
}
所需jar包
bcprov-jdk15-141.jar
iText-2.1.4.jar
itext-2.0.2.jar
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
摘 要 穷游网酒店数据采集与可视化分析大屏的背景是为了满足用户对酒店数据的需求以及提供数据洞察和决策支持。随着旅游业的快速发展,人们对酒店信息的需求日益增加,而穷游网作为一家专注于旅游信息的网站,拥有丰富的酒店数据资源。 这个大屏的目的是通过数据采集和可视化分…