Outline for remove_struct_tree

This commit is contained in:
John Whitington
2025-03-10 13:36:45 +00:00
parent 502f51b671
commit 38e7573350
5 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,9 @@
2.9 (to come)
New features:
* -remove-struct-tree removes whole structure tree
Extended features:
o -obj JSON output

View File

@ -229,6 +229,7 @@ type op =
| PrintStructTree
| ExtractStructTree
| ReplaceStructTree of string
| RemoveStructTree
| SetLanguage of string
| Redact
| Rasterize
@ -385,6 +386,7 @@ let string_of_op = function
| PrintStructTree -> "PrintStructTree"
| ExtractStructTree -> "ExtractStructTree"
| ReplaceStructTree _ -> "ReplaceStructTree"
| RemoveStructTree -> "RemoveStructTree"
| SetLanguage _ -> "SetLanguage"
| Redact -> "Redact"
| Rasterize -> "Rasterize"
@ -959,7 +961,7 @@ let banned banlist = function
| OCGRename | OCGList | OCGOrderAll | PrintFontEncoding _ | TableOfContents | Typeset _ | Composition _
| TextWidth _ | SetAnnotations _ | CopyAnnotations _ | ExtractStream _ | ReplaceStream _ | PrintObj _ | ReplaceObj _
| Verify _ | MarkAs _ | RemoveMark _ | ExtractStructTree | ReplaceStructTree _ | SetLanguage _
| PrintStructTree | Rasterize | OutputImage
| PrintStructTree | Rasterize | OutputImage | RemoveStructTree
-> false (* Always allowed *)
(* Combine pages is not allowed because we would not know where to get the
-recrypt from -- the first or second file? *)
@ -4891,6 +4893,10 @@ let go () =
let json = Cpdfyojson.Safe.from_file s in
Cpdfua.replace_struct_tree pdf json;
write_pdf false pdf
| Some RemoveStructTree ->
let pdf = get_single_pdf args.op false in
Cpdfua.remove_struct_tree pdf;
write_pdf false pdf
| Some (SetLanguage s) ->
let pdf = get_single_pdf args.op false in
Cpdfmetadata.set_language pdf s;

Binary file not shown.

View File

@ -1850,3 +1850,5 @@ let create_pdfua2 title pagesize pages =
let pdf = {pdf with Pdf.major = 2; Pdf.minor = 0} in
mark2 2024 pdf;
pdf
let remove_struct_tree pdf = ()

View File

@ -31,6 +31,9 @@ val extract_struct_tree : Pdf.t -> Cpdfyojson.Safe.t
(** Reapply an edited JSON structure tree to its PDF. *)
val replace_struct_tree : Pdf.t -> Cpdfyojson.Safe.t -> unit
(** Remove a structure tree entirely from a file, including unmarking marked content. *)
val remove_struct_tree : Pdf.t -> unit
(** Make a blank PDF/UA-1 PDF given a title, paper size, and number of pages. *)
val create_pdfua1 : string -> Pdfpaper.t -> int -> Pdf.t