pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Lehmkuehler <andr...@lehmi.de>
Subject Re: What is different from the input pdf file and output pdf file?
Date Tue, 24 Sep 2013 15:59:51 GMT
Hi,

Am 24.09.2013 08:04, schrieb 学而时习之:
> package copyfile;
>
>
> import java.text.SimpleDateFormat;
> import java.util.List;
> import org.apache.pdfbox.pdfparser.PDFStreamParser;
> import org.apache.pdfbox.pdfwriter.ContentStreamWriter;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
> import org.apache.pdfbox.pdmodel.PDPage;
> import org.apache.pdfbox.pdmodel.common.PDStream;
>
>
> public class cpfile {
> 	static String inputfile = "d:/pdf分析/7.pdf";
> 	static String outputfile = inputfile.replace(".pdf", "cp.pdf");
>
>
> 	public static void main(String[] args) {
> 		dealone(inputfile);
> 	}
>
>
> 	private static void dealone(String f) {
> 		PDDocument document = null;
> 		try {
> 			document = PDDocument.load(f);
> 			PDDocumentCatalog catalog = document.getDocumentCatalog();
> 			List<PDPage> pages = catalog.getAllPages();
> 			for (Object pageObj : catalog.getAllPages()) {
> 				PDPage page = (PDPage) pageObj;
> 				PDFStreamParser parser = new PDFStreamParser(page.getContents());
> 				parser.parse();
> 				List tokens = parser.getTokens();
>
>
> 				PDStream newContents = new PDStream(document);
> 				ContentStreamWriter writer = new ContentStreamWriter(
> 						newContents.createOutputStream());
> 				writer.writeTokens(tokens);
> 				newContents.addCompression();
> 				page.setContents(newContents);
> 			}
> 			document.save(outputfile);
>
>
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		} finally {
> 			try {
> 				document.close();
> 			} catch (Exception e) {
> 				e.printStackTrace();
> 			}
>
>
> 		}
>
>
> 	}
> }
What are you trying to do?

BR
Andreas Lehmkühler


Mime
View raw message