Support for PDF/UA-2 markers

This commit is contained in:
John Whitington 2024-06-26 15:34:45 +01:00
parent ab7073cad8
commit b0c630d822
3 changed files with 17 additions and 3 deletions

View File

@ -4502,11 +4502,15 @@ let go () =
let pdf = get_single_pdf args.op false in
Cpdfua.mark pdf;
write_pdf false pdf
| "PDF/UA-2" ->
let pdf = get_single_pdf args.op false in
Cpdfua.mark2 2024 pdf;
write_pdf false pdf
| _ -> error "Unknown standard"
end
| Some (RemoveMark standard) ->
begin match standard with
| "PDF/UA-1" ->
| "PDF/UA-1" | "PDF/UA-2" ->
let pdf = get_single_pdf args.op false in
Cpdfua.remove_mark pdf;
write_pdf false pdf

View File

@ -1351,6 +1351,10 @@ let test_matterhorn_json pdf testname =
let pdfua_marker =
Cpdfmetadata.(E (((rdf, "Description"), [((rdf, "about"), ""); ((Cpdfxmlm.ns_xmlns, "pdfuaid"), pdfuaid)]), [E (((pdfuaid, "part"), []), [D "1"])]))
let pdfua2_marker year =
Cpdfmetadata.(E (((rdf, "Description"), [((rdf, "about"), ""); ((Cpdfxmlm.ns_xmlns, "pdfuaid"), pdfuaid)]), [E (((pdfuaid, "part"), []), [D "2"]);
E (((pdfuaid, "rev"), []), [D (string_of_int year)])]))
let rec insert_as_rdf_description fragment = function
| Cpdfmetadata.E (((_, "RDF"), _) as rdftag, rdfs) ->
Cpdfmetadata.E (rdftag, fragment::rdfs)
@ -1360,7 +1364,7 @@ let rec insert_as_rdf_description fragment = function
let rec delete_pdfua_marker tree =
let is_pdfuaid = function
| Cpdfmetadata.E (((pdfuaid, "part"), _), _) when pdfuaid = Cpdfmetadata.pdfuaid -> true
| Cpdfmetadata.E (((pdfuaid, ("part" | "rev" | "amd" | "corr")), _), _) when pdfuaid = Cpdfmetadata.pdfuaid -> true
| _ -> false
in
match tree with
@ -1370,7 +1374,7 @@ let rec delete_pdfua_marker tree =
Cpdfmetadata.E (x, map delete_pdfua_marker children)
| x -> x
let mark pdf =
let mark_inner pdfua_marker pdf =
let pdf2 = if Cpdfmetadata.get_metadata pdf = None then Cpdfmetadata.create_metadata pdf else pdf in
pdf.Pdf.objects <- pdf2.Pdf.objects;
pdf.Pdf.trailerdict <- pdf2.Pdf.trailerdict;
@ -1390,6 +1394,10 @@ let mark pdf =
pdf.Pdf.root <- pdf3.Pdf.root
| None -> assert false
let mark = mark_inner pdfua_marker
let mark2 year = mark_inner (pdfua2_marker year)
let remove_mark pdf =
match Cpdfmetadata.get_metadata pdf with
| Some metadata ->

View File

@ -5,6 +5,8 @@ val test_matterhorn_json : Pdf.t -> string -> Cpdfyojson.Safe.t
val mark : Pdf.t -> unit
val mark2 : int -> Pdf.t -> unit
val remove_mark : Pdf.t -> unit
val extract_struct_tree : Pdf.t -> Cpdfyojson.Safe.t