You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by Manuel Corini <ma...@gmail.com> on 2016/07/16 08:53:05 UTC
Problem to split PDF files
Hello PDFbox,
I'm Manuel, nice to meet you.
I'm using pdfbox-app-2.0.2.jar api; I would like to slpit a Pdf document, I
have some problems: How I can to set the path file, for to load the file
Pdf for split ?
I think that the problemis here:
document = PDDocument.load(new File("C:\\Users\\Desktop\\EmailTest.pdf"));
because the standard use is:
document = PDDocument.load(new File(filename));
How I can change filename for to set the file path ?
This is my code:
public static void main(String[] args) throws IOException {
PDDocument document;
document = PDDocument.load(new
File("C:\\Users\\Desktop\\EmailTest.pdf"));
Splitter splitter = new Splitter();
List<PDDocument> listOfSplitPages;
listOfSplitPages = splitter.split(document);
Iterator<PDDocument> iterator = listOfSplitPages.listIterator();
// I am using variable i to denote page numbers.
int i = 1;
while(iterator.hasNext()){
PDDocument pd = iterator.next();
// Saving each page with its assumed page no.
pd.save("C:\\Users\\Desktop " + i++ + ".pdf");
}
}
}
Re: Problem to split PDF files
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 16.07.2016 um 10:53 schrieb Manuel Corini:
> Hello PDFbox,
>
> I'm Manuel, nice to meet you.
> I'm using pdfbox-app-2.0.2.jar api; I would like to slpit a Pdf document, I
> have some problems: How I can to set the path file, for to load the file
> Pdf for split ?
>
> I think that the problemis here:
> document = PDDocument.load(new File("C:\\Users\\Desktop\\EmailTest.pdf"));
> because the standard use is:
> document = PDDocument.load(new File(filename));
> How I can change filename for to set the file path ?
You assign the path to the variable "filename".
>
>
> This is my code:
>
> public static void main(String[] args) throws IOException {
>
> PDDocument document;
> document = PDDocument.load(new
> File("C:\\Users\\Desktop\\EmailTest.pdf"));
> Splitter splitter = new Splitter();
> List<PDDocument> listOfSplitPages;
> listOfSplitPages = splitter.split(document);
> Iterator<PDDocument> iterator = listOfSplitPages.listIterator();
>
> // I am using variable i to denote page numbers.
> int i = 1;
> while(iterator.hasNext()){
> PDDocument pd = iterator.next();
> // Saving each page with its assumed page no.
> pd.save("C:\\Users\\Desktop " + i++ + ".pdf");
> }
That one will create files that are named
c:\users\desktop 1.pdf
c:\users\desktop 2.pdf
c:\users\desktop 3.pdf
i.e. the "\\" is missing after the p.
Note that 2.0.2 has a problem with splitting, the files will be too big.
If you're splitting more than one page, use 2.0.1 or 2.0.3 (when it
comes out, i.e. in a few months / weeks)
Tilman
PS "dev" is for developers of PDFBox. You want to post to "users". What
made you think that "dev" is the correct list? I'm asking because I
wonder whether this is a documentation problem that we don't know about yet.
> }
> }
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org