You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Fabien WALD <fa...@uhb.fr> on 2016/03/07 13:41:19 UTC

Divide, find and rename PDF file / Diviser, rechercher et renommer fichier PDF

Hello,

I have a PDF file of several hundred pages.
This file contains the results of examinations of several students.

I would like to create a single file for each student.

My need is:

1) Read the PDF file and divide whenever he finds the word "No duplicate 
will be provided."
Indeed, it is this phrase that serves as a separator between each student.

2) Rename PDF files by this number in the file (can be easily extracted 
because it is always surrounded by the same word "Student" and "INE")

Do you have a quick solution to offer me? Ideally command line?

Thank you in advance.

Cordially.

A French User :-)

----

Bonjour,

J'ai un fichier PDF de plusieurs centaines de pages.
Ce fichier contient les résultats d'examens de plusieurs étudiants.

J'aimerai créer un fichier unique pour chaque étudiant.

Mon besoin est donc :

1) Lire le fichier PDF et le diviser à chaque fois qu'il trouve le mot 
"Aucun duplicata ne sera fourni".
En effet, c'est cette phrase qui sert de séparateur entre chaque étudiant.

2) Renommer les fichiers PDF par un Numéro présent dans le fichier (on 
peut extraire facilement car il est toujours entouré des mêmes mots 
"Etudiant" et "INE")

Avez vous une solution rapide à me proposer ? Idéalement en ligne de 
commande ?

Merci d'avance.

Cordialement.

-- 
<http://www.univ-rennes2.fr>Fabien Wald
Domaine Formation Insertion Recherche
Direction du Système d'Information
Tel: 02.99.14.13.59 - Fax: 02.99.14.13.50

Re: Divide, find and rename PDF file / Diviser, rechercher et renommer fichier PDF

Posted by Tilman Hausherr <TH...@t-online.de>.
I won't write the software for you, and there's no command line utility, 
but here are a few hints:

- use 2.0, not 1.8
- open a document: PDDocument doc = PDDocument.load(new File());
- PDFTextStripper to extract text from a page

                 pdfTextStripper.setStartPage(page);
                 pdfTextStripper.setEndPage(page);
                 String pageText = pdfTextStripper.getText(document);

- new PDDocument() to create an empty document
- PDDocument.importPage(page) to import a page from an existing document 
to a new one
- save() to save
- don't forget to close your small documents
- regular expression for the number

             final Pattern p = Pattern.compile(".*Student(\\d+)INE.*");
             Matcher m = p.matcher(pageText);
             if (m.find())
                 num = m.group(1);

- have logic for documents that have several pages (i.e. if number is 
the same, or if no number)
- note that setStartPage() is 1-based, but document.getPage() is 0-based
- don't forget to save the last document after your loop has ended
- count the sum of all pages of the docs you save and compare it with 
the original document to be safe

Obviously you can't share the PDF. If you want to share the code you 
write, I'll try to help you if you encounter any problems. The amount of 
work is less than a day.

Bonne chance!

Tilman



Am 07.03.2016 um 13:41 schrieb Fabien WALD:
> Hello,
>
> I have a PDF file of several hundred pages.
> This file contains the results of examinations of several students.
>
> I would like to create a single file for each student.
>
> My need is:
>
> 1) Read the PDF file and divide whenever he finds the word "No 
> duplicate will be provided."
> Indeed, it is this phrase that serves as a separator between each student.
>
> 2) Rename PDF files by this number in the file (can be easily 
> extracted because it is always surrounded by the same word "Student" 
> and "INE")
>
> Do you have a quick solution to offer me? Ideally command line?
>
> Thank you in advance.
>
> Cordially.
>
> A French User :-)
>
> ----
>
> Bonjour,
>
> J'ai un fichier PDF de plusieurs centaines de pages.
> Ce fichier contient les résultats d'examens de plusieurs étudiants.
>
> J'aimerai créer un fichier unique pour chaque étudiant.
>
> Mon besoin est donc :
>
> 1) Lire le fichier PDF et le diviser à chaque fois qu'il trouve le mot 
> "Aucun duplicata ne sera fourni".
> En effet, c'est cette phrase qui sert de séparateur entre chaque étudiant.
>
> 2) Renommer les fichiers PDF par un Numéro présent dans le fichier (on 
> peut extraire facilement car il est toujours entouré des mêmes mots 
> "Etudiant" et "INE")
>
> Avez vous une solution rapide à me proposer ? Idéalement en ligne de 
> commande ?
>
> Merci d'avance.
>
> Cordialement.
>
> -- 
> <http://www.univ-rennes2.fr>Fabien Wald
> Domaine Formation Insertion Recherche
> Direction du Système d'Information
> Tel: 02.99.14.13.59 - Fax: 02.99.14.13.50