This commit is contained in:
John Whitington 2020-07-21 12:28:32 +01:00
parent 17a3d959ba
commit 1305853bd8
4 changed files with 44 additions and 5 deletions

View File

@ -7,6 +7,7 @@ o New -labels-progress option to improve page labels interface
o New options -output-json et al. to export PDF files in JSON format o New options -output-json et al. to export PDF files in JSON format
o New option -stamp-as-xobject to add one PDF as an xobject in another o New option -stamp-as-xobject to add one PDF as an xobject in another
o No longer depends on Bigarray or Unix modules o No longer depends on Bigarray or Unix modules
o Appearance streams transformed when transforming annotations
Version 2.3 (patchlevel 1, December 2019) Version 2.3 (patchlevel 1, December 2019)

View File

@ -3,12 +3,13 @@ MODS = tjutil tjutf16 tjllist tjparserMonad tjjson \
xmlm \ xmlm \
cpdfwriteJSON cpdfstrftime cpdfcoord cpdf cpdfcommand cpdfwriteJSON cpdfstrftime cpdfcoord cpdf cpdfcommand
SOURCES = cpdftime.c $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml SOURCES = $(foreach x,$(MODS),$(x).ml $(x).mli) cpdfcommandrun.ml
RESULT = cpdf RESULT = cpdf
ANNOTATE = true ANNOTATE = true
PACKS = camlpdf PACKS = unix camlpdf
CFLAGS = -fPIC
OCAMLFLAGS = -bin-annot OCAMLFLAGS = -bin-annot
OCAMLNCFLAGS = -g -safe-string -w -3 OCAMLNCFLAGS = -g -safe-string -w -3
OCAMLBCFLAGS = -g -safe-string -w -3 OCAMLBCFLAGS = -g -safe-string -w -3

37
cpdf.ml
View File

@ -2287,6 +2287,10 @@ let change_pattern_matrices_page pdf tr page =
page page
| _ -> page | _ -> page
(* test *)
let transform_xobject_in_place pdf transform i =
Printf.printf "transforming xobject %i as part of annotation\n" i
(* Apply transformations to any annotations in /Annots (i.e their /Rect entries) *) (* Apply transformations to any annotations in /Annots (i.e their /Rect entries) *)
let transform_annotations pdf transform rest = let transform_annotations pdf transform rest =
(*Printf.printf "in transform_annotations\n";*) (*Printf.printf "in transform_annotations\n";*)
@ -2313,8 +2317,37 @@ let transform_annotations pdf transform rest =
Pdf.Array [Pdf.Real minx; Pdf.Real miny; Pdf.Real maxx; Pdf.Real maxy] Pdf.Array [Pdf.Real minx; Pdf.Real miny; Pdf.Real maxx; Pdf.Real maxy]
| None -> raise (Pdf.PDFError "transform_annotations: no rect") | None -> raise (Pdf.PDFError "transform_annotations: no rect")
in in
let annot' = Pdf.add_dict_entry annot "/Rect" rect' in let ap' =
Pdf.addobj_given_num pdf (i, annot') match Pdf.lookup_direct pdf "/AP" annot with
None -> None
| Some dict -> Some dict
in
let annot = Pdf.add_dict_entry annot "/Rect" rect' in
begin match ap' with
None -> ()
| Some (Pdf.Dictionary dict) ->
(* Each entry in the dictionary is either
* a) an indirect reference to a stream Form XObject
* b) a direct or indirect dictionary with some entries,
* each of which is an indirect reference to a stream. *)
(* We do this in place. *)
List.iter
(fun (k, v) ->
match v with
Pdf.Indirect i -> transform_xobject_in_place pdf transform i
| _ -> let dict = Pdf.lookup_direct pdf k (Pdf.Dictionary dict) in
match dict with Some (Pdf.Dictionary dict) ->
List.iter
(fun (_, v) ->
match v with
Pdf.Indirect i -> transform_xobject_in_place pdf transform i
| _ -> Printf.eprintf "Malformed /AP structure b"; ())
dict
| _ -> Printf.eprintf "Malformed /AP structure c"; ())
dict
| _ -> Printf.eprintf "Malformed /AP structure\n"; ()
end;
Pdf.addobj_given_num pdf (i, annot)
| _ -> Printf.eprintf "transform_annotations: not indirect") | _ -> Printf.eprintf "transform_annotations: not indirect")
annots annots
| _ -> () | _ -> ()

View File

@ -20,7 +20,11 @@ let rec json_of_object pdf fcs no_stream_data = function
| P.Dictionary elts -> | P.Dictionary elts ->
iter iter
(function (function
("/Contents", P.Indirect i) -> fcs i ("/Contents", P.Indirect i) ->
begin match Pdf.lookup_obj pdf i with
| Pdf.Array is -> iter (function Pdf.Indirect i -> fcs i | _ -> ()) is
| _ -> fcs i
end
| ("/Contents", P.Array elts) -> iter (function P.Indirect i -> fcs i | _ -> ()) elts | ("/Contents", P.Array elts) -> iter (function P.Indirect i -> fcs i | _ -> ()) elts
| _ -> ()) | _ -> ())
elts; elts;