Renumber pages of a PDF
I want to edit the metadata of a scanned PDF to assign custom page numbers to different pages. For example, what are now pages 1-3 I might want to call i, ii and iii, and what are pages 4-10, I want to call 1-7. I do not want to change the actual order of the pages.
Is there
A) A way to do this at all using free tools; and
B) A way to do this "in batch" (so, without having to renumber each page manually).
software-recommendation pdf
add a comment |
I want to edit the metadata of a scanned PDF to assign custom page numbers to different pages. For example, what are now pages 1-3 I might want to call i, ii and iii, and what are pages 4-10, I want to call 1-7. I do not want to change the actual order of the pages.
Is there
A) A way to do this at all using free tools; and
B) A way to do this "in batch" (so, without having to renumber each page manually).
software-recommendation pdf
1
Would you be happy with a solution based on LaTeX? It would be possible to include the PDF in an otherwise empty document and create the PDF page numbers as you like.
– Martin Scharrer
Apr 8 '11 at 23:34
I would indeed be happy with a LaTeX solution. Can you post some details below?
– MarkovCh1
Apr 9 '11 at 17:08
add a comment |
I want to edit the metadata of a scanned PDF to assign custom page numbers to different pages. For example, what are now pages 1-3 I might want to call i, ii and iii, and what are pages 4-10, I want to call 1-7. I do not want to change the actual order of the pages.
Is there
A) A way to do this at all using free tools; and
B) A way to do this "in batch" (so, without having to renumber each page manually).
software-recommendation pdf
I want to edit the metadata of a scanned PDF to assign custom page numbers to different pages. For example, what are now pages 1-3 I might want to call i, ii and iii, and what are pages 4-10, I want to call 1-7. I do not want to change the actual order of the pages.
Is there
A) A way to do this at all using free tools; and
B) A way to do this "in batch" (so, without having to renumber each page manually).
software-recommendation pdf
software-recommendation pdf
edited Apr 8 '11 at 23:05
MarkovCh1
asked Mar 26 '11 at 0:55
MarkovCh1MarkovCh1
1,35711628
1,35711628
1
Would you be happy with a solution based on LaTeX? It would be possible to include the PDF in an otherwise empty document and create the PDF page numbers as you like.
– Martin Scharrer
Apr 8 '11 at 23:34
I would indeed be happy with a LaTeX solution. Can you post some details below?
– MarkovCh1
Apr 9 '11 at 17:08
add a comment |
1
Would you be happy with a solution based on LaTeX? It would be possible to include the PDF in an otherwise empty document and create the PDF page numbers as you like.
– Martin Scharrer
Apr 8 '11 at 23:34
I would indeed be happy with a LaTeX solution. Can you post some details below?
– MarkovCh1
Apr 9 '11 at 17:08
1
1
Would you be happy with a solution based on LaTeX? It would be possible to include the PDF in an otherwise empty document and create the PDF page numbers as you like.
– Martin Scharrer
Apr 8 '11 at 23:34
Would you be happy with a solution based on LaTeX? It would be possible to include the PDF in an otherwise empty document and create the PDF page numbers as you like.
– Martin Scharrer
Apr 8 '11 at 23:34
I would indeed be happy with a LaTeX solution. Can you post some details below?
– MarkovCh1
Apr 9 '11 at 17:08
I would indeed be happy with a LaTeX solution. Can you post some details below?
– MarkovCh1
Apr 9 '11 at 17:08
add a comment |
9 Answers
9
active
oldest
votes
Here a solution based on LaTeX. It uses the pdfpages
package to include the scanned PDF (here called scan.pdf
). The PDF page labels you want can be set using the hyperref
package with the pdfpagelabels
option enabled. It uses the normal thepage
macro as a label which can be defined to lower case roman numbers. The page counter is then reset and changed back to normal numbers.
documentclass[a4paper]{article}% or use 'letterpaper'
usepackage{pdfpages}
usepackage[pdfpagelabels]{hyperref}
begin{document}
% Set lower case roman numbers (Roman would be upper case):
renewcommand{thepage}{roman{page}}
includepdf[pages=1-3]{scan.pdf}
% Back to normal (arabic) numbers:
renewcommand{thepage}{arabic{page}}
% Reset page counter to 1:
setcounter{page}{1}
includepdf[pages=4-]{scan.pdf}
end{document}
Place the above code into a file (e.g. scan_mod.tex
) and compile it with pdflatex
:
# pdflatex scan_mod
This will produce scan_mod.pdf
. However any special annotations incl. hyperlinks will disappear. This shouldn't be any problem with scanned PDFs.
If you need this more often you could write a script which accepts the number of roman numbered pages and the file name(s) as arguments and creates a tempfile with the above code where the name and numbers are variables, which is then compiled.
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
2
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
1
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
|
show 1 more comment
You can do that with a text editor.
- metadata - How to change internal page numbers in the meta data of a PDF? - Super User
As the answer says, open a PDF file with a text editor, search /Catalog
entry, and then append an entry named /PageLabels
like this:
/PageLabels << /Nums [
0 << /P (cover) >> % labels 1st page with the string "cover"
1 << /S /r >> % numbers pages 2-6 in small roman numerals
6 << /S /D >> % numbers pages 7-x in decimal arabic numerals
]
>>
Note that the page indices (physical page numbers) begin with 0
.
Of cource, you can do this automatically using scripting languages.
PDF Standards - Page Labels has detailed specification.
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
add a comment |
There's a tool called PDF Mod which is a free tool to rearrange the pages of a PDF.
It can be installed from the Ubuntu Software Centre in Ubuntu 10.10 and higher.
To install in Ubuntu 9.10 or 10.04 :
To install Add the ppa ppa:pdfmod-team/ppa
to your software sources (Here's how to do that) and install pdfmod from the software center
Adapted from : http://www.webupd8.org/2011/03/edit-pdf-documents-in-linux-with-pdf.html
Good Luck :D
4
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
add a comment |
jPDF Tweak is an Open Source graphical utility that offers page numbering (the correct term is "page labeling") and many other beginner to advanced PDF editing features. It runs on Ubuntu and other operating systems.
The Documentation page provides step-by-step instructions.
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
add a comment |
Just found a pointer that it could be possible to use ghostscript
for this, here: pdftk - Add and edit bookmarks to pdf - Unix and Linux - Stack Exchange #18600; it refers to links:
- [other] how to generate bookmarks via ghostscript/pdfwrite/pdfmark - Ubuntu Forums
- Ghostcript PDF Reference & Tips — Milan Kupcevic
However, the above deal with bookmarks - not with logical pagination. It turns out from pdfmarkReference.pdf, the needed "command" is '/Label
' (or '/PAGELABEL
') - and it further refers to PDFReference.pdf chapter 8.3.1 "Page Labels". Unfortunately, that chapter doesn't necessarrily explain how pdfmarks could be used with page labels - but this post does:
- [gs-bugs] [Bug 691889] pdfwrite with "/PAGELABEL pdfmark" operator does not work with multiple pages
The /PAGELABEL pdfmark does not have any /Page key, so one can set the
label for the ‘current’ page only (and, as a consequence, only for one
page at a time). Since you call it at the very beginning, it’s expected
to set a label for the 1st page and only for it.
Multiple /PAGELABELs for the same page: the pdfmark reference says the
last one takes effect, so the result of your 1st commandline is OK.
Note the /Page key is ignored.
How to set page labels from PostScript? I can think of 2 methods:
(A) The 100% documented way:
Issue a /PAGELABEL as part of each page.
(B) The less documented way:
...
gswin32c -sDEVICE=pdfwrite -sOutputFile=50pages.pdf -dNOPAUSE
GS>[/_objdef {pl} /type /dict /OBJ pdfmark
GS>[{pl} <</Nums [0 <</P (Page ) /S /r /St 10>> 2 <<>>]>> /PUT pdfmark
GS>[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
GS>50 { showpage } repeat
GS>quit
... and further in that thread:
As to making this work; since the original file is a PDF file, you can run each
page from the file individually. So you can set the PAGELABEL pdfmark for page
1, run page 1 from the original file, set the PAGELABEL for page 2, run page 2
from the original file and so on.
Because the label is (as SaGS) said applied to the current page, this should
correctly set the labels for each page in the output PDF file.
(caveat: I haven't actually tried this)
EDIT: just to show this - if you have this saved as pdfmarks
file:
[ /Label (-1) /PAGELABEL pdfmark
showpage
[ /Label (0) /PAGELABEL pdfmark
showpage
[ /Label (1) /PAGELABEL pdfmark
showpage
... and you call:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile.pdf pdfmarks
... then you will get three empty pages appended at the end of infile.pdf
, labeled -1, 0 and 1 :)
Well, maybe this helps sometime to get a simpler gs
script for renumbering pages :)
Cheers!
EDIT2: Got it, I think - use same gs
command as above - and below are the contents of the pdfmarks
script, which will renumber the infile.pdf, so it starts with -1, 0, 1 ... It's basically a modified example from the PDF reference (see comments for more):
% Type name (Optional) The type of PDF object that this dictionary describes; if present, must be PageLabel for a page label dictionary.
% S name (Optional) The numbering style to be used for the numeric portion of each page label:
% D Decimal arabic numerals
% R Uppercase roman numerals
% r Lowercase roman numerals
% A Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on)
% a Lowercase letters (a to z for the first 26 pages, aa to zz for the next 26, and so on)
% P text string (Optional) The label prefix for page labels in this range.
% St integer (Optional) The value of the numeric portion for the first page label in the range. Subsequent pages will be numbered sequentially from this value, which must be greater than or equal to 1. Default value: 1.
% renumber first 25 pages - push each by 10, and add prefix:
% [/_objdef {pl} /type /dict /OBJ pdfmark
% [{pl} <</Nums [0 <</P (Page ) /S /D /St 10>> 25 <<>>]>> /PUT pdfmark
% [{Catalog} <</PageLabels {pl}>> /PUT pdfmark
[/_objdef {pl} /type /dict /OBJ pdfmark
[{pl} <</Nums [ 0 << /P (-1) >> % just label -1 (no style) for pg 0;
1 << /P (0) >> % just label 0 (no style) for pg 1;
2 << /S /D /St 1 >> % decimal style, start from 1, for pg2 and on.
]>> /PUT pdfmark
[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
add a comment |
Openoffice/Libreoffice can do the trick with the pdf-import extension and a pagination Macro.
Not a perfect solution, but it works for me (apart from using PDF Mod - which I would strongly suggest).
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
add a comment |
Try pyPdf, a python library to manipulate PDF documents. Some, but not much, programming would be necessary.
You could also have a look at PDFtk, though I haven't checked if it supports changing the page number associated with individual pages. Both are available as packages in Ubuntu.
1
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
add a comment |
There is another app out there called PDFEdit - its hosted on source forge.
Source Forge Project Page - However this doesn't help because it doesn't the functionality you require
1
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
2
@Syzygy - indeed, just checked:pdfedit
can showCatalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!
– sdaau
Oct 14 '11 at 0:36
add a comment |
There is a little python script, that can do the job: https://github.com/lovasoa/pagelabels-py
In your case call:
./addpagelabels.py --delete file.pdf
./addpagelabels.py --startpage 1 --type 'roman lowercase' file.pdf
./addpagelabels.py --startpage 4 --type arabic file.pdf
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f32048%2frenumber-pages-of-a-pdf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here a solution based on LaTeX. It uses the pdfpages
package to include the scanned PDF (here called scan.pdf
). The PDF page labels you want can be set using the hyperref
package with the pdfpagelabels
option enabled. It uses the normal thepage
macro as a label which can be defined to lower case roman numbers. The page counter is then reset and changed back to normal numbers.
documentclass[a4paper]{article}% or use 'letterpaper'
usepackage{pdfpages}
usepackage[pdfpagelabels]{hyperref}
begin{document}
% Set lower case roman numbers (Roman would be upper case):
renewcommand{thepage}{roman{page}}
includepdf[pages=1-3]{scan.pdf}
% Back to normal (arabic) numbers:
renewcommand{thepage}{arabic{page}}
% Reset page counter to 1:
setcounter{page}{1}
includepdf[pages=4-]{scan.pdf}
end{document}
Place the above code into a file (e.g. scan_mod.tex
) and compile it with pdflatex
:
# pdflatex scan_mod
This will produce scan_mod.pdf
. However any special annotations incl. hyperlinks will disappear. This shouldn't be any problem with scanned PDFs.
If you need this more often you could write a script which accepts the number of roman numbered pages and the file name(s) as arguments and creates a tempfile with the above code where the name and numbers are variables, which is then compiled.
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
2
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
1
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
|
show 1 more comment
Here a solution based on LaTeX. It uses the pdfpages
package to include the scanned PDF (here called scan.pdf
). The PDF page labels you want can be set using the hyperref
package with the pdfpagelabels
option enabled. It uses the normal thepage
macro as a label which can be defined to lower case roman numbers. The page counter is then reset and changed back to normal numbers.
documentclass[a4paper]{article}% or use 'letterpaper'
usepackage{pdfpages}
usepackage[pdfpagelabels]{hyperref}
begin{document}
% Set lower case roman numbers (Roman would be upper case):
renewcommand{thepage}{roman{page}}
includepdf[pages=1-3]{scan.pdf}
% Back to normal (arabic) numbers:
renewcommand{thepage}{arabic{page}}
% Reset page counter to 1:
setcounter{page}{1}
includepdf[pages=4-]{scan.pdf}
end{document}
Place the above code into a file (e.g. scan_mod.tex
) and compile it with pdflatex
:
# pdflatex scan_mod
This will produce scan_mod.pdf
. However any special annotations incl. hyperlinks will disappear. This shouldn't be any problem with scanned PDFs.
If you need this more often you could write a script which accepts the number of roman numbered pages and the file name(s) as arguments and creates a tempfile with the above code where the name and numbers are variables, which is then compiled.
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
2
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
1
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
|
show 1 more comment
Here a solution based on LaTeX. It uses the pdfpages
package to include the scanned PDF (here called scan.pdf
). The PDF page labels you want can be set using the hyperref
package with the pdfpagelabels
option enabled. It uses the normal thepage
macro as a label which can be defined to lower case roman numbers. The page counter is then reset and changed back to normal numbers.
documentclass[a4paper]{article}% or use 'letterpaper'
usepackage{pdfpages}
usepackage[pdfpagelabels]{hyperref}
begin{document}
% Set lower case roman numbers (Roman would be upper case):
renewcommand{thepage}{roman{page}}
includepdf[pages=1-3]{scan.pdf}
% Back to normal (arabic) numbers:
renewcommand{thepage}{arabic{page}}
% Reset page counter to 1:
setcounter{page}{1}
includepdf[pages=4-]{scan.pdf}
end{document}
Place the above code into a file (e.g. scan_mod.tex
) and compile it with pdflatex
:
# pdflatex scan_mod
This will produce scan_mod.pdf
. However any special annotations incl. hyperlinks will disappear. This shouldn't be any problem with scanned PDFs.
If you need this more often you could write a script which accepts the number of roman numbered pages and the file name(s) as arguments and creates a tempfile with the above code where the name and numbers are variables, which is then compiled.
Here a solution based on LaTeX. It uses the pdfpages
package to include the scanned PDF (here called scan.pdf
). The PDF page labels you want can be set using the hyperref
package with the pdfpagelabels
option enabled. It uses the normal thepage
macro as a label which can be defined to lower case roman numbers. The page counter is then reset and changed back to normal numbers.
documentclass[a4paper]{article}% or use 'letterpaper'
usepackage{pdfpages}
usepackage[pdfpagelabels]{hyperref}
begin{document}
% Set lower case roman numbers (Roman would be upper case):
renewcommand{thepage}{roman{page}}
includepdf[pages=1-3]{scan.pdf}
% Back to normal (arabic) numbers:
renewcommand{thepage}{arabic{page}}
% Reset page counter to 1:
setcounter{page}{1}
includepdf[pages=4-]{scan.pdf}
end{document}
Place the above code into a file (e.g. scan_mod.tex
) and compile it with pdflatex
:
# pdflatex scan_mod
This will produce scan_mod.pdf
. However any special annotations incl. hyperlinks will disappear. This shouldn't be any problem with scanned PDFs.
If you need this more often you could write a script which accepts the number of roman numbered pages and the file name(s) as arguments and creates a tempfile with the above code where the name and numbers are variables, which is then compiled.
answered Apr 9 '11 at 17:36
Martin ScharrerMartin Scharrer
7901516
7901516
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
2
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
1
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
|
show 1 more comment
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
2
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
1
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Thank you for such a thorough answer! This is a great solution. The only other solutions I was aware of included either .NET or something equally horrible, or wading through dialogs in Adobe Acrobat (which I can't afford anyway). This is even scriptable!
– MarkovCh1
Apr 10 '11 at 0:24
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
Nice solution! I was wondering about the same question of batch generation of bookmarks/outlines on the left panel with hyperlinks to the beginning of each section/chapter. Is it possible to use LaTex as well? Here is my question askubuntu.com/questions/27312/bookmark-pdf-and-djvu-files . Thanks!
– Tim
Apr 15 '11 at 23:49
2
2
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
@Tim: You can create PDF bookmarks with LaTeX when combining PDFs. See my answer to How do I use LaTeX to create table of contents (chapter headings, subsections etc) for a set of pdf files which I am merging into a single large pdf? on TeX.SX.
– Martin Scharrer
Apr 16 '11 at 8:37
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
This is a fantastic answer, I used it and it works perfectly.
– Andrea Lazzarotto
Oct 27 '13 at 16:11
1
1
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
@TiGR: Yes, that's because the pages of the original PDF are added to a new PDF and in this process hyperlinks and similar things are discarded (for safety as I remember). Because the OP was about scanned PDF this wasn't an issue.
– Martin Scharrer
Oct 18 '14 at 16:46
|
show 1 more comment
You can do that with a text editor.
- metadata - How to change internal page numbers in the meta data of a PDF? - Super User
As the answer says, open a PDF file with a text editor, search /Catalog
entry, and then append an entry named /PageLabels
like this:
/PageLabels << /Nums [
0 << /P (cover) >> % labels 1st page with the string "cover"
1 << /S /r >> % numbers pages 2-6 in small roman numerals
6 << /S /D >> % numbers pages 7-x in decimal arabic numerals
]
>>
Note that the page indices (physical page numbers) begin with 0
.
Of cource, you can do this automatically using scripting languages.
PDF Standards - Page Labels has detailed specification.
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
add a comment |
You can do that with a text editor.
- metadata - How to change internal page numbers in the meta data of a PDF? - Super User
As the answer says, open a PDF file with a text editor, search /Catalog
entry, and then append an entry named /PageLabels
like this:
/PageLabels << /Nums [
0 << /P (cover) >> % labels 1st page with the string "cover"
1 << /S /r >> % numbers pages 2-6 in small roman numerals
6 << /S /D >> % numbers pages 7-x in decimal arabic numerals
]
>>
Note that the page indices (physical page numbers) begin with 0
.
Of cource, you can do this automatically using scripting languages.
PDF Standards - Page Labels has detailed specification.
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
add a comment |
You can do that with a text editor.
- metadata - How to change internal page numbers in the meta data of a PDF? - Super User
As the answer says, open a PDF file with a text editor, search /Catalog
entry, and then append an entry named /PageLabels
like this:
/PageLabels << /Nums [
0 << /P (cover) >> % labels 1st page with the string "cover"
1 << /S /r >> % numbers pages 2-6 in small roman numerals
6 << /S /D >> % numbers pages 7-x in decimal arabic numerals
]
>>
Note that the page indices (physical page numbers) begin with 0
.
Of cource, you can do this automatically using scripting languages.
PDF Standards - Page Labels has detailed specification.
You can do that with a text editor.
- metadata - How to change internal page numbers in the meta data of a PDF? - Super User
As the answer says, open a PDF file with a text editor, search /Catalog
entry, and then append an entry named /PageLabels
like this:
/PageLabels << /Nums [
0 << /P (cover) >> % labels 1st page with the string "cover"
1 << /S /r >> % numbers pages 2-6 in small roman numerals
6 << /S /D >> % numbers pages 7-x in decimal arabic numerals
]
>>
Note that the page indices (physical page numbers) begin with 0
.
Of cource, you can do this automatically using scripting languages.
PDF Standards - Page Labels has detailed specification.
edited Mar 20 '17 at 10:18
Community♦
1
1
answered Sep 19 '13 at 3:51
Akihiro HARAIAkihiro HARAI
6822714
6822714
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
add a comment |
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
+1 This answer is much simpler and better than the accepted one, and the link to the spec is a great help.
– jja
Mar 31 '16 at 11:24
add a comment |
There's a tool called PDF Mod which is a free tool to rearrange the pages of a PDF.
It can be installed from the Ubuntu Software Centre in Ubuntu 10.10 and higher.
To install in Ubuntu 9.10 or 10.04 :
To install Add the ppa ppa:pdfmod-team/ppa
to your software sources (Here's how to do that) and install pdfmod from the software center
Adapted from : http://www.webupd8.org/2011/03/edit-pdf-documents-in-linux-with-pdf.html
Good Luck :D
4
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
add a comment |
There's a tool called PDF Mod which is a free tool to rearrange the pages of a PDF.
It can be installed from the Ubuntu Software Centre in Ubuntu 10.10 and higher.
To install in Ubuntu 9.10 or 10.04 :
To install Add the ppa ppa:pdfmod-team/ppa
to your software sources (Here's how to do that) and install pdfmod from the software center
Adapted from : http://www.webupd8.org/2011/03/edit-pdf-documents-in-linux-with-pdf.html
Good Luck :D
4
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
add a comment |
There's a tool called PDF Mod which is a free tool to rearrange the pages of a PDF.
It can be installed from the Ubuntu Software Centre in Ubuntu 10.10 and higher.
To install in Ubuntu 9.10 or 10.04 :
To install Add the ppa ppa:pdfmod-team/ppa
to your software sources (Here's how to do that) and install pdfmod from the software center
Adapted from : http://www.webupd8.org/2011/03/edit-pdf-documents-in-linux-with-pdf.html
Good Luck :D
There's a tool called PDF Mod which is a free tool to rearrange the pages of a PDF.
It can be installed from the Ubuntu Software Centre in Ubuntu 10.10 and higher.
To install in Ubuntu 9.10 or 10.04 :
To install Add the ppa ppa:pdfmod-team/ppa
to your software sources (Here's how to do that) and install pdfmod from the software center
Adapted from : http://www.webupd8.org/2011/03/edit-pdf-documents-in-linux-with-pdf.html
Good Luck :D
edited Apr 13 '17 at 12:23
Community♦
1
1
answered Mar 26 '11 at 5:58
WilsonzaizaiWilsonzaizai
7652618
7652618
4
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
add a comment |
4
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
4
4
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
Ah, but my question wasn't asking about how to rearrange the pages. It was to change the metadata for the pages: relabel the page numbers (insert roman numerals as the first few pages, maybe skip a few; PDFs support the former certainly).
– MarkovCh1
Mar 27 '11 at 5:31
add a comment |
jPDF Tweak is an Open Source graphical utility that offers page numbering (the correct term is "page labeling") and many other beginner to advanced PDF editing features. It runs on Ubuntu and other operating systems.
The Documentation page provides step-by-step instructions.
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
add a comment |
jPDF Tweak is an Open Source graphical utility that offers page numbering (the correct term is "page labeling") and many other beginner to advanced PDF editing features. It runs on Ubuntu and other operating systems.
The Documentation page provides step-by-step instructions.
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
add a comment |
jPDF Tweak is an Open Source graphical utility that offers page numbering (the correct term is "page labeling") and many other beginner to advanced PDF editing features. It runs on Ubuntu and other operating systems.
The Documentation page provides step-by-step instructions.
jPDF Tweak is an Open Source graphical utility that offers page numbering (the correct term is "page labeling") and many other beginner to advanced PDF editing features. It runs on Ubuntu and other operating systems.
The Documentation page provides step-by-step instructions.
edited Aug 15 '14 at 7:13
answered Aug 15 '14 at 6:16
CherryBerryCherryBerry
412
412
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
add a comment |
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
Thanks, this what really helped me, preserving forms and all. jPDF Tweak is really powerful thing, though with not very convenient interface.
– TiGR
Oct 19 '14 at 20:12
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
If the original question did not mention batch jobs, I would say this answer really deserves to be the accepted one.
– Brian Z
Mar 19 '15 at 10:52
add a comment |
Just found a pointer that it could be possible to use ghostscript
for this, here: pdftk - Add and edit bookmarks to pdf - Unix and Linux - Stack Exchange #18600; it refers to links:
- [other] how to generate bookmarks via ghostscript/pdfwrite/pdfmark - Ubuntu Forums
- Ghostcript PDF Reference & Tips — Milan Kupcevic
However, the above deal with bookmarks - not with logical pagination. It turns out from pdfmarkReference.pdf, the needed "command" is '/Label
' (or '/PAGELABEL
') - and it further refers to PDFReference.pdf chapter 8.3.1 "Page Labels". Unfortunately, that chapter doesn't necessarrily explain how pdfmarks could be used with page labels - but this post does:
- [gs-bugs] [Bug 691889] pdfwrite with "/PAGELABEL pdfmark" operator does not work with multiple pages
The /PAGELABEL pdfmark does not have any /Page key, so one can set the
label for the ‘current’ page only (and, as a consequence, only for one
page at a time). Since you call it at the very beginning, it’s expected
to set a label for the 1st page and only for it.
Multiple /PAGELABELs for the same page: the pdfmark reference says the
last one takes effect, so the result of your 1st commandline is OK.
Note the /Page key is ignored.
How to set page labels from PostScript? I can think of 2 methods:
(A) The 100% documented way:
Issue a /PAGELABEL as part of each page.
(B) The less documented way:
...
gswin32c -sDEVICE=pdfwrite -sOutputFile=50pages.pdf -dNOPAUSE
GS>[/_objdef {pl} /type /dict /OBJ pdfmark
GS>[{pl} <</Nums [0 <</P (Page ) /S /r /St 10>> 2 <<>>]>> /PUT pdfmark
GS>[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
GS>50 { showpage } repeat
GS>quit
... and further in that thread:
As to making this work; since the original file is a PDF file, you can run each
page from the file individually. So you can set the PAGELABEL pdfmark for page
1, run page 1 from the original file, set the PAGELABEL for page 2, run page 2
from the original file and so on.
Because the label is (as SaGS) said applied to the current page, this should
correctly set the labels for each page in the output PDF file.
(caveat: I haven't actually tried this)
EDIT: just to show this - if you have this saved as pdfmarks
file:
[ /Label (-1) /PAGELABEL pdfmark
showpage
[ /Label (0) /PAGELABEL pdfmark
showpage
[ /Label (1) /PAGELABEL pdfmark
showpage
... and you call:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile.pdf pdfmarks
... then you will get three empty pages appended at the end of infile.pdf
, labeled -1, 0 and 1 :)
Well, maybe this helps sometime to get a simpler gs
script for renumbering pages :)
Cheers!
EDIT2: Got it, I think - use same gs
command as above - and below are the contents of the pdfmarks
script, which will renumber the infile.pdf, so it starts with -1, 0, 1 ... It's basically a modified example from the PDF reference (see comments for more):
% Type name (Optional) The type of PDF object that this dictionary describes; if present, must be PageLabel for a page label dictionary.
% S name (Optional) The numbering style to be used for the numeric portion of each page label:
% D Decimal arabic numerals
% R Uppercase roman numerals
% r Lowercase roman numerals
% A Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on)
% a Lowercase letters (a to z for the first 26 pages, aa to zz for the next 26, and so on)
% P text string (Optional) The label prefix for page labels in this range.
% St integer (Optional) The value of the numeric portion for the first page label in the range. Subsequent pages will be numbered sequentially from this value, which must be greater than or equal to 1. Default value: 1.
% renumber first 25 pages - push each by 10, and add prefix:
% [/_objdef {pl} /type /dict /OBJ pdfmark
% [{pl} <</Nums [0 <</P (Page ) /S /D /St 10>> 25 <<>>]>> /PUT pdfmark
% [{Catalog} <</PageLabels {pl}>> /PUT pdfmark
[/_objdef {pl} /type /dict /OBJ pdfmark
[{pl} <</Nums [ 0 << /P (-1) >> % just label -1 (no style) for pg 0;
1 << /P (0) >> % just label 0 (no style) for pg 1;
2 << /S /D /St 1 >> % decimal style, start from 1, for pg2 and on.
]>> /PUT pdfmark
[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
add a comment |
Just found a pointer that it could be possible to use ghostscript
for this, here: pdftk - Add and edit bookmarks to pdf - Unix and Linux - Stack Exchange #18600; it refers to links:
- [other] how to generate bookmarks via ghostscript/pdfwrite/pdfmark - Ubuntu Forums
- Ghostcript PDF Reference & Tips — Milan Kupcevic
However, the above deal with bookmarks - not with logical pagination. It turns out from pdfmarkReference.pdf, the needed "command" is '/Label
' (or '/PAGELABEL
') - and it further refers to PDFReference.pdf chapter 8.3.1 "Page Labels". Unfortunately, that chapter doesn't necessarrily explain how pdfmarks could be used with page labels - but this post does:
- [gs-bugs] [Bug 691889] pdfwrite with "/PAGELABEL pdfmark" operator does not work with multiple pages
The /PAGELABEL pdfmark does not have any /Page key, so one can set the
label for the ‘current’ page only (and, as a consequence, only for one
page at a time). Since you call it at the very beginning, it’s expected
to set a label for the 1st page and only for it.
Multiple /PAGELABELs for the same page: the pdfmark reference says the
last one takes effect, so the result of your 1st commandline is OK.
Note the /Page key is ignored.
How to set page labels from PostScript? I can think of 2 methods:
(A) The 100% documented way:
Issue a /PAGELABEL as part of each page.
(B) The less documented way:
...
gswin32c -sDEVICE=pdfwrite -sOutputFile=50pages.pdf -dNOPAUSE
GS>[/_objdef {pl} /type /dict /OBJ pdfmark
GS>[{pl} <</Nums [0 <</P (Page ) /S /r /St 10>> 2 <<>>]>> /PUT pdfmark
GS>[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
GS>50 { showpage } repeat
GS>quit
... and further in that thread:
As to making this work; since the original file is a PDF file, you can run each
page from the file individually. So you can set the PAGELABEL pdfmark for page
1, run page 1 from the original file, set the PAGELABEL for page 2, run page 2
from the original file and so on.
Because the label is (as SaGS) said applied to the current page, this should
correctly set the labels for each page in the output PDF file.
(caveat: I haven't actually tried this)
EDIT: just to show this - if you have this saved as pdfmarks
file:
[ /Label (-1) /PAGELABEL pdfmark
showpage
[ /Label (0) /PAGELABEL pdfmark
showpage
[ /Label (1) /PAGELABEL pdfmark
showpage
... and you call:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile.pdf pdfmarks
... then you will get three empty pages appended at the end of infile.pdf
, labeled -1, 0 and 1 :)
Well, maybe this helps sometime to get a simpler gs
script for renumbering pages :)
Cheers!
EDIT2: Got it, I think - use same gs
command as above - and below are the contents of the pdfmarks
script, which will renumber the infile.pdf, so it starts with -1, 0, 1 ... It's basically a modified example from the PDF reference (see comments for more):
% Type name (Optional) The type of PDF object that this dictionary describes; if present, must be PageLabel for a page label dictionary.
% S name (Optional) The numbering style to be used for the numeric portion of each page label:
% D Decimal arabic numerals
% R Uppercase roman numerals
% r Lowercase roman numerals
% A Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on)
% a Lowercase letters (a to z for the first 26 pages, aa to zz for the next 26, and so on)
% P text string (Optional) The label prefix for page labels in this range.
% St integer (Optional) The value of the numeric portion for the first page label in the range. Subsequent pages will be numbered sequentially from this value, which must be greater than or equal to 1. Default value: 1.
% renumber first 25 pages - push each by 10, and add prefix:
% [/_objdef {pl} /type /dict /OBJ pdfmark
% [{pl} <</Nums [0 <</P (Page ) /S /D /St 10>> 25 <<>>]>> /PUT pdfmark
% [{Catalog} <</PageLabels {pl}>> /PUT pdfmark
[/_objdef {pl} /type /dict /OBJ pdfmark
[{pl} <</Nums [ 0 << /P (-1) >> % just label -1 (no style) for pg 0;
1 << /P (0) >> % just label 0 (no style) for pg 1;
2 << /S /D /St 1 >> % decimal style, start from 1, for pg2 and on.
]>> /PUT pdfmark
[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
add a comment |
Just found a pointer that it could be possible to use ghostscript
for this, here: pdftk - Add and edit bookmarks to pdf - Unix and Linux - Stack Exchange #18600; it refers to links:
- [other] how to generate bookmarks via ghostscript/pdfwrite/pdfmark - Ubuntu Forums
- Ghostcript PDF Reference & Tips — Milan Kupcevic
However, the above deal with bookmarks - not with logical pagination. It turns out from pdfmarkReference.pdf, the needed "command" is '/Label
' (or '/PAGELABEL
') - and it further refers to PDFReference.pdf chapter 8.3.1 "Page Labels". Unfortunately, that chapter doesn't necessarrily explain how pdfmarks could be used with page labels - but this post does:
- [gs-bugs] [Bug 691889] pdfwrite with "/PAGELABEL pdfmark" operator does not work with multiple pages
The /PAGELABEL pdfmark does not have any /Page key, so one can set the
label for the ‘current’ page only (and, as a consequence, only for one
page at a time). Since you call it at the very beginning, it’s expected
to set a label for the 1st page and only for it.
Multiple /PAGELABELs for the same page: the pdfmark reference says the
last one takes effect, so the result of your 1st commandline is OK.
Note the /Page key is ignored.
How to set page labels from PostScript? I can think of 2 methods:
(A) The 100% documented way:
Issue a /PAGELABEL as part of each page.
(B) The less documented way:
...
gswin32c -sDEVICE=pdfwrite -sOutputFile=50pages.pdf -dNOPAUSE
GS>[/_objdef {pl} /type /dict /OBJ pdfmark
GS>[{pl} <</Nums [0 <</P (Page ) /S /r /St 10>> 2 <<>>]>> /PUT pdfmark
GS>[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
GS>50 { showpage } repeat
GS>quit
... and further in that thread:
As to making this work; since the original file is a PDF file, you can run each
page from the file individually. So you can set the PAGELABEL pdfmark for page
1, run page 1 from the original file, set the PAGELABEL for page 2, run page 2
from the original file and so on.
Because the label is (as SaGS) said applied to the current page, this should
correctly set the labels for each page in the output PDF file.
(caveat: I haven't actually tried this)
EDIT: just to show this - if you have this saved as pdfmarks
file:
[ /Label (-1) /PAGELABEL pdfmark
showpage
[ /Label (0) /PAGELABEL pdfmark
showpage
[ /Label (1) /PAGELABEL pdfmark
showpage
... and you call:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile.pdf pdfmarks
... then you will get three empty pages appended at the end of infile.pdf
, labeled -1, 0 and 1 :)
Well, maybe this helps sometime to get a simpler gs
script for renumbering pages :)
Cheers!
EDIT2: Got it, I think - use same gs
command as above - and below are the contents of the pdfmarks
script, which will renumber the infile.pdf, so it starts with -1, 0, 1 ... It's basically a modified example from the PDF reference (see comments for more):
% Type name (Optional) The type of PDF object that this dictionary describes; if present, must be PageLabel for a page label dictionary.
% S name (Optional) The numbering style to be used for the numeric portion of each page label:
% D Decimal arabic numerals
% R Uppercase roman numerals
% r Lowercase roman numerals
% A Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on)
% a Lowercase letters (a to z for the first 26 pages, aa to zz for the next 26, and so on)
% P text string (Optional) The label prefix for page labels in this range.
% St integer (Optional) The value of the numeric portion for the first page label in the range. Subsequent pages will be numbered sequentially from this value, which must be greater than or equal to 1. Default value: 1.
% renumber first 25 pages - push each by 10, and add prefix:
% [/_objdef {pl} /type /dict /OBJ pdfmark
% [{pl} <</Nums [0 <</P (Page ) /S /D /St 10>> 25 <<>>]>> /PUT pdfmark
% [{Catalog} <</PageLabels {pl}>> /PUT pdfmark
[/_objdef {pl} /type /dict /OBJ pdfmark
[{pl} <</Nums [ 0 << /P (-1) >> % just label -1 (no style) for pg 0;
1 << /P (0) >> % just label 0 (no style) for pg 1;
2 << /S /D /St 1 >> % decimal style, start from 1, for pg2 and on.
]>> /PUT pdfmark
[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
Just found a pointer that it could be possible to use ghostscript
for this, here: pdftk - Add and edit bookmarks to pdf - Unix and Linux - Stack Exchange #18600; it refers to links:
- [other] how to generate bookmarks via ghostscript/pdfwrite/pdfmark - Ubuntu Forums
- Ghostcript PDF Reference & Tips — Milan Kupcevic
However, the above deal with bookmarks - not with logical pagination. It turns out from pdfmarkReference.pdf, the needed "command" is '/Label
' (or '/PAGELABEL
') - and it further refers to PDFReference.pdf chapter 8.3.1 "Page Labels". Unfortunately, that chapter doesn't necessarrily explain how pdfmarks could be used with page labels - but this post does:
- [gs-bugs] [Bug 691889] pdfwrite with "/PAGELABEL pdfmark" operator does not work with multiple pages
The /PAGELABEL pdfmark does not have any /Page key, so one can set the
label for the ‘current’ page only (and, as a consequence, only for one
page at a time). Since you call it at the very beginning, it’s expected
to set a label for the 1st page and only for it.
Multiple /PAGELABELs for the same page: the pdfmark reference says the
last one takes effect, so the result of your 1st commandline is OK.
Note the /Page key is ignored.
How to set page labels from PostScript? I can think of 2 methods:
(A) The 100% documented way:
Issue a /PAGELABEL as part of each page.
(B) The less documented way:
...
gswin32c -sDEVICE=pdfwrite -sOutputFile=50pages.pdf -dNOPAUSE
GS>[/_objdef {pl} /type /dict /OBJ pdfmark
GS>[{pl} <</Nums [0 <</P (Page ) /S /r /St 10>> 2 <<>>]>> /PUT pdfmark
GS>[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
GS>50 { showpage } repeat
GS>quit
... and further in that thread:
As to making this work; since the original file is a PDF file, you can run each
page from the file individually. So you can set the PAGELABEL pdfmark for page
1, run page 1 from the original file, set the PAGELABEL for page 2, run page 2
from the original file and so on.
Because the label is (as SaGS) said applied to the current page, this should
correctly set the labels for each page in the output PDF file.
(caveat: I haven't actually tried this)
EDIT: just to show this - if you have this saved as pdfmarks
file:
[ /Label (-1) /PAGELABEL pdfmark
showpage
[ /Label (0) /PAGELABEL pdfmark
showpage
[ /Label (1) /PAGELABEL pdfmark
showpage
... and you call:
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile.pdf pdfmarks
... then you will get three empty pages appended at the end of infile.pdf
, labeled -1, 0 and 1 :)
Well, maybe this helps sometime to get a simpler gs
script for renumbering pages :)
Cheers!
EDIT2: Got it, I think - use same gs
command as above - and below are the contents of the pdfmarks
script, which will renumber the infile.pdf, so it starts with -1, 0, 1 ... It's basically a modified example from the PDF reference (see comments for more):
% Type name (Optional) The type of PDF object that this dictionary describes; if present, must be PageLabel for a page label dictionary.
% S name (Optional) The numbering style to be used for the numeric portion of each page label:
% D Decimal arabic numerals
% R Uppercase roman numerals
% r Lowercase roman numerals
% A Uppercase letters (A to Z for the first 26 pages, AA to ZZ for the next 26, and so on)
% a Lowercase letters (a to z for the first 26 pages, aa to zz for the next 26, and so on)
% P text string (Optional) The label prefix for page labels in this range.
% St integer (Optional) The value of the numeric portion for the first page label in the range. Subsequent pages will be numbered sequentially from this value, which must be greater than or equal to 1. Default value: 1.
% renumber first 25 pages - push each by 10, and add prefix:
% [/_objdef {pl} /type /dict /OBJ pdfmark
% [{pl} <</Nums [0 <</P (Page ) /S /D /St 10>> 25 <<>>]>> /PUT pdfmark
% [{Catalog} <</PageLabels {pl}>> /PUT pdfmark
[/_objdef {pl} /type /dict /OBJ pdfmark
[{pl} <</Nums [ 0 << /P (-1) >> % just label -1 (no style) for pg 0;
1 << /P (0) >> % just label 0 (no style) for pg 1;
2 << /S /D /St 1 >> % decimal style, start from 1, for pg2 and on.
]>> /PUT pdfmark
[{Catalog} <</PageLabels {pl}>> /PUT pdfmark
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Oct 14 '11 at 0:24
sdaausdaau
1,56012737
1,56012737
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
add a comment |
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
Great! Thanks, you don't joke around :)
– MarkovCh1
Oct 15 '11 at 15:58
add a comment |
Openoffice/Libreoffice can do the trick with the pdf-import extension and a pagination Macro.
Not a perfect solution, but it works for me (apart from using PDF Mod - which I would strongly suggest).
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
add a comment |
Openoffice/Libreoffice can do the trick with the pdf-import extension and a pagination Macro.
Not a perfect solution, but it works for me (apart from using PDF Mod - which I would strongly suggest).
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
add a comment |
Openoffice/Libreoffice can do the trick with the pdf-import extension and a pagination Macro.
Not a perfect solution, but it works for me (apart from using PDF Mod - which I would strongly suggest).
Openoffice/Libreoffice can do the trick with the pdf-import extension and a pagination Macro.
Not a perfect solution, but it works for me (apart from using PDF Mod - which I would strongly suggest).
answered Apr 9 '11 at 5:36
RolandiXor♦RolandiXor
44.5k25140230
44.5k25140230
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
add a comment |
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
The pdf-import extension seems busted for OpenOffice.org 3.2. Importing (into Draw and Writer) gives an "I/O error."
– MarkovCh1
Apr 9 '11 at 16:54
add a comment |
Try pyPdf, a python library to manipulate PDF documents. Some, but not much, programming would be necessary.
You could also have a look at PDFtk, though I haven't checked if it supports changing the page number associated with individual pages. Both are available as packages in Ubuntu.
1
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
add a comment |
Try pyPdf, a python library to manipulate PDF documents. Some, but not much, programming would be necessary.
You could also have a look at PDFtk, though I haven't checked if it supports changing the page number associated with individual pages. Both are available as packages in Ubuntu.
1
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
add a comment |
Try pyPdf, a python library to manipulate PDF documents. Some, but not much, programming would be necessary.
You could also have a look at PDFtk, though I haven't checked if it supports changing the page number associated with individual pages. Both are available as packages in Ubuntu.
Try pyPdf, a python library to manipulate PDF documents. Some, but not much, programming would be necessary.
You could also have a look at PDFtk, though I haven't checked if it supports changing the page number associated with individual pages. Both are available as packages in Ubuntu.
answered Apr 9 '11 at 8:21
loevborgloevborg
5,57211823
5,57211823
1
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
add a comment |
1
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
1
1
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
Hm, PDFtk doesn't seem to be able to do it. pyPdf has many methods for extracting metadata, but doesn't seem to be able to write them back into the document.
– MarkovCh1
Apr 9 '11 at 17:07
add a comment |
There is another app out there called PDFEdit - its hosted on source forge.
Source Forge Project Page - However this doesn't help because it doesn't the functionality you require
1
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
2
@Syzygy - indeed, just checked:pdfedit
can showCatalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!
– sdaau
Oct 14 '11 at 0:36
add a comment |
There is another app out there called PDFEdit - its hosted on source forge.
Source Forge Project Page - However this doesn't help because it doesn't the functionality you require
1
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
2
@Syzygy - indeed, just checked:pdfedit
can showCatalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!
– sdaau
Oct 14 '11 at 0:36
add a comment |
There is another app out there called PDFEdit - its hosted on source forge.
Source Forge Project Page - However this doesn't help because it doesn't the functionality you require
There is another app out there called PDFEdit - its hosted on source forge.
Source Forge Project Page - However this doesn't help because it doesn't the functionality you require
edited Oct 14 '11 at 2:09
Community♦
1
1
answered Apr 9 '11 at 1:28
lazyPowerlazyPower
4,51322740
4,51322740
1
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
2
@Syzygy - indeed, just checked:pdfedit
can showCatalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!
– sdaau
Oct 14 '11 at 0:36
add a comment |
1
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
2
@Syzygy - indeed, just checked:pdfedit
can showCatalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!
– sdaau
Oct 14 '11 at 0:36
1
1
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
I don't actually think PDF Edit can change the page numbers. I tried and haven't succeeded, in any case.
– MarkovCh1
Apr 9 '11 at 16:49
2
2
@Syzygy - indeed, just checked:
pdfedit
can show Catalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!– sdaau
Oct 14 '11 at 0:36
@Syzygy - indeed, just checked:
pdfedit
can show Catalog/PageLabels
Dict if a document has it, but if it is selected, it says: "This dictionary does not have any directly editable properties"... Cheers!– sdaau
Oct 14 '11 at 0:36
add a comment |
There is a little python script, that can do the job: https://github.com/lovasoa/pagelabels-py
In your case call:
./addpagelabels.py --delete file.pdf
./addpagelabels.py --startpage 1 --type 'roman lowercase' file.pdf
./addpagelabels.py --startpage 4 --type arabic file.pdf
add a comment |
There is a little python script, that can do the job: https://github.com/lovasoa/pagelabels-py
In your case call:
./addpagelabels.py --delete file.pdf
./addpagelabels.py --startpage 1 --type 'roman lowercase' file.pdf
./addpagelabels.py --startpage 4 --type arabic file.pdf
add a comment |
There is a little python script, that can do the job: https://github.com/lovasoa/pagelabels-py
In your case call:
./addpagelabels.py --delete file.pdf
./addpagelabels.py --startpage 1 --type 'roman lowercase' file.pdf
./addpagelabels.py --startpage 4 --type arabic file.pdf
There is a little python script, that can do the job: https://github.com/lovasoa/pagelabels-py
In your case call:
./addpagelabels.py --delete file.pdf
./addpagelabels.py --startpage 1 --type 'roman lowercase' file.pdf
./addpagelabels.py --startpage 4 --type arabic file.pdf
answered Jan 13 at 21:00
DG'DG'
1012
1012
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f32048%2frenumber-pages-of-a-pdf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Would you be happy with a solution based on LaTeX? It would be possible to include the PDF in an otherwise empty document and create the PDF page numbers as you like.
– Martin Scharrer
Apr 8 '11 at 23:34
I would indeed be happy with a LaTeX solution. Can you post some details below?
– MarkovCh1
Apr 9 '11 at 17:08