Begin work on -composition

This commit is contained in:
John Whitington 2023-03-03 16:02:16 +00:00
parent df16849a04
commit b3951da415
3 changed files with 17 additions and 2 deletions

View File

@ -8,6 +8,7 @@ o Embed the 14 standard fonts if requested
o Add links to parts of text with -add-text as %URL[|]. o Add links to parts of text with -add-text as %URL[|].
o Convert JPEGs and PNGs to PDFs with -jpeg and -png o Convert JPEGs and PNGs to PDFs with -jpeg and -png
o Export fully, import, and round-trip annotations via JSON o Export fully, import, and round-trip annotations via JSON
o Show composition of PDF with -composition and -composition-json
Extended features: Extended features:

View File

@ -221,6 +221,7 @@ type op =
| TableOfContents | TableOfContents
| Typeset of string | Typeset of string
| Draw | Draw
| Composition of bool
let string_of_op = function let string_of_op = function
| PrintFontEncoding _ -> "PrintFontEncoding" | PrintFontEncoding _ -> "PrintFontEncoding"
@ -352,6 +353,7 @@ let string_of_op = function
| TableOfContents -> "TableOfContents" | TableOfContents -> "TableOfContents"
| Typeset _ -> "Typeset" | Typeset _ -> "Typeset"
| Draw -> "Draw" | Draw -> "Draw"
| Composition _ -> "Composition"
(* Inputs: filename, pagespec. *) (* Inputs: filename, pagespec. *)
type input_kind = type input_kind =
@ -828,7 +830,7 @@ let banned banlist = function
| SetModify _|SetCreator _|SetProducer _|RemoveDictEntry _ | ReplaceDictEntry _ | PrintDictEntry _ | SetMetadata _ | SetModify _|SetCreator _|SetProducer _|RemoveDictEntry _ | ReplaceDictEntry _ | PrintDictEntry _ | SetMetadata _
| ExtractText | ExtractImages | ExtractFontFile | ExtractText | ExtractImages | ExtractFontFile
| AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce | AddPageLabels | RemovePageLabels | OutputJSON | OCGCoalesce
| OCGRename | OCGList | OCGOrderAll | PrintFontEncoding _ | TableOfContents | Typeset _ | OCGRename | OCGList | OCGOrderAll | PrintFontEncoding _ | TableOfContents | Typeset _ | Composition _
-> false (* Always allowed *) -> false (* Always allowed *)
(* Combine pages is not allowed because we would not know where to get the (* Combine pages is not allowed because we would not know where to get the
-recrypt from -- the first or second file? *) -recrypt from -- the first or second file? *)
@ -866,7 +868,7 @@ let rec decrypt_if_necessary (_, _, user_pw, owner_pw, was_dec_with_owner, _) op
if not (Pdfcrypt.is_encrypted pdf) then pdf else if not (Pdfcrypt.is_encrypted pdf) then pdf else
match op with Some (CombinePages _) -> match op with Some (CombinePages _) ->
(* This is a hack because we don't have support for recryption on combine (* This is a hack because we don't have support for recryption on combine
* pages. This is pervented by permissions above, but in the case that the * pages. This is prevented by permissions above, but in the case that the
* owner password is blank (e.g christmas_tree_lights.pdf), we would end * owner password is blank (e.g christmas_tree_lights.pdf), we would end
* up here. *) * up here. *)
soft_error "Combine pages: both files must be unencrypted for this operation, or add -decrypt-force" soft_error "Combine pages: both files must be unencrypted for this operation, or add -decrypt-force"
@ -2804,6 +2806,12 @@ and specs =
("-typeset", ("-typeset",
Arg.String settypeset, Arg.String settypeset,
" Typeset a text file as a PDF"); " Typeset a text file as a PDF");
("-composition",
Arg.Unit (setop (Composition false)),
" Show composition of PDF");
("-composition-json",
Arg.Unit (setop (Composition true)),
" Show composition of PDF in JSON format");
(* Creating new PDF content *) (* Creating new PDF content *)
("-draw", Arg.Unit (setop Draw), " Begin drawing"); ("-draw", Arg.Unit (setop Draw), " Begin drawing");
("-rect", Arg.String addrect, " Draw rectangle"); ("-rect", Arg.String addrect, " Draw rectangle");
@ -3368,6 +3376,8 @@ let warn_prerotate range pdf =
let prerotate range pdf = let prerotate range pdf =
Cpdfpage.upright ~fast:args.fast range pdf Cpdfpage.upright ~fast:args.fast range pdf
let show_composition json pdf = ()
let embed_font () = let embed_font () =
match args.font with match args.font with
| StandardFont f -> | StandardFont f ->
@ -4348,6 +4358,9 @@ let go () =
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in
write_pdf false (Cpdfdraw.draw args.fast range pdf (rev (Hashtbl.find drawops "_"))) write_pdf false (Cpdfdraw.draw args.fast range pdf (rev (Hashtbl.find drawops "_")))
| Some (Composition json) ->
let pdf = get_single_pdf args.op false in
show_composition json pdf
(* Advise the user if a combination of command line flags makes little sense, (* Advise the user if a combination of command line flags makes little sense,
or error out if it make no sense at all. *) or error out if it make no sense at all. *)

View File

@ -5,6 +5,7 @@
%Document -list-annotations[-json] now obey page range %Document -list-annotations[-json] now obey page range
%Document round-tripping of annotations, supersede -copy-annotations. %Document round-tripping of annotations, supersede -copy-annotations.
%Document -utf for JSON and mark -clean-strings as deprecated since can fail to round-trip binary strings which begin with a BOM? %Document -utf for JSON and mark -clean-strings as deprecated since can fail to round-trip binary strings which begin with a BOM?
%Document -composition[-json]
\documentclass{book} \documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf,
% dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc. % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.