This commit is contained in:
John Whitington 2021-12-21 11:12:52 +00:00
parent 6616516f77
commit a9bfd16142
7 changed files with 26 additions and 50 deletions

View File

@ -1,6 +1,6 @@
# Build the cpdf command line tools and top level # Build the cpdf command line tools and top level
MODS = cpdfyojson cpdfxmlm \ MODS = cpdfyojson cpdfxmlm \
cpdfunicodedata cpdferror cpdfjson cpdfstrftime cpdfcoord cpdfattach \ cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord cpdfattach \
cpdfpagespec cpdfposition cpdfpresent cpdfmetadata cpdf cpdffont cpdftype \ cpdfpagespec cpdfposition cpdfpresent cpdfmetadata cpdf cpdffont cpdftype \
cpdftexttopdf cpdftoc cpdfpad cpdfocg cpdfsqueeze cpdfspot cpdfpagelabels cpdfcreate cpdfcommand cpdftexttopdf cpdftoc cpdfpad cpdfocg cpdfsqueeze cpdfspot cpdfpagelabels cpdfcreate cpdfcommand

28
cpdf.ml
View File

@ -8,34 +8,6 @@ type color =
| RGB of float * float * float | RGB of float * float * float
| CYMK of float * float * float * float | CYMK of float * float * float * float
let debug = ref false
(* Get the number of pages in file. Doesn't need decryption. *)
let endpage_io ?revision i user_pw owner_pw =
let pdf = Pdfread.pdf_of_input_lazy ?revision user_pw owner_pw i in
Pdfpage.endpage pdf
let print_pdf_objs pdf =
Printf.printf "Trailerdict: %s\n" (Pdfwrite.string_of_pdf pdf.Pdf.trailerdict);
Printf.printf "Root: %i\n" pdf.Pdf.root;
begin match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
| Some catalog ->
Printf.printf "Catalog: %s\n" (Pdfwrite.string_of_pdf catalog);
begin match Pdf.lookup_direct pdf "/Pages" catalog with
| Some pages ->
Printf.printf "Pages: %s\n" (Pdfwrite.string_of_pdf pages)
| None ->
flprint "no catalog\n"
end
| None ->
flprint "No catalog!\n"
end;
Pdf.objiter
(fun n obj ->
Printf.printf "%i 0 obj:\n\n" n;
Printf.printf "%s\n" (Pdfwrite.string_of_pdf obj))
pdf
(* Return page label at pdf page num, or page number in arabic if no label *) (* Return page label at pdf page num, or page number in arabic if no label *)
let pagelabel pdf num = let pagelabel pdf num =
Pdfpagelabels.pagelabeltext_of_pagenumber Pdfpagelabels.pagelabeltext_of_pagenumber

View File

@ -1,23 +1,13 @@
(** Coherent PDF Tools Core Routines *) (** Coherent PDF Tools Core Routines *)
open Pdfutil open Pdfutil
type color = type color =
Grey of float Grey of float
| RGB of float * float * float | RGB of float * float * float
| CYMK of float * float * float * float | CYMK of float * float * float * float
(** {2 Debug} *)
(** Debug: Print out a PDF in readable form to the terminal *)
val print_pdf_objs : Pdf.t -> unit
(** {2 Working with pages} *) (** {2 Working with pages} *)
(** Like [Pdfpage.endpage], but from an input and possible password - does the
minimal work to find the number of pages. *)
val endpage_io : ?revision:int -> Pdfio.input -> string option -> string option -> int
(** Given a function from page number and page to page, a document, and a list (** Given a function from page number and page to page, a document, and a list
of page numbers to apply it to, apply the function to all those pages. *) of page numbers to apply it to, apply the function to all those pages. *)
val process_pages : (int -> Pdfpage.t -> Pdfpage.t * int * Pdftransform.transform_matrix) -> val process_pages : (int -> Pdfpage.t -> Pdfpage.t * int * Pdftransform.transform_matrix) ->
@ -46,8 +36,6 @@ val add_bookmarks : json:bool -> bool -> Pdfio.input -> Pdf.t -> Pdf.t
output in the format specified in cpdfmanual.pdf *) output in the format specified in cpdfmanual.pdf *)
val list_bookmarks : json:bool -> Cpdfmetadata.encoding -> int list -> Pdf.t -> Pdfio.output -> unit val list_bookmarks : json:bool -> Cpdfmetadata.encoding -> int list -> Pdf.t -> Pdfio.output -> unit
(** {2 Stamping} *) (** {2 Stamping} *)
(** [combine_pages fast under over scaletofit swap equalize] combines the page (** [combine_pages fast under over scaletofit swap equalize] combines the page
@ -207,7 +195,6 @@ val trim_marks : ?fast:bool -> Pdf.t -> int list -> Pdf.t
val show_boxes : ?fast:bool -> Pdf.t -> int list -> Pdf.t val show_boxes : ?fast:bool -> Pdf.t -> int list -> Pdf.t
(** {2 Annotations} *) (** {2 Annotations} *)
(** List the annotations to standard output in a given encoding. See cpdfmanual.pdf for the format details. *) (** List the annotations to standard output in a given encoding. See cpdfmanual.pdf for the format details. *)
@ -252,15 +239,12 @@ val blackfills : color -> int list -> Pdf.t -> Pdf.t
(** Remove images from a PDF, optionally adding crossed boxes. *) (** Remove images from a PDF, optionally adding crossed boxes. *)
val draft : string option -> bool -> int list -> Pdf.t -> Pdf.t val draft : string option -> bool -> int list -> Pdf.t -> Pdf.t
val remove_all_text : int list -> Pdf.t -> Pdf.t val remove_all_text : int list -> Pdf.t -> Pdf.t
(**/**) (**/**)
val process_xobjects : Pdf.t -> Pdfpage.t -> (Pdf.t -> Pdf.pdfobject -> Pdf.pdfobject list -> Pdf.pdfobject list) -> unit val process_xobjects : Pdf.t -> Pdfpage.t -> (Pdf.t -> Pdf.pdfobject -> Pdf.pdfobject list -> Pdf.pdfobject list) -> unit
val debug : bool ref
val extract_text : float option -> Pdf.t -> int list -> string val extract_text : float option -> Pdf.t -> int list -> string
val append_page_content : string -> bool -> bool -> int list -> Pdf.t -> Pdf.t val append_page_content : string -> bool -> bool -> int list -> Pdf.t -> Pdf.t
@ -279,8 +263,6 @@ val image_resolution : Pdf.t -> int list -> float -> (int * string * int * int *
val copy_box : string -> string -> bool -> Pdf.t -> int list -> Pdf.t val copy_box : string -> string -> bool -> Pdf.t -> int list -> Pdf.t
val add_bookmark_title : string -> bool -> Pdf.t -> Pdf.t val add_bookmark_title : string -> bool -> Pdf.t -> Pdf.t
val remove_unused_resources : Pdf.t -> Pdf.t val remove_unused_resources : Pdf.t -> Pdf.t
@ -296,5 +278,3 @@ val name_of_spec : Cpdfmetadata.encoding ->
val extract_images : string -> val extract_images : string ->
string -> string ->
Cpdfmetadata.encoding -> bool -> bool -> Pdf.t -> int list -> string -> unit Cpdfmetadata.encoding -> bool -> bool -> Pdf.t -> int list -> string -> unit

View File

@ -1298,7 +1298,6 @@ let setdebug () =
set Pdfwrite.write_debug; set Pdfwrite.write_debug;
set Pdfcrypt.crypt_debug; set Pdfcrypt.crypt_debug;
set Pdfops.debug; set Pdfops.debug;
set Cpdf.debug;
args.debug <- true args.debug <- true
let setdebugcrypt () = let setdebugcrypt () =

View File

@ -1,3 +1,5 @@
open Pdfutil
let blank_document width height pages = let blank_document width height pages =
let pdf_pages = let pdf_pages =
map (fun () -> Pdfpage.blankpage (Pdfpaper.make Pdfunits.PdfPoint width height)) (many () pages) map (fun () -> Pdfpage.blankpage (Pdfpaper.make Pdfunits.PdfPoint width height)) (many () pages)

22
cpdfdebug.ml Normal file
View File

@ -0,0 +1,22 @@
open Pdfutil
let print_pdf_objs pdf =
Printf.printf "Trailerdict: %s\n" (Pdfwrite.string_of_pdf pdf.Pdf.trailerdict);
Printf.printf "Root: %i\n" pdf.Pdf.root;
begin match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
| Some catalog ->
Printf.printf "Catalog: %s\n" (Pdfwrite.string_of_pdf catalog);
begin match Pdf.lookup_direct pdf "/Pages" catalog with
| Some pages ->
Printf.printf "Pages: %s\n" (Pdfwrite.string_of_pdf pages)
| None ->
flprint "no catalog\n"
end
| None ->
flprint "No catalog!\n"
end;
Pdf.objiter
(fun n obj ->
Printf.printf "%i 0 obj:\n\n" n;
Printf.printf "%s\n" (Pdfwrite.string_of_pdf obj))
pdf

1
cpdfdebug.mli Normal file
View File

@ -0,0 +1 @@
val print_pdf_objs : Pdf.t -> unit