This commit is contained in:
John Whitington 2023-02-20 12:56:59 +00:00
parent 3bb87b6352
commit c803c9e511
5 changed files with 34 additions and 39 deletions

View File

@ -200,7 +200,7 @@ let get_annotations_json pdf =
let json = `List (flatten (map2 (annotations_json_page pdf) pages pagenums)) in
Pdfio.bytes_of_string (J.to_string json)
(** Set annotations from JSON. Existing annotations will be removed. *)
(** Set annotations from JSON. Existing annotations? *)
let set_annotations_json pdf json = ()
(* Equalise the page lengths of two PDFs by chopping or extending the first one.

View File

@ -3369,15 +3369,6 @@ let prerotate range pdf =
Cpdfpage.upright ~fast:args.fast range pdf
let embed_font () =
let fontpack_of_standardfont sf =
let te = Pdftext.text_extractor_of_font_real sf in
let table = null_hash () in
for x = 0 to 255 do
let u = hd (Pdftext.codepoints_of_text te (string_of_char (char_of_int x))) in
Hashtbl.add table u (0, x)
done;
([sf], table)
in
match args.font with
| StandardFont f ->
(* FIXME proper error handling for missing file etc. *)
@ -3394,7 +3385,7 @@ let embed_font () =
e -> error (Printf.sprintf "Can't load font for embedding: %s\n" (Printexc.to_string e))
end
| None ->
PreMadeFontPack (fontpack_of_standardfont (Pdftext.StandardFont (f, args.fontencoding)))
PreMadeFontPack (Cpdfembed.fontpack_of_standardfont (Pdftext.StandardFont (f, args.fontencoding)))
end
| OtherFont f ->
ExistingNamedFont

View File

@ -8,6 +8,15 @@ type cpdffont =
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding}
| ExistingNamedFont
let fontpack_of_standardfont sf =
let te = Pdftext.text_extractor_of_font_real sf in
let table = null_hash () in
for x = 0 to 255 do
let u = hd (Pdftext.codepoints_of_text te (string_of_char (char_of_int x))) in
Hashtbl.add table u (0, x)
done;
([sf], table)
let get_char (fonts, table) u =
match Hashtbl.find table u with
| (n, charcode) -> Some (charcode, n, List.nth fonts n)

View File

@ -15,6 +15,8 @@ type cpdffont =
| EmbedInfo of {fontfile : Pdfio.bytes; fontname : string; encoding : Pdftext.encoding}
| ExistingNamedFont
val fontpack_of_standardfont : Pdftext.font -> t
val get_char : t -> int -> (int * int * Pdftext.font) option
val embed_truetype :

View File

@ -234,16 +234,9 @@ let squeeze ?logto ?(pagedata=true) ?(recompress=true) pdf =
end;
if recompress then
begin
ignore (decompress_pdf pdf);
log (Printf.sprintf "Recompressing document\n");
let n = !Pdfcodec.flate_level in
Pdfcodec.flate_level := 9;
ignore (recompress_pdf pdf);
Pdfcodec.flate_level := n
end
else
(* Re-compress processed pagedata, even if recompress not set *)
if pagedata then ignore (recompress_pdf pdf)
with
e ->
raise