I need to extract 10 first pages of around 100 PDF files. As you know, Adobe Acrobat DC doesn't allow doing so at once, and I have to extract 10 pages for each file separately. I wrote the following little code that performs such a task
SetDirectory[NotebookDirectory[]];
all = FileNames[];
npage = 10;
Do[
Clear[orgPDF, newPDF, vname, name, newname];
SetDirectory[NotebookDirectory[]];
orgPDF = Import[all[[i]], "PDF"];
newPDF =
CreateDocument[orgPDF[[1 ;; npage]], PageBreakBelow -> True,
Visible -> False];
SetDirectory["exPDFfolder"];
vname = all[[i]];
name = StringSplit[vname, "."][[1]];
newname = StringTemplate["new_`1`.pdf"][name];
Export[newname, newPDF, "AllowRasterization" -> True]
, {i, Length[all] - 2}]
Where all PDF files are placed in a same folder and I set loop number to Length[all] - 2
because of excluding the nb
file and also exPDFfolder
folder.
The only problem with this code is that exported/extracted PDF files include pages with lower quality and also very high margins, which doesn't look good. I think the way of importing PDF file (like graphic, not text) leads to the problem.
How can I extract the first 10 pages as the same of original PDF file?
Addendum:
Unlike the comments say this is not the best way, I think it's a good idea to take advantage of Mathemtica features which are not available easily in appropriate software programs. In this case, Acrobat DC (the most powerful tool for manipulating PDF files) doesn't have a bulk extraction feature (although it has such a feature for watermarking for example).
To see what happens, I put here one of my original and extracted files
Import["article.pdf", {"PageGraphics", 10}]
? The document says"PageGraphics"
is vector-like comparing with"PageImages".
$\endgroup$