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 option -stamp-as-xobject to add one PDF as an xobject in another
o No longer depends on Bigarray or Unix modules
o Appearance streams transformed when transforming annotations
Version 2.3 (patchlevel 1, December 2019)

View File

@ -3,12 +3,13 @@ MODS = tjutil tjutf16 tjllist tjparserMonad tjjson \
xmlm \
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
ANNOTATE = true
PACKS = camlpdf
PACKS = unix camlpdf
CFLAGS = -fPIC
OCAMLFLAGS = -bin-annot
OCAMLNCFLAGS = -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
(* 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) *)
let transform_annotations pdf transform rest =
(*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]
| None -> raise (Pdf.PDFError "transform_annotations: no rect")
in
let annot' = Pdf.add_dict_entry annot "/Rect" rect' in
Pdf.addobj_given_num pdf (i, annot')
let ap' =
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")
annots
| _ -> ()

View File

@ -20,7 +20,11 @@ let rec json_of_object pdf fcs no_stream_data = function
| P.Dictionary elts ->
iter
(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
| _ -> ())
elts;