CPDF(1)
๐ cpdf(1) โ General Commands Manual ๐
okay bestie, pull up a chair, grab a boba, because we're about to get SO cozy with cpdf(1). this is the manpage for the cpdf command line tools and it's genuinely iconic, no cap.
โจ NAME โจ
cpdf โ PDF command line tools. that's it. that's the name. short, sweet, serves.
โจ SYNOPSIS โจ
simple operation, the everyday slay:
cpdf [in.pdf] [operation] [options] [-o out.pdf]
operation on a password-protected file, iykyk:
cpdf in.pdf [user=<password>] [owner=<password>] ... [-o out.pdf]
multiple operations, one after another (chaining, we love to see it):
cpdf [in.pdf] [operation] [options] AND [operation] [options] AND ... [-o out.pdf]
โจ DESCRIPTION โจ
Cpdf is an AGPL-licensed command line tool for processing PDF files. ๐ literally does it all.
the rest of this document gives a brief description of each command line operation and option. the file cpdfmanual.pdf โ which you should find installed on your system, or otherwise at https://www.coherentpdf.com/cpdfmanual.pdf โ gives the full usage details. so if this page leaves you wanting more, that's where the full tea lives. ๐ซ
the sections in this document follow the chapters of cpdfmanual.pdf, for easy cross-referencing. cute, organized, main character energy. โจ
๐ 1. BASIC USAGE ๐
the starter pack of flags
-versionโ print the Cpdf version number. just, like, who are you. in a good way.-help,โhelpโ gives links to sources of help. we all need a little help sometimes bestie. ๐ซถ-summaryโ lists and describes very briefly each command line option. the tl;dr of tl;drs.-o <filename>โ the output filename. > โ ๏ธ beware of writing back to the input file. that's not a vibe check, that's a genuine warning. don't do it.-i <filename>โ Cpdf automatically treats any filename ending with.pdf(any case) as an input PDF. but if your file doesn't end with.pdf, you can supply the file with-iinstead. inclusivity! ๐-range <range>โ gives the range of pages to be affected by an operation. by default, all pages are affected. the range may be specified without-rangesimply by writing it directly after the filename it relates to. example ranges: โ2โ โ1-5โ โ1,2,3-endโ โoddโ โNOT1-5โ. seecpdfmanual.pdffor a full description. so many options, so many looks. ๐-progressโ show which operations and on which pages they are operating, as it happens, on standard error. live updates, we're streaming. ๐บ-keep-versionโ keep the PDF version of the input document even if features are used which would otherwise make it increase. don't let anyone force you to change. โ-fastโ presume ISO-compliant content streams when processing page content. this is faster, because it does not involve re-parsing whole streams to add content. speed. ๐๏ธ-idir <path>โ add a whole directory of PDFs as inputs. bulk, we love a bulk moment.-idir-only-pdfsโ restrict-idirto only files ending in.pdf(any case). > must appear before-idir. order matters, bestie.-recryptโ re-encrypt output files using the same encryption parameters (if any) as the input file. privacy, but make it consistent. ๐-decrypt-forceโ allow the output file to be written decrypted even if permissions would otherwise prevent it. force, but make it authorized. ๐-stdoutโ write the output file to standard output instead of to a file with-o. pipe it, slay it.-stdinโ read the input PDF from standard input instead of from a named file. the other end of the pipe. ๐ซถ-stdin-user <password>โ supply the user password for the PDF which is from standard input.-stdin-owner <password>โ supply the owner password the the PDF which is from standard input. (yes it says "the the", that's canon, we don't edit the queen. ๐)-producer <string>โ set the producer of the output file. put your name on it, it's your art.-creator <string>โ set the creator of the output file. even more credit. โจ-change-idโ change the PDF's ID field when writing the output file. fresh identity, fresh start. ๐ฆ-lโ linearize the PDF when writing. > requires a linearizer to be supplied with-cpdflin.-cpdflin <path>โ give the path of an external linearizer. for example, Qpdf.-keep-lโ keep the linearization status (either linearized or not) of the input file upon output. > requires a linearizer to be supplied with-cpdflin.-no-preserve-objstmโ do not preserve existing object streams when writing the output file. note that-create-objstmand-no-preserve-objstmmay be used together โ the effect is then to redo all object streams. combo move. ๐ฅ-create-objstmโ create new object streams when writing the output file. note that-create-objstmand-no-preserve-objstmmay be used together โ the effect is then to redo all object streams. same combo, other direction. ๐-args <filename>โ read command line arguments from the given file by direct textual substitution into the command line, prior to any other processing.-args-json <filename>โ read command line arguments from a JSON file consisting of a single array of strings. json girlies rise. ๐ง-utf8โ read and write string data as UTF8. almost always the sensible option, and will become the default in a future version. ahead of its time, honestly. โญ-strippedโ convert string output to 7 bit ASCII by dropping any high characters. > to be used with caution. ๐ญ-rawโ perform no processing on string outputs. raw, unfiltered, no edits. periodt.-gs <path>โ a very few of Cpdf's functions rely upon thegscommand. its path may be supplied with-gs.-gs-malformedโ this option is used to allow Cpdf to call out to thegscommand to pre-process badly malformed files as a last resort. emergency mode, bestie. ๐จ-gs-malformed-forceโ seecpdfmanual.pdffor details of this fragile command. fragile. handle with care. ๐-gs-quietโ do not show the output ofgswhen used. shhh. ๐คซ-error-on-malformedโ do not attempt to reconstruct malformed files by any method, but exit with an error. no fixing, just honesty. ๐
๐ 2. MERGING AND SPLITTING ๐
๐ธ Merging ๐ธ
cpdf -merge in1.pdf [<range>] in2.pdf [<range>] [<more names/ranges>]
[-collate] [-collate-n <n>] [-retain-numbering] [-merge-add-bookmarks
[-merge-add-bookmarks-use-titles]] [-remove-duplicate-fonts]
[-process-struct-trees] [-subformat <subformat>] -o out.pdf
the -merge operation allows the merging of several files into one. ranges can be used to select only a subset of pages from each input file in the output. the output file consists of the concatenation of all the input pages in the order specified on the command line. actually โ plot twist โ the -merge can be omitted, since this is the default operation of Cpdf. it's giving "effortless". ๐
-collateโ instead of ordinary operation, take the first page from the first document, then the first from the second and so on. then the second page from the first document and on until all pages are exhausted. shuffling the deck, iconic. ๐-collate-n <n>โ like-collate, but in chunks of more than one page. chunkier collate.-retain-numberingโ keep the page numbering of each input file intact, rather than renumbering the pages in the output document beginning at 1. no renumbering, no notes. โ-merge-add-bookmarks [-merge-add-bookmarks-use-titles]โ add a top-level bookmark for each file, using the filename. the option-merge-add-bookmarks-use-titles, when used in conjunction with-merge-add-bookmarks, uses the titles from document metadata instead. cute little tabs for days. ๐-remove-duplicate-fontsโ ensures that fonts used in more than one input appear only once in the output. decluttering, we stan. ๐งน-process-struct-treesโ merge input structure trees in the output.-subformat <subformat>โ if-subformatโPDF/UA-2โ is given, together with-process-struct-trees, Cpdf will add a top-level Document structure tree element.
๐ฆ Portfolios ๐ฆ
a PDF portfolio is a special kind of PDF which contains other documents (PDF and otherwise) within it. support is mostly limited to Adobe products at time of writing. it's a whole little world in there. ๐
cpdf -portfolio in.pdf -pf <filename> [-pfd <string>] [-pfr
<relationship>] [-pf ...] -o out.pdf
the input in.pdf here is the main file. you can build a blank one with -create-pdf.
-pf <filename>โ the filename for each file to include in the portfolio.-pfd <description>โ the description for the file (> must appear after-pf).-pfr <relationship>โ the so-called relationship for the file (> must appear after-pf). it's complicated, but we support it. ๐
โ๏ธ Splitting โ๏ธ
we can split an input PDF into its constituent pages, and output one PDF for each page or each chunk of pages.
cpdf -split in.pdf [-chunk <n>] [-process-struct-trees] [-utf8] -o <format>
the output format has many options (see cpdfmanual.pdf for details). but the simplest is just to number the outputs in sequence. for example cpdf in.pdf -o out%%%.pdf will produce out001.pdf, out002.pdf and so on. look at them go. ๐
-chunk <n>โ choose a chunk size other than 1.-process-struct-treesโ split the input document's structure tree into the output documents.-utf8โ this option may be required in the case of some output formats. seecpdfmanual.pdffor details.
๐ Splitting on bookmarks ๐
cpdf -split-bookmarks <level> in.pdf [-process-struct-trees] [-utf8] -o <format>
split on bookmark boundaries at a given level, instead of splitting on each page. level 0 is top level, level 1 next, and so on. see above for format details. following the vibes of your bookmarks, respectfully. ๐
-process-struct-treesโ split the input document's structure tree into the output documents.-utf8โ this option may be required in the case of some output formats. seecpdfmanual.pdffor details.
โญ Splitting to a given size โญ
cpdf -split-max <n> in.pdf [-process-struct-trees] [-utf8] -o <format>
split the file, if possible, to a maximum file size (in bytes) for each output PDF. see above for format details. keeping it bite-sized, fr fr.
-process-struct-treesโ split the input document's structure tree into the output documents.-utf8โ this option may be required in the case of some output formats. seecpdfmanual.pdffor details.
๐ซ Interleaved splitting ๐ซ
we can use -spray to write the split pages to more than one named output file. when Cpdf runs out of output files, it adds the next page to the first output file, and so on until all input pages are exhausted. round robin but make it pages. ๐
cpdf -spray in.pdf [-process-struct-trees] [-utf8] -o a.pdf [-o b.pdf [-o ...]]
-process-struct-treesโ split the input document's structure tree into the output documents.-utf8โ this option may be required in the case of some output formats. seecpdfmanual.pdffor details.
๐ฆ 3. PAGES ๐ฆ
ok bestie this chapter is all about moving pages around, scaling them, rotating them, flipping them โ the whole glow-up menu. let's go ๐
cpdf -scale-page "<x scale> <y scale>" in.pdf [<range>] [-fast]
[<position>] -o out.pdf
Scale pages in the given range by the given factor e.g "2 2". See Chapter 8 for information on positions. (yes queen, chapter 8 is where the positions live, we'll get there ๐)
cpdf -scale-to-fit "<x size> <y size>" in.pdf [<range>] [-fast]
[-prerotate] [<position>] [-scale-to-fit-scale <scale>]
[-scale-to-fit-rotate-clockwise] [-scale-to-fit-rotate-anticlockwise] -o
out.pdf
Scale pages in the given range to fit the given size e.g "a4paper" or "10in 7in", without altering the aspect ratio. By default the content will be centered on the new page. See Chapter 8 for information on positions.
-scale-to-fit-scale <n>โ scale to a proportion of the available area instead of filling it. like,0.9for 90 percent. so close to full but leaving a lil margin, very demure ๐-scale-to-fit-rotate-clockwise,-scale-to-fit-rotate-anticlockwiseโ automatically rotate the page to maximise use of area. it's giving "make it fit, bestie" ๐-prerotateโ remove any viewing rotation before beginning. clean slate energy โจ
cpdf -stretch "<x size> <y size>" in.pdf [<range>] [-fast] -o out.pdf
Scale pages without regard to aspect ratio. yeah she's gonna get squished or stretched, no thoughts, no proportions ๐
cpdf -center-to-fit "<x size> <y size>" in.pdf [<range>] [-fast] -o
out.pdf
Center each page on a new page size, without scaling it. just vibing in the middle, untouched ๐ธ
cpdf -scale-contents <scale> in.pdf [<range>] [<position>] [-fast] -o
out.pdf
Scale the content of pages by a given factor, without changing the size of the page. See the end of this chapter for position. (the paper stays, the stuff on it grows ๐)
cpdf -shift "<shift x> <shift y>" in.pdf [<range>] [-fast] -o out.pdf
Shift the content of pages by a given displacement. sliding into a new spot, no cap ๐
cpdf -shift-boxes "<shift x> <shift y>" in.pdf [<range>] -o out.pdf
Shift the boxes of a page by a given displacement, without moving the content. the frame moves, the art stays. iconic contrast โจ
cpdf -rotate <angle> in.pdf [<range>] -o out.pdf
Change the PDF viewing rotation of pages to 0, 90, 180 or 270 degrees clockwise.
cpdf -rotateby <angle> in.pdf [<range>] -o out.pdf
Change the PDF viewing rotation of pages by 0, 90, 180 or 270 degrees clockwise. (so -rotate sets it, -rotateby adds to it โ iykyk ๐ฅ)
cpdf -upright in.pdf [<range>] [-fast] -o out.pdf
The -upright operation does whatever combination of -rotate and -rotate-contents is required to change the rotation of the document to zero without altering its appearance. In addition, it makes sure the media box has its origin at (0,0), changing other boxes to compensate. she does it ALL and makes it look effortless ๐
cpdf -rotate-contents <angle> in.pdf [<range>] [-fast] -o out.pdf
Rotates the content of the page around its center point by the given angle.
cpdf -hflip in.pdf [<range>] [-fast] -o out.pdf
Flip page content horizontally. mirror moment ๐ช
cpdf -vflip in.pdf [<range>] [-fast] -o out.pdf
Flip page content vertically. upside-down era ๐
cpdf -[media | crop | art | trim | bleed]box <boxspec> in.pdf [<range>]
-o out.pdf
Set the media, crop, art, trim or bleed box. For example -cropbox "50 50 300 200" sets minx 50, miny 50, width 300, height 200. To use absolute numbers instead of width and height, prefix with a question mark, writing "?50 50 350 250" instead. (the ? is like "bestie these are absolutes, don't @ me") โ
cpdf -remove-[crop | art | trim | bleed]box in.pdf [<range>] -o out.pdf
Remove a crop, art, trim or bleed box from pages. gone. deleted. no trace ๐จ
cpdf -frombox <boxname> -tobox <boxname> in.pdf [<range>]
[-mediabox-if-missing] -o out.pdf
Copy a box to another. For example from /TrimBox to /CropBox. box-to-box pipeline, so slay ๐
-mediabox-if-missingโ use media box, rather than failing, if the-fromboxis missing. (no tantrum, just fall back gracefully ๐ซถ)
cpdf -hard-box <boxname> in.pdf [<range>] [-fast] [-mediabox-if-missing]
-o out.pdf
Create a hard box for a given box name โ that is to say, one which clips its content. hard box = hard boundaries, she doesn't let anything spill out ๐ง
cpdf -show-boxes in.pdf [<range>] [-fast] -o out.pdf
Show the media, crop, art, trim, and bleed boxes in Red, Green, Blue, Orange and Pink respectively. a whole rainbow of boundaries ๐
cpdf -trim-marks in.pdf [<range>] [-fast] -o out.pdf
Add trim marks to a PDF. The trim box must be present. (no trim box, no trim marks, them's the rules โ๏ธ)
๐ 4. ENCRYPTION AND DECRYPTION ๐
ok this is the "who's allowed to see/touch what" chapter. very main character, very gatekeeping, but make it security ๐
cpdf -encrypt <method> [-pw=]<owner password> [-pw=]<user password>
in.pdf [-no-encrypt-metadata] <permissions> -o out.pdf
Encrypt a document given the method (e.g AES256ISO for modern usage), owner and user passwords, and optionally permissions. E.g cpdf -encrypt AES256ISO secret "" in.pdf -o out.pdf.
-no-encrypt-metadataโ do not encrypt metadata (AES encryption only).-pw=<password>โ useful if a password may begin with a dash. (so the parser doesn't get confused and think your password is a flag, bestie ๐)
Permissions (pick your limits, queen):
-no-editโ cannot change the document.-no-printโ cannot print the document.-no-copyโ cannot select or copy text or graphics.-no-annotโ cannot add or change form fields or annotations.-no-formsโ cannot edit form fields.-no-extractโ cannot extract text or graphics.-no-assembleโ cannot, for example, merge files.-no-hq-printโ cannot print high-quality.
Note: Adobe Acrobat and Adobe Reader may show slightly different permissions in info dialogues โ this is a result of policy changes and not a bug in Cpdf. You may need to experiment. fr fr, don't come for cpdf, she's innocent ๐ญ
cpdf -decrypt in.pdf owner=<owner password> [-decrypt-force] -o out.pdf
Decrypt a document, given its owner password.
-decrypt-forceโ decrypt even without the owner password, using just the user password. The user password is often blank. (lowkey wild but okay, she said "I'll allow it" ๐)
๐๏ธ 5. COMPRESSION ๐๏ธ
shrinking files is self-care, periodt โจ
cpdf -decompress in.pdf [-just-content] [-jbig2dec <path>] -o out.pdf
Decompress the streams in a PDF file, for instance to manually inspect it. (unzip it like "let me see your true form" ๐)
-just-contentโ only decompress page content streams.-jbig2dec <path>โ give the path to thejbig2decprogram which Cpdf uses, if available, to decompress JBIG2 streams.
cpdf -compress in.pdf -o out.pdf
Compress any streams which are uncompressed using the FlateDecode method, with the exception of metadata streams. (metadata gets to stay unbothered ๐)
cpdf -squeeze in.pdf [-squeeze-log-to <filename>] [-squeeze-no-pagedata]
-o out.pdf
Squeeze a file by coalescing like objects, and various other methods. she's squeezing it like a lemon, getting every last drop ๐
-squeeze-log-to <filename>โ write the squeeze log to file rather than standard output.-squeeze-no-pagedataโ avoid processing page data, making the squeeze process much faster at the cost of a little compression. speed over squeeze, a tradeoff bestie โก
cpdf -remove-article-threads in.pdf -o out.pdf
Remove article threads.
cpdf -remove-page-piece in.pdf -o out.pdf
Remove page piece information.
cpdf -remove-web-capture in.pdf -o out.pdf
Remove web capture data.
cpdf -remove-procsets in.pdf -o out.pdf
Remove ProcSets, a now-irrelevant data structure from early PDFs. ancient relic, we don't know her anymore ๐
cpdf -remove-output-intents in.pdf -o out.pdf
Remove output intents, a colour-matching system for documents intended to be printed.
๐ 6. BOOKMARKS ๐
the navigation chapter!! bookmarks are literally the little side quests of a PDF and I'm obsessed ๐
cpdf -list-bookmarks in.pdf [-utf8]
Print bookmark data to standard output. The data includes level, title, page number linked to, and full link data. Use -utf8 always. For example:
0 "Part 1" 1 open
1 "Part 1A" 2 "[2 /XYZ 200 400 null]"
1 "Part 1B" 3
0 "Part 2" 4
1 "Part 2a" 5
cpdf -list-bookmarks-json in.pdf [-preserve-actions]
Print bookmark data to standard output in JSON format instead. Here is a single entry in the JSON array of bookmarks:
{ "level": 0,
"text": "1 Basic Usage",
"page": 17,
"open": false,
"target":
[ { "I": 17 },
{ "N": "/XYZ" },
{ "F": 85.039 },
{ "F": 609.307 },
null ]
"colour": [ 0.0, 0.0, 0.0 ],
"italic": false,
"bold": false
}
-preserve-actionsโ instead of resolving complex destinations types to simple ones, keep the originals. (don't dumb it down, she said ๐ )
cpdf -remove-bookmarks in.pdf -o out.pdf
Remove all bookmarks from a PDF. sorry to the navigation, she's gone ๐ญ
cpdf -add-bookmarks <filename> in.pdf -o out.pdf
Add bookmarks, given an old-style bookmark file.
cpdf -add-bookmarks-json <filename> in.pdf -o out.pdf
Add bookmarks, given a new-style JSON bookmark file.
cpdf -bookmarks-open-to-level <n> in.pdf -o out.pdf
Set all bookmarks up to and including a given level to be open. (expand the vibe up to level <n> โจ)
cpdf -table-of-contents in.pdf [-toc-title <string>] [-toc-no-bookmark]
[-toc-dot-leaders] [-font <font>] [-font-size <n>] [-embed-std14 <path>]
[-process-struct-trees] [-subformat <subformat>] -o out.pdf
Generate a typeset table of contents from existing bookmarks, adding it to the beginning of the document. she's front and center, main character energy ๐
-toc-title <string>โ title (default is"Table of Contents").-toc-no-bookmarkโ do not add an entry for the new table of contents in the document's bookmarks.-toc-dot-leadersโ add dot leaders. (.......you know the vibe ๐)-font <font>โ give the font (default Times Roman).-font-size <n>โ give the font size (default12pt).-embed-std14โ embed standard 14 fonts given their path (seecpdfmanual.pdffor details).-process-struct-treesโ create a structure tree for the new table of contents and merge it with the document's.-subformat <subformat>โ add-subformat "PDF/UA-2"when adding a table of contents to aPDF/UA-2file to keep compatibility.
๐ฌ 7. PRESENTATIONS ๐ฌ
making a slideshow out of your PDF? she's a director now, call her auteur ๐ฅ
cpdf -presentation in.pdf [<range>] -o out.pdf [-trans
<transition-name>] [-duration <float>] [-vertical] [-outward]
[-direction <n>] [-effect-duration <float>]
Make a slide-show presentation from a PDF.
-trans <transition>โ the transition style, one ofSplit,Blinds,Box,Wipe,Dissolve,Glitter. pick your era โจ-duration <n>โ time in seconds before presentation advances (default: no automatic advancement). (default is basically "she waits for your cue, diva ๐ซถ")-verticalโ select vertical blinds for transition typeBlinds.-outwardโ select outward sweep for transition typeBox.-direction <n>โ direction forWipeandGlitterstyles. Seecpdfmanual.pdffor full information.-effect-duration <n>โ length in seconds of the transition itself.
๐ 8. TEXT AND STAMPS ๐
okay bestie, this is the section where we put stuff on top of pages. stamps, text, rectangles โ the whole glow-up. ๐
๐ธ Stamping one PDF onto another ๐ธ
cpdf [-stamp-on | -stamp-under] stamp.pdf in.pdf [<range>]
[-scale-stamp-to-fit] [<positioning command>] [-relative-to-cropbox]
[-process-struct-trees] [-fast] -o out.pdf
So you grab a one-page PDF (that's your stamp, your little sticker โจ) and you slap it over or under every single page in your <range>. Where does it land? That's up to the positioning commands, which are literally further down this chapter โ go look. And if you don't say anything? Default is the bottom left of the media box. no thoughts, head empty, bottom left.
-scale-stamp-to-fitโ scales the stamp so it actually fits the page before applying it. ๐-relative-to-cropboxโ measures the positioning command from the crop box instead of the media box.-process-struct-treesโ keeps your tagged PDF tagged. The main file keeps its structure, and the stamp gets marked as an artifact. ๐ซถ
the synopsis also has -fast sitting in there, minding its own business.
๐ฆ Combining two PDFs, page by page ๐ฆ
cpdf -combine-pages over.pdf under.pdf [-fast] [-prerotate]
[-no-warn-rotate] [-process-struct-trees] [-underneath]
[-stamp-scale-to-fit] -o out.pdf
This is a sandwich ๐ฅช. Page 1 of the first file with page 1 of the second, page 2 with page 2, and on and on like that.
-prerotateโ strips out any rotation differences between the files before combining them.-no-warn-rotateโ do not warn about unresolved rotation differences. silence. ๐คซ-underneathโ reverses the order of the "over" and "under" files.-process-struct-treesโ keeps tagged PDF alive. The "under" file keeps its structure; the "over" file gets marked as an artifact.
the synopsis also includes-fastand-stamp-scale-to-fitโ they're listed there, bestie, that's all I'm telling you.
๐ Adding text ๐
cpdf [-add-text <string> | -add-rectangle โ<x size> <y size>โ] [-font
<fontname>] [-font-size <n>] [-load-ttf <name>=<filename>] [-embed-std14
<path>] [-color <color>] [-line-spacing <n>] [-outline] [-linewidth <n>]
[-underneath] [-relative-to-cropbox] [-prerotate] [-no-warn-rotate]
[-bates <n>] [-bates-at-range <n>] [-bates-pad-to <n>] [-opacity <n>]
[-midline] [-topline] [-fast] [-process-struct-trees] in.pdf [<range>]
-o out.pdf
Adding text to a PDF, periodt. And there are these little special codes for page numbers, and for time and date โ they hit SO different. Like:
%Page Page number in arabic notation (1, 2, 3. . . )
%PageDiv2 Page number in arabic notation divided by two
%roman Page number in lower-case roman notation (i, ii, iii. . . )
%Roman Page number in upper-case roman notation (I, II, III. . . )
%EndPage Last page of document in arabic notation
%Label The page label of the page
%EndLabel The page label of the last page
%filename The full file name of the input document
%URL[text|URL] Add text, which links to URL (does not work for diagonal text)
%Bookmark<n> Bookmark text at level n (0, 1, 2, 3, 4)
%Bates Bates number
And the date-and-time formats, which are giving clock app energy โฐ:
%a Abbreviated weekday name (Sun, Mon etc.)
%A Full weekday name (Sunday, Monday etc.)
%b Abbreviated month name (Jan, Feb etc.)
%B Full month name (January, February etc.)
%d Day of the month (01-31)
%e Day of the month (1-31)
%H Hour in 24-hour clock (00-23)
%I Hour in 12-hour clock (01-12)
%j Day of the year (001-366)
%m Month of the year (01-12)
%M Minute of the hour (00-59)
%p "a.m" or "p.m"
%S Second of the minute (00-61)
%T Same as %H:%M:%S
%u Weekday (1-7, 1 = Sunday)
%w Weekday (0-6, 0 = Sunday)
%Y Year (0000-9999)
%% The % character
And oh! \n may be used to demarcate multiple lines. multi-line text? we love to see it. ๐
๐ The text options ๐
-font <font>โ pick your font (defaultTimes Roman). Your options are:
Times-Roman
Times-Bold
Times-Italic
Times-BoldItalic
Helvetica
Helvetica-Bold
Helvetica-Oblique
Helvetica-BoldOblique
Courier
Courier-Bold
Courier-Oblique
Courier-BoldOblique
-font-size <n>โ sets the font size (default12pt).-load-ttf <name>=<filename>โ loads a truetype font and gives it a name you can then use with-font. For example-load-ttf A=NotoSans-Black.ttf. ๐๏ธ-embed-std14 <path>โ embeds the standard 14 fonts, given the path to the URW Base35 free fonts.-color <color>โ picks the text colour using one (Grey), three (RGB), or four (CMYK) numbers from 0-1. E.g-color โ0.5 0.4 0.5โ.-line-spacing <n>โ sets the spacing for multi-line text (default1).-outlineโ use outline text.-linewidth <n>โ line width for outline text.-underneathโ puts the text under the page instead of on top of it.-relative-to-cropboxโ positions are relative to the crop box rather than the media box.-prerotateโ removes any viewing rotation before adding the text.-no-warn-rotateโ do not warn about unresolved viewing rotation.-bates <n>โ sets the bates number for use with%Bates.-bates-at-range <n>โ sets the bates number for the first page in the range.-bates-pad-to <n>โ pads bates numbers to a given number of leading zeros.-opacity <n>โ sets text opacity. Wholly opaque is1, wholly transparent is0.-midlineโ position is relative to the midline of the text rather than the baseline.-toplineโ position is relative to the topline of the text rather than the baseline.-process-struct-treesโ maintains tagged PDF, for example with PDF/UA. The main file keeps its structure; the stamped text gets marked as an artifact.
๐ Positioning commands ๐
-pos-left โ<x> <y>โโ puts the left of the baseline of the text at (x, y).-pos-center โ<x> <y>โโ puts the center of the baseline of the text at (x, y).-pos-right โ<x> <y>โโ puts the right of the baseline of the text at (x, y).-top <n>โ baseline of the text,npts from the top middle of the page.-topleft <n>โ left of the baseline of the text,npts below and right of the top left of the page.-topleft โ<x> <y>โโ left of the baseline of the text,ypts below andxpts right of the top left of the page.-topright <n>โ right of the baseline of the text,npts below and left of the top right of the page.-topright โ<x> <y>โโ right of the baseline of the text,ypts below andxpts left of the top right of the page.-left <n>โ left of the baseline of the text,npts right of the left middle of the page.-bottomleft <n>โ left of the baseline of the text,npts up and right of the bottom left of the page.-bottomleft โ<x> <y>โโ left of the baseline of the text,ypts up andxpts right of the bottom left of the page.-bottom <n>โ center of the baseline of the text,npts up from the bottom middle of the page.-bottomright <n>โ right of the baseline of the text,npts up and left from the bottom right of the page.-bottomright โ<x> <y>โโ right of the baseline of the text,ypts up andxpts left from the bottom right of the page.-right <n>โ right of the baseline of the text,npts left of the center right of the page.-diagonalโ positions the text diagonally, bottom left to top right. โ๏ธ-reverse-diagonalโ positions the text diagonally, top left to bottom right. โ๏ธ-centerโ positions the text centered on the page. main character energy fr.-justify-leftโ left justification for multi-line text. Default depends upon position.-justify-rightโ right justification for multi-line text. Default depends upon position.-justify-centerโ center justification for multi-line text. Default depends upon position.
๐ง Removing the text you added ๐ง
cpdf -remove-text in.pdf [<range>] -o out.pdf
Removes text that was previously added by Cpdf. undo, but make it legal. โจ
๐ Low-level stuff ๐
cpdf -prepend-content <content> in.pdf [<range>] -o out.pdf
A low-level operation to prepend raw content to the beginning of page streams.
cpdf -postpend-content <content> in.pdf [<range>] -o out.pdf
A low-level operation to postpend raw content to the end of page streams.
cpdf -stamp-as-xobject stamp.pdf in.pdf [<range>] -o out.pdf
A low-level operation to add stamp.pdf as a Form XObject into the given pages of a PDF, and write its name to standard output. ๐
โจ 9. MULTIPAGE FACILITIES โจ
okay bestie, this is the section where we get โจfancyโจ โ padding, redacting, imposing, chopping. basically page-level glow-ups and page-level destruction. let's go ๐
๐ Padding: blank pages on purpose
cpdf [-pad-before | -pad-after] in.pdf [<range>] [-pad-with pad.pdf] -o
out.pdf
Add blank pages before or after each page in the given range. yes, every single page in that range gets a lil buddy. ๐ซถ
-pad-with <filename>โ Use a separate PDF to act as the padding. so instead of a boring empty page, your pad pages can be... literally anything. iconic.
๐ Padding, but on a schedule
cpdf -pad-every <n> in.pdf [-pad-with pad.pdf] -o out.pdf
Add a blank page after every n pages.
-pad-with <filename>โ Use a separate PDF to act as the padding. same deal as above, your padding can be a whole vibe of its own.
๐ Padding until the count is cute (a multiple, technically)
cpdf [-pad-multiple | -pad-multiple-before] [<n>] in.pdf -o out.pdf
Add as many blank pages as are required before or after the original pages to make the fileโs length a multiple of the given number of pages. it's giving "even numbers only" energy fr fr ๐
๐ -redact: the glow-down ๐
cpdf -redact in.pdf [<range>] [-process-struct-trees] -o out.pdf
Remove the content of the pages in the given range entirely, including annotations and any resources. not "hide", not "cover with a black box" โ gone. the pages stay, the contents do not. ๐ซฅ
-process-struct-treesโ Process the documentโs structure tree to remove any parts which are marked as relating to the now-redacted pages. so the document's own little map of itself doesn't still be pointing at stuff that no longer exists. thoughtful queen behavior ๐
๐ Imposition: many pages, one page
cpdf [-impose <pagesize> | impose-xy โ<x> <y>โ] in.pdf [-impose-columns]
[-impose-rtl] [-impose-btt] [-impose-margin <n>] [-impose-spacing <n>]
[-impose-linewidth <n>] [-fast] [-process-struct-trees] -o out.pdf
Cpdf has two imposition operations:
-imposefits multiple pages onto a given page size e.g-impose a4portraitor-impose โ8in 12inโ-impose-xybuilds an output page with the x pages horizontally and y pages vertically e.g-impose-xy โ2 3โ
so like, either you say "squish it onto this paper size" or you say "give me a grid, x by y, and I'll fill it". both slay. ๐
-impose-columnsโ Lay the pages out in columns rather than rows. plot twist: it's a grid but vertical now.-impose-rtlโ Lay the pages out right to left.-impose-bttโ Lay the pages out bottom to top.-impose-margin <n>โ Add a margin around the edge of each page. When using-impose-xythe page size increases; with-imposethe pages are scaled. so which one grows depends on which mode you picked, noted ๐-impose-spacing <n>โ Add spacing between rows and columns. When using-impose-xythe page size increases; with-imposethe pages are scaled. same rules as the margin, bestie.-impose-linewidth <n>โ Add a border around each input page. With-imposethe pages are scaled after the border is added, so you must account for this yourself. โ ๏ธ that's on you to do the math, she's not doing it for you.-process-struct-treesโ Mark the fileโs content as an artifact for the purposes of imposition.
๐ The two classic twoups (yes they're old, they still work)
cpdf -twoup-stack in.pdf [-fast] [-process-struct-trees] -o out.pdf
cpdf -twoup in.pdf [-fast] [-process-struct-trees] -o out.pdf
Two old imposition functions which can now both be done with -impose / -impose-xy. so like, they're the vintage versions, still serving looks ๐ฐ๏ธ
The -twoup-stack operation puts two logical pages on each physical page, rotating them 90 degrees to do so. The new mediabox is thus larger. Whereas the -twoup operation does the same, but scales the new sides down so that the media box is unchanged.
so: one makes the box bigger, the other shrinks the pages to fit. two paths, both valid ๐
-process-struct-treesโ Mark the fileโs content as an artifact for the purposes of imposition.
๐ -chop: page goes in, pages come out
cpdf -chop โ<x> <y>โ in.pdf [<range>] [-chop-columns] [-chop-rtl]
[-chop-btt] -o out.pdf
The -chop operation cuts up a page into multiple pages, according to the chosen grid. girlies are getting sliced โ๏ธโจ
-chop-columnsโ Arrange by columns instead of rows.-chop-rtlโ Arrange right to left.-chop-bttโ Arrange bottom to top.
๐ -chop-h / -chop-v: one cut, two pages
cpdf [-chop-h <y> | -chop-v <x>] in.pdf [<range>] [-chop-columns] -o
out.pdf
Chop each page into two, vertically or horizontally, at the given position. E.g -chop-h 200pt.
-chop-columnsโ Reverse the order of pages in the output.
๐ 10. ANNOTATIONS ๐
the little sticky notes, comments and highlights layer. we love her, we support her, we are also going to move her around a lot. ๐๏ธ
๐ Peeking at them
cpdf -list-annotations in.pdf [<range>]
List textual content of annotations to standard output. Each annotation is preceded by the page number and followed by a newline.
so it's a lil scroll of "page number, then the words, then a line break" over and over. simple, readable, obsessed ๐
๐ The same thing but ~JSON~
cpdf -list-annotations-json in.pdf [<range>]
List annotation objects in JSON format. This includes all ancillary objects, to support round-tripping. See cpdfmanual.pdf for full format details.
round-tripping means you can take it out and put it right back in without losing anything. no cap. ๐
๐ Putting annotations in from a file
cpdf -set-annotations <filename> in.pdf [<range>] [-underneath] -o
out.pdf
Set annotations from a JSON file. They will be added on top of any annotations already present.
-underneathโ Put the annotations underneath instead of on top of existing ones. shy annotation behavior, we respect it ๐
๐ Copying annotations between files
cpdf -copy-annotations from.pdf to.pdf [<range>] -o out.pdf
Copy annotations from from.pdf to to.pdf. yes the naming is exactly that literal, and honestly? thank u for the clarity bestie ๐ซถ
๐ Yeeting them
cpdf -remove-annotations in.pdf [<range>] -o out.pdf
Remove annotations from the document. all of them. in the range. bye ๐
๐ 11. DOCUMENT INFORMATION AND METADATA ๐
okay bestie, this is the โจreceiptsโจ section โ everything cpdf can tell you about a doc, and everything it can write into one. sit down, hydrate, we're going through it ๐
peep the info
cpdf -info[-json] in.pdf [-utf8] [-in | -cm | -mm]
Print info about a document in plain text (-info) or JSON (-info-json). For example:
cpdf -info pdf_reference.pdf
Encryption: Not encrypted
Permissions:
Linearized: true
Object streams: true
ID: <0b1f990718e2a92c0c112fbf08b233fb> <b2f1dbee369e11d9b951000393c97fd8>
Version: 1.5
Pages: 1236
Title: PDF Reference, version 1.6
Author: Adobe Systems Incorporated
Subject: Adobe Portable Document Format (PDF)
Keywords:
Creator: FrameMaker 7.0
Producer: Acrobat Distiller 6.0.1 for Macintosh
Created: D:20041114084116Z
Modified: D:20041114163850-08'00'
Trapped: False
PageMode: UseOutlines
PageLayout:
OpenAction: [1/XYZ -32768 -32768 1]
HideToolbar:
HideMenubar:
HideWindowUI:
FitWindow:
CenterWindow:
DisplayDocTitle: True
NonFullScreenPageMode:
AcroForm: False
XFA: False
Marked: False
UserProperties: False
Suspects: False
MediaBox: 0.000000 0.000000 612.000000 792.000000
CropBox: 41.000000 63.000000 572.000000 729.000000
BleedBox:
TrimBox: various
ArtBox: various
Subformats:
Language: en-us
XMP dc:title: PDF Reference, version 1.6
XMP dc:creator: Adobe Systems Incorporated
XMP dc:description: Adobe Portable Document Format (PDF)
like, that's the whole vibe of your file, laid bare. iconic.
-utf8โ Output in UTF8 format (plain text only)-in/-mm/-cmโ Output dimensions in inches, millimetres or centimetres instead of points.
page info, but per page
cpdf -page-info[-json] in.pdf [<range>] [-in | -cm | -mm]
List page information in plain (-page-info) or JSON (-page-info-json) format.
cpdf -page-info 14psfonts.pdf
Page 1:
Label: i
MediaBox: 0.000000 0.000000 600.000000 450.000000
CropBox: 200.000000 200.000000 500.000000 500.000000
BleedBox:
TrimBox:
ArtBox:
Rotation: 0
Annotations: 0
-in/-mm/-cmโ Output dimensions in inches, millimetres or centimetres instead of points.
how many pages tho
cpdf -pages in.pdf
Print the number of pages in the file. short, sweet, slay ๐
setting the metadata, one field at a time
cpdf -set-title <string> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-author <string> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-subject <string> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-keywords <string> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-creator <string> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-producer <string> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
Set metadata. yes queen, put your name on it ๐ซถ
dates
cpdf -set-create <date> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-modify <date> in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
Set creation or modification dates. See Appendix A of cpdfmanual.pdf for details of the PDF date format. (fr fr, go read the appendix, the date format is its own little beast ๐ญ)
trapped status
cpdf -set-trapped in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
cpdf -set-untrapped in.pdf [-also-set-xmp] [-just-set-xmp] -o out.pdf
Set the trapped status of a PDF.
-also-set-xmpโ Set the XMP metadata if the field is present, in addition to setting the old-style PDF metadata.-just-set-xmpโ Just set the XMP metadata, if the field is present, in addition to setting the old-style PDF metadata.
how it opens, how it looks
cpdf -set-page-layout <layout> in.pdf -o out.pdf
Set the page layout: one of SinglePage, OneColumn, TwoColumnLeft, TwoColumnRight, TwoPageLeft, TwoPageRight
cpdf -set-page-mode <mode> in.pdf -o out.pdf
Set the page mode: one of UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments.
cpdf -set-non-full-screen-page-mode <mode> in.pdf -o out.pdf
Set the non full screen mode for a PDF with FullScreen page mode: one of UseNone, UseOutlines, UseThumbs, UseAttachments.
cpdf -hide-toolbar <true | false> in.pdf -o out.pdf
Hide or reveal the viewer's toolbar.
cpdf -hide-menubar <true | false> in.pdf -o out.pdf
Hide or reveal the viewer's menubar.
cpdf -hide-window-ui <true | false> in.pdf -o out.pdf
Hide or reveal the window's scroll bars.
cpdf -fit-window <true | false> in.pdf -o out.pdf
Resize the document's windows to fit the size of the first page.
cpdf -center-window <true | false> in.pdf -o out.pdf
Position the document window in the center of the screen. main character energy, centered, as she deserves ๐
cpdf -display-doc-title <true | false> in.pdf -o out.pdf
Display the document title instead of the file name in the title bar.
open right here, bestie
cpdf -open-at-page <n> in.pdf -o out.pdf
Set the document to open at the given page number.
cpdf -open-at-page-fit <n> in.pdf -o out.pdf
Set the document to open at the given page number scaled to fit the window.
cpdf -open-at-page-custom <destination> in.pdf -o out.pdf
Set the document to open at a custom destination. See cpdfmanual.pdf for details.
language + XMP metadata
cpdf -set-language <language> in.pdf -o out.pdf
Set the document's global language, for example "en-US"
cpdf -set-metadata <filename> in.pdf -o out.pdf
Replace or add XMP metadata.
cpdf -remove-metadata in.pdf -o out.pdf
Remove the main XMP metadata stream.
cpdf -remove-all-metadata in.pdf -o out.pdf
Remove all XMP metadata streams. like, all of them. no survivors ๐ญ
cpdf -print-metadata in.pdf
Print the XMP metadata stream to standard output.
cpdf -extract-all-metadata in.pdf -o <path>
Extract XMP metadata streams to the given directory.
cpdf -create-metadata in.pdf -o out.pdf
Create or replace XMP metadata from old-style metadata.
cpdf -set-metadata-date <date> in.pdf -o out.pdf
Set the XMP metadata date. See Appendix A in cpdfmanual.pdf for date format details.
page labels โจ
cpdf -add-page-labels in.pdf [<range>] [-label-style <style>] [-label-prefix <string>] [-label-startval <n>] [-labels-progress] -o out.pdf
Add page labels to a PDF. Multiple calls may be used to add multiple ranges of page labels.
-label-styleโ One ofDecimalArabic,LowercaseRoman,UppercaseRoman,LowercaseLetters,UppercaseLetters,NoLabelPrefixOnly.-label-prefixโ The textual prefix for these labels.-label-startvalโ By default the labels begin at page number 1 for each range. To override this, we can use-label-startval.-labels-progressโ make sure the start value progresses between sub-ranges when the page range specified is disjoint, e.g "1-9, 30-40" or "odd".
cpdf -remove-page-labels in.pdf -o out.pdf
Remove the page labels.
cpdf -print-page-labels[-json] in.pdf
Print the page labels in plain text (-print-page-labels) or JSON (-print-page-labels-json) format.
what is this file even made of
cpdf -composition[-json] in.pdf
Print the composition of a PDF, showing how much space is taken by images, fonts etc.
cpdf -composition cpdfmanual.pdf
Images: 0 bytes (0.00%)
Fonts: 144731 bytes (46.72%)
Content streams: 132767 bytes (42.85%)
Structure Info: 0 bytes (0.00%)
Attached Files: 0 bytes (0.00%)
XRef Table: 21082 bytes (6.80%)
Piece Info: 0 bytes (0.00%)
Unclassified: 11229 bytes (3.62%)
look at those fonts EATING up 46.72% of the file. fonts really said "this is my moment" ๐
๐ 12. FILE ATTACHMENTS ๐
tucking extra files inside your PDF? yes. very "I brought snacks for everyone" energy. ๐
attach a file
cpdf -attach-file <filename> in.pdf [-to-page <n>] [-afd <string>] [-afr <relationship>] [-attach-file ...] -o out.pdf
Attach a file to a PDF, given its filename.
-to-page <n>โ Instead of attaching globally, add it as an attachment on a single page.-afd <string>โ Supply the textual description for this attachment.-afr <relationship>โ Supply the so-called Relationship for this attachment.
and yes bestie, you can stack it โ -attach-file ... again and again to pile more on ๐
what's in there
cpdf -list-attached-files in.pdf [-json] [-include-data]
List attached files.
-jsonโ List attached files in JSON format. Seecpdfmanual.pdffor full details.-include-dataโ Include the attachment file data when listing in JSON format.
cleaning house
cpdf -remove-files in.pdf -o out.pdf
Remove attached files from a PDF.
cpdf -dump-attachments in.pdf -o <path>
Extract the attachments to a given directory.
okay so that's the metadata-and-attachments of it all โ and there's still more coming, don't you dare close the tab ๐ธ
๐ผ๏ธ 13. IMAGES ๐ผ๏ธ
okay bestie, images!! this whole section is about finding, listing, extracting, and squishing the pictures inside your PDF ๐
cpdf -list-images[-json] in.pdf [<range>] [-inline]
This one lists the images in a file, and it spills ALL the tea: their object number, page numbers, image name, width, height, size in bytes, bits per pixel, colour space, compression method, mask type and mask object number ๐ You can get it in plain text with -list-images or as JSON with -list-images-json.
-inlineโ also list inline images. (yes, those sneaky ones ๐ซถ)
cpdf -list-images-used[-json] in.pdf [<range>] [-inline]
cpdf -image-resolution[-json] <n> in.pdf [<range>] [-inline]
The -list-images-used and -list-images-used-json operations list the images at point of use with their page number, image name, width in pixels, height in pixels, x resolution, y resolution and object number โจ If you use -image-resolution or -image-resolution-json instead, it reports only such images as do not reach a minimum resolution.
-inlineโ also list inline images.
cpdf -extract-images in.pdf [<range>] [-im <path>] [-p2p <path>] [-dedup
| -dedup-perpage] [-raw] [-inline] [-merge-masks] -o <path>
Extract images to a given path, e.g "output/%%%", which would create output/001.jpg, output/002.png and so on ๐
JPEG, JPEG2000 and lossless JBIG2 images are extracted directly. Lossy JBIG2 images are extracted in sections. Other images are written as PNGs, processed with ImageMagick.
-im <path>โ provide path to ImageMagick.-p2p <path>โ provide path to pnmtopng if ImageMagick not available.-dedupโ deduplicate images, extracting only once even if multiply-included.-dedup-per-pageโ deduplicate images, but only per-page.-rawโ output.pnmfiles instead of.png.-inlineโ also extract inline images.-merge-masksโ merge soft masks with their images when extracting.
cpdf -extract-single-image <object number> in.pdf [-im <path>] [-p2p
<path>] [-raw] [-merge-masks] -o <filename>
Extract a single image, given its object number ๐ฏ Other flags as above.
cpdf -process-images in.pdf [<range>] [-process-images-info]
[-process-images-force] [-im <filename>] [-jbig2enc <filename>]
[-jbig2dec <filename>] [-lossless-resample[-dpi] <n> | -lossless-to-jpeg
<n>] [-jpeg-to-jpeg <n>] [-jpeg-to-jpeg-scale <n>]
[-lossless-to-jpeg2000 <n>] [-jpeg2000-to-jpeg2000 <n>]
[-jpeg-to-jpeg-dpi <n>] [-1bpp-method <method>] [-jbig2-lossy-threshold
<n>] [-pixel-threshold <n>] [-length-threshold <n>]
[-percentage-threshold <n>] [-dpi-threshold <n>] [-resample-interpolate]
-o out.pdf
Re-process existing images within the PDF, typically to reduce size ๐ For a full commentary, see cpdfmanual.pdf.
-process-images-infoโ show the work being done.-process-images-forceโ process image even when size would increase.-im <path>โ supply path to ImageMagick.-jbig2enc <path>โ supply path to jbig2enc.-jbig2dec <path>โ supply path to jbig2dec.-lossless-resample <n>โ resample lossless images to the given percentage scale.-lossless-resample-dpi <n>โ resample lossless images to a given DPI resolution.-lossless-to-jpeg <n>โ convert lossless images to JPEG at the given quality level.-jpeg-to-jpeg <n>โ reprocess JPEG images to the given quality level.-jpeg-to-jpeg-scale <n>โ reprocess JPEG images to the given percentage scale.-jpeg-to-jpeg-dpi <n>โ reprocess JPEG images to the given DPI resolution.-lossless-to-jpeg2000 <n>โ convert lossless images to JPEG 2000 at the given quality level.-jpeg2000-to-jpeg2000 <n>โ reprocess JPEG 2000 images to the given quality level.-1bpp-method <1bppmethod>โ specify method for 1bpp images. One ofJBIG2Lossy,JBIG2Lossless,CCITT,CCITTG4.-jbig2-lossy-threshold <n>โ set the threshold for lossy JBIG2 compression.-pixel-threshold <n>โ images below this number of pixels not processed (default25).-length-threshold <n>โ images with less than this number of bytes not processed (default100).-percentage-threshold <n>โ results not below this percentage of original size discarded (default90).-dpi-threshold <n>โ only image above this threshold at all use points processed (default no dpi threshold).-resample-interpolateโ use interpolation when resampling.
cpdf -rasterize in.pdf [<range>] [-gs <path>] [-rasterize[-gray | -1bpp
| -jpeg | -jpeggray]] [-rasterize-res <n>] [-rasterize-jpeg-quality <n>]
[-rasterize-no-antialias | -rasterize-downsample] [-rasterize-annots]
[-rasterize-alpha] -o out.pdf
Rasterize each page, replacing the page content with the rasterized version in the output PDF ๐ฅ
-gs <path>โ supply path to gs.-rasterize-grayโ use grayscale instead of colour.-rasterize-1bppโ use monochrome instead of colour.-rasterize-jpegโ use JPEG instead of lossless compression.-rasterize-jpeggrayโ use grayscale JPEG instead of lossless compression.-rasterize-res <n>โ set the resolution (default144dpi).-rasterize-jpeg-quality <n>โ set JPEG image quality (0..100).-rasterize-no-antialiasโ turn off anti-aliasing.-rasterize-downsampleโ use better but slower anti-aliasing.-rasterize-annotsโ rasterize annotations instead of retaining.-rasterize-alphaโ produce an alpha channel (lossless only)
cpdf -output-image in.pdf [<range>] [-gs <path>] [-rasterize[-gray |
-1bpp | -jpeg | -jpeggray] [-rasterize-res <n>] [-rasterize-jpeg-quality
<n>] [-rasterize-no-antialias | -rasterize-downsample]
[-rasterize-annots] [-rasterize-alpha] [-tobox <boxname>] -o <format>
Output rasterized images for each page to the given folder and format, e.g "dir/%%%.png" would create dir/001.png and so on โจ Options as above and:
-tobox <boxname>โ specify the box to rasterize (default/MediaBox).
๐ 14. FONTS ๐
cpdf -list-fonts[-json] in.pdf
List the fonts on each page in a file together with their types ๐ Either in plain text (-list-fonts) or JSON (-list-fonts-json) format.
cpdf -print-font-table <font name> in.pdf [-print-font-table-page <n>]
Print a font table for a given font name and page, e.g:
cpdf -print-font-table /XYPLPB+NimbusSanL-Bold -print-font-table-page 2 cpdfmanual.pdf
67 = U+0043 (C - LATIN CAPITAL LETTER C) = /C
68 = U+0044 (D - LATIN CAPITAL LETTER D) = /D
70 = U+0046 (F - LATIN CAPITAL LETTER F) = /F
71 = U+0047 (G - LATIN CAPITAL LETTER G) = /G
...
cpdf -copy-font fromfile.pdf in.pdf [<range>] -copy-font-page <n>
-copy-font-name <name> -o out.pdf
A low-level operation to copy a font from one file to another ๐ง
-copy-font-page <n>โ the page from which to copy the font.-copy-font-name <n>โ the (PDF) name of the font.
cpdf -remove-fonts in.pdf -o out.pdf
Remove fonts from a file. (yeah, just. gone ๐)
cpdf -missing-fonts in.pdf
Report missing fonts โ i.e those which are unembedded ๐
cpdf -embed-missing-fonts -gs <path to gs> in.pdf -o out.pdf
Use gs to embed missing fonts into a PDF.
โ ๏ธ Note: putting a PDF file through gs in this manner may not be lossless: some metadata may not be preserved. fr fr, be careful bestie ๐ญ
cpdf -extract-font <n>,<pdf font name> in.pdf -o out.font
Extract a font file from a PDF given a page number, font name pair, e.g:
cpdf -extract-font 5,/F50 in.pdf -o out.ttf
๐ฆ 15. PDF AND JSON ๐ฆ
cpdf in.pdf -output-json [-output-json-parse-content-streams]
[-output-json-no-stream-data] [-output-json-decompress-streams]
[-output-json-clean-strings] [-utf8] -o out.json
Convert PDF to a JSON format which may be inspected, or edited and round-tripped back into PDF ๐
-output-json-parse-content-streamsโ parse the content streams into JSON too.-output-json-no-stream-dataโ elide stream data. This makes a smaller file, but bars round-tripping.-output-json-decompress-streamsโ keep the streams intact, and decompress them.-output-json-clean-stringsโ deprecated in favour of-utf8below.-utf8โ use UTF8 rather than PDFDocEncoding for strings, to make them more easily editable.
cpdf -j in.json -o out.pdf
Convert a JSON file to a PDF file โจ
๐ 16. OPTIONAL CONTENT GROUPS ๐
cpdf -ocg-list in.pdf
List the optional content groups in the PDF, one per line, to standard output ๐
cpdf -ocg-rename in.pdf -ocg-rename-from <a> -ocg-rename-to <b> -o
out.pdf
Rename an optional content group given the old and new names ๐
cpdf -ocg-order-all in.pdf -o out.pdf
Ensure that every optional content group appears in the order list โจ
cpdf -ocg-coalesce-on-name in.pdf -o out.pdf
Coalesce optional content groups. For example, if we merge or stamp two files both with an OCG called "Layer 1", we will have two different optional content groups. This command will merge them into a single optional content group ๐ซถ
โจ 17. CREATING NEW PDFS โจ
okay bestie, ready to manifest some brand new PDFs from the void? ๐ this section is all about making files out of thin air, turning text into pages, and even wrangling weird image formats. let's get into it.
cpdf -create-pdf [-create-pdf-pages <n>] [-create-pdf-papersize <papersize>] -o out.pdf
Create a new PDF (default: one page, A4 portrait).
-create-pdf-pages <n>โ Give the number of pages.-create-pdf-papersize <papersize>โ Give the paper size, e.g โa3landscapeโ or โ200pt 600ptโ
cpdf -typeset <filename> [-create-pdf-papersize <papersize>] [-font <font>] [-font-size <n>] [-subformat <subformat>] [-title <string>] -o out.pdf
Typeset a text file into a PDF.
-create-pdf-papersize <papersize>โ Give the paper size.-font <font>โ The font (default Times-Roman)-font-size <n>โ The font size (default 12pt)-subformat <subformat>โ Specify PDF/UA-1 or PDF/UA-2 to make a conforming file.-title <string>โ Specify a title when using-subformatfor a PDF/UA file.
cpdf -jpeg <filename> [-subformat <subformat>] [-title <string>] -o out.pdf
cpdf -png <filename> [-subformat <subformat>] [-title <string>] -o out.pdf
cpdf -jpeg2000 <filename> [-subformat <subformat>] [-title <string>] -o out.pdf
Build a PDF from an image file (JPEG, PNG or JPEG2000).
-subformat <subformat>โ Specify PDF/UA-1 or PDF/UA-2 to make a conforming file.-title <string>โ Specify a title when using-subformatfor a PDF/UA file.
cpdf [-jbig2-global <filename>] -jbig2 <filename> [-jbig2-global | -jbig2-global-clear] [-jbig2 <filename>] ... [-subformat <subformat>] [-title <string>] -o out.pdf
Make a multi-page PDF from one or more PDF-appropriate JBIG2 fragments prepared by the jbig2enc program. For example, in lossless mode:
cpdf -jbig2 1.jbig2 -jbig2 2.jbig2 -jbig2 3.jbig2 -o out.pdf
In lossy mode, jbig2globals segments may be specified:
cpdf -jbig2-global 0.jbig2globals -jbig2 1.jbig2 -jbig2 2.jbig2 -jbig2 3.jbig2 -o out.pdf
-jbig2-global <filename>โ Change thejbig2globalsegment in use.-jbig2-global-clearโ Cease use ofjbig2globalsegment, and return to lossless mode.-subformat <subformat>โ Specify PDF/UA-1 or PDF/UA-2 to make a conforming file.-title <string>โ Specify a title when using-subformatfor a PDF/UA file.
๐จ 18. DRAWING ON PDFS ๐จ
now we're getting artsy. this is where you literally draw on top of (or underneath) a PDF. so fun. ๐๏ธโจ
cpdf in.pdf [<range>] [-draw-struct-tree] -draw <draw operations> [-underneath] -o out.pdf
Draw on a PDF. See cpdfmanual.pdf for a tutorial, and full information.
-draw-struct-treeโ Produce structure information.-underneathโ Draw underneath instead of on top of any existing page content.
cpdf -text-width <string> [-font <font>] [-fontsize <n>]
Return the width of a string of text in a one of the standard 14 fonts. Used for calculations of text position (e.g right-alignment).
-font <font>โ Specify the font.-fontsize <n>โ Specify the font size.
โ๏ธ Building and showing paths โ๏ธ
-rect โx y w hโโ Draw rectangle.-to โx yโโ Move to.-line โx yโโ Add line to path.-bez โx1 y1 x2 y2 x3 y3โโ Add Bezier curve to path.-bez23 โx2 y2 x3 y3โโ Add Bezier curve to path.-bez13 โx1 y1 x3 y3โโ Add Bezier curve to path.-circle โx y rโโ Add circle to path.-strokeโ Stroke path.-fillโ Fill path.-filleoโ Fill path, even odd.-strokefillโ Stroke and fill path.-strokefilleoโ Stroke and fill path, even odd.-closeโ Close path.
โ๏ธ Clipping with paths โ๏ธ
-clipโ Clip.-clipeoโ Clip, even odd.
๐จ Path parameters ๐จ
-strokecol โgโ | โr g bโ | โc y m kโ | <namedcolour>โ Set stroke colour.-fillcol โgโ | โr g bโ | โc y m kโ | <namedcolour>โ Set fill colour.-thick <n>โ Set stroke thickness.-cap <butt | round | square>โ Set cap.-join <miter | round | bevel>โ Set join.-miter <n>โ Set miter limit.-dash <pattern>โ Set dash pattern.
๐งฎ The graphics stack and matrices ๐งฎ
-pushโ Push graphics stack.-popโ Pop graphics stack.-matrix โa b c d e fโโ Append to graphics matrix.-mtrans โtx tyโโ Translate the graphics matrix.-mrot โx y aโโ Rotate the graphics matrix.-mscale โx y sx syโโ Scale the graphics matrix.-mshearx โx y aโโ Shear the graphics matrix in X.-msheary โx y aโโ Shear the graphics matrix in Y.
๐ Re-use with XObjects ๐
-xobj-bbox โx y w hโโ Specify the bounding box for xobjects.-xobj <name>โ Begin saving a sequence of graphics operators.-end-xobjโ End saving a sequence of graphics operators.-use <name>โ Use a saved sequence of graphics operators.
๐ผ๏ธ Images ๐ผ๏ธ
-draw-jpeg <name>=<filename>โ Load a JPEG from file and name it.-draw-png <name>=<filename>โ Load a PNG from file and name it.-draw-jpeg2000 <name>=<filename>โ Load a JPEG2000 from file and name it.-image <name>โ Draw an image which has already been loaded.
๐ซฅ Transparency ๐ซฅ
-fill-opacity <n>โ Set opacity.-stroke-opacity <n>โ Set stroke opacity.
๐ Text ๐
-btโ Begin text.-etโ End text.-text <string>โ Draw text.-stext <string>โ Draw text with%specials.-para <paragraph>โ Typeset a paragraph.-paras <paragraph>โ Typeset multiple paragraphs.-indent <n>โ Set paragraph indent.-leading <n>โ Set leading.-charspace <n>โ Set character spacing.-wordspace <n>โ Set word space.-textscale <n>โ Set text scale.-rendermode <n>โ Set text rendering mode.-rise <n>โ Set text rise.-nlโ New line.
โก๏ธ The Next Page โก๏ธ
-newpageโ Move to a fresh page.
๐๏ธ Structure Information ๐๏ธ
-draw-struct-treeโ Add structure information. Must precede-drawon command line.-tag <name>โ Begin marked content.-end-tagโ End marked content.-stag <name>โ Begin structure tree branch.-end-stagโ End structure tree branch.-auto-tagsโ Automatically tag paragraphs and images.-no-auto-tagsโ Refrain from automatically tagging paragraphs and images.-artifactโ Begin manual artifact.-end-artifactโ End manual artifact.-no-auto-artifactsโ Prevent automatic addition of artifacts during post-processing.-namespace <namespace>โ Set the namespace for future branches of the tree.-eltinfo <elt=string>โ Set element information.-end-eltinfoโ Erase element information.-rolemap <rolemap>โ Set role map.
โฟ 19. ACCESSIBLE PDFS WITH PDF/UA โฟ
making your PDFs accessible is such a slay. ๐ this section is all about PDF/UA, structure trees, and making sure everyone can read your stuff. let's go.
cpdf -print-struct-tree in.pdf
Print a PDFโs structure tree to standard output for inspection.
cpdf -extract-struct-tree in.pdf -o out.json
Extract the whole structure tree in JSON format. See cpdfmanual.pdf for details.
cpdf -replace-struct-tree in.json in.pdf -o out.pdf
Replace a PDFโs structure tree with one from a JSON file.
cpdf -remove-struct-tree in.pdf -o out.pdf
Remove the structure tree from a file.
cpdf -mark-as-artifact in.pdf -o out.pdf
Mark all the content of the file as being an artifact.
cpdf -verify โPDF/UA-1(matterhorn)โ in.pdf [-verify-single <test>] [-json]
Verify conformance with PDF/UA-1.
-jsonโ Output conformance failures in JSON rather than plain text format.-verify-single <test>โ Verify just one test. Seecpdfmanual.pdffor list of tests.
cpdf -mark-as [โPDF/UA-1โ | โPDF/UA-2โ] in.pdf -o out.pdf
Mark a PDF as conforming to PDF/UA-1 or PDF/UA-2
cpdf -remove-mark [โPDF/UA-1โ | โPDF/UA-2โ] in.pdf -o out.pdf
Remove conformance marker from a PDF.
cpdf -create-pdf-ua-<1 | 2> <string> [-create-pdf-pages <n>] [-create-pdf-papersize <papersize>] -o out.pdf
Create a new, blank, PDF/UA-1 or PDF/UA-2 file with the given title.
-create-pdf-pages <n>โ Give the number of pages.-create-pdf-papersize <papersize>โ Give the paper size, e.g โa3landscapeโ or โ200pt 600ptโ
๐ฆ 20. MISCELLANEOUS ๐ฆ
Okay bestie, this is the โจeverything elseโจ section โ the little grab-bag of chaos where cpdf keeps all the odds and ends that didn't fit anywhere else. Buckle up, it's a long one ๐
๐ผ๏ธ Yeeting the photos
cpdf -draft in.pdf [<range>] [-boxes] [-draft-remove-only <n>] -o out.pdf
This one removes bit-mapped (photographic) images from a PDF. Like, gone. Bye. Not the vibes you need if you're printing a rough draft and don't wanna burn through ink ๐จ๏ธ๐
-boxesโ instead of just deleting each image, it drops a crossed box in its place so you can literally see where it used to be. Helpful for "wait, what was there?"-draft-remove-onlyโ removes only one image, the one with the given name. And where do you get that name, you ask? From stuff like-list-images-used, bestie. That's the plug ๐
๐ค Stripping and recolouring text
cpdf -remove-all-text in.pdf [<range>] -o out.pdf
Removes all text from a PDF. All of it. Every last glyph. No cap ๐ซข
cpdf -blacktext in.pdf [<range>] -o out.pdf
Makes all text black. Simple as. ๐ค
cpdf -blacklines in.pdf [<range>] -o out.pdf
Makes all lines black. ๐ค
cpdf -blackfills in.pdf [<range>] -o out.pdf
Makes all fills black. ๐ค
๐ Line thickness shenanigans
cpdf -thinlines <min thickness> in.pdf [<range>] -o out.pdf
This makes every line at minimum the thickness you give it. But here's the tea: if you pass a negative value, it does the opposite โ it thins lines down to the absolute value of whatever you typed. So if you run it twice, once with a positive number and then once with a negative one, you can literally clamp your thicknesses into a range, or even snap everything to one single value. Iconic behaviour honestly ๐
๐งผ The deprecated one (rip)
cpdf -clean in.pdf -o out.pdf
Deprecated! This work is now done by default whenever cpdf writes any file. So likeโฆ you don't need to call it. It's giving legacy. But it's still here if you're feeling nostalgic ๐
๐ข Setting the version
cpdf -set-version <version number> in.pdf -o out.pdf
Sets the version of a PDF. Watch out for the math though, it's a lil quirky:
- For version
1.4, you use-set-version 4. - For PDF versions starting with 2, you add ten to the number. So for PDF
2.0, you'd use-set-version 10.
Don't ask why, just vibe with it ๐
๐ ID stuff
cpdf -copy-id-from source.pdf in.pdf -o out.pdf
Copies the ID from one PDF to another. Stealing the identity, but make it legal ๐
cpdf -remove-id in.pdf -o out.pdf
Removes the ID from a PDF entirely. Poof, gone โจ
๐ Spot colours
cpdf -list-spot-colors in.pdf
Lists the names of any separation colour spaces hanging out in your PDF. Very niche, very slay.
๐งฌ Dictionary entry surgery (low level, proceed with care)
cpdf -print-dict-entry <key> in.pdf [-json]
cpdf -remove-dict-entry <key> in.pdf [-dict-entry-search <term>] -o out.pdf
cpdf -replace-dict-entry <key> -replace-dict-entry-value <value> in.pdf [-dict-entry-search <term>] -o out.pdf
These are low level operations that edit PDF objects directly. That's the deep end, bestie โ you're poking at the actual guts of the file. For the full details, go read cpdfmanual.pdf. ๐
โ๏ธ Clipping, be gone
cpdf -remove-clipping in.pdf [<range>] -o out.pdf
Removes any clipping paths from a PDF. No more being contained by the system ๐ฆ
๐งฐ Object-level operations (the real deep end)
cpdf -obj[-json] <object specification> in.pdf
cpdf -replace-obj <object specification>=<object> in.pdf -o out.pdf
cpdf -remove-obj <object number> in.pdf -o out.pdf
cpdf -extract-stream[-decompress] <object specification> in.pdf -o out.dat
cpdf -replace-stream <object specification> -replace-stream-with <filename> in.pdf -o out.pdf
These are low level operations to explore and edit PDF files object-by-object. Like, literally one object at a time. This is surgeon hours ๐ฌ For details, again: cpdfmanual.pdf. ๐ซถ
๐ต๏ธ JavaScript check
cpdf -contains-javascript in.pdf
Prints true if the PDF contains JavaScript, and false if it doesn't. A little vibe check for sneaky scripts ๐
cpdf -remove-javascript in.pdf -o out.pdf
Removes JavaScript from a PDF. Scrubbing the place clean ๐งฝโจ
๐ธ ENVIRONMENT ๐ธ
These are the lil environment variables that change how cpdf behaves. Set them and watch the magic happen ๐ช
CPDF_SHOW_EXTโ shows the command line of external commands as they get called, if it's equal toโtrueโ.CPDF_DEBUGโ does the exact same thing as adding-debugto the command line, if it's equal toโtrueโ.CPDF_REPRODUCIBLE_DATESโ expands the dataโnowโto the same, false value every single time, if it's equal toโtrueโ.CAMLPDF_REPRODUCIBLE_IDSโ produces the same file ID each time, if it's equal toโtrueโ.
๐ญ BUGS ๐ญ
Found a bug? Spill the tea here:
- https://github.com/johnwhitington/cpdf-source/issues
- or email contact@coherentgraphics.co.uk
We love a report, fr fr ๐ซถ
๐ AUTHORS ๐
Coherent Graphics Ltd. โ the masterminds behind all this. Absolute main character energy โจ
And that's a wrap on the whole cpdf(1) page, bestie!! ๐ You just read every last section and I'm so proud of you. This lil slice came from the February 2026 edition of the manual, and the page is filed under CPDF(1) โ so if you ever need to find it again, that's your girl ๐
Go forth and PDF like the icon you are. Slay. Periodt. ๐ ๐ฆ๐ธ
๐ฆ where this page comes from
- epel 10: cpdf 2.9-2.el10_3 ยท AGPL-3.0-only and ISC and BSD-3-Clause and CC-BY-4.0 and Unicode-DFS-2015
- epel 9: cpdf 2.9-2.el9 ยท AGPL-3.0-only and ISC and BSD-3-Clause and CC-BY-4.0 and Unicode-DFS-2015
- fedora 43: cpdf 2.9-1.fc43 ยท AGPL-3.0-only and ISC and BSD-3-Clause and CC-BY-4.0 and Unicode-DFS-2015
- fedora 44: cpdf 2.9-1.fc44 ยท AGPL-3.0-only and ISC and BSD-3-Clause and CC-BY-4.0 and Unicode-DFS-2015
- ubuntu stonking: cpdf 2.9-1build1 ยท AGPL-3.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms