From a9bfd161423849cd090e06995e03954330e03834 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 21 Dec 2021 11:12:52 +0000 Subject: [PATCH] more --- Makefile | 2 +- cpdf.ml | 28 ---------------------------- cpdf.mli | 20 -------------------- cpdfcommand.ml | 1 - cpdfcreate.ml | 2 ++ cpdfdebug.ml | 22 ++++++++++++++++++++++ cpdfdebug.mli | 1 + 7 files changed, 26 insertions(+), 50 deletions(-) create mode 100644 cpdfdebug.ml create mode 100644 cpdfdebug.mli diff --git a/Makefile b/Makefile index 8ef69d4..6d81aaa 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Build the cpdf command line tools and top level MODS = cpdfyojson cpdfxmlm \ - cpdfunicodedata cpdferror cpdfjson cpdfstrftime cpdfcoord cpdfattach \ + cpdfunicodedata cpdferror cpdfdebug cpdfjson cpdfstrftime cpdfcoord cpdfattach \ cpdfpagespec cpdfposition cpdfpresent cpdfmetadata cpdf cpdffont cpdftype \ cpdftexttopdf cpdftoc cpdfpad cpdfocg cpdfsqueeze cpdfspot cpdfpagelabels cpdfcreate cpdfcommand diff --git a/cpdf.ml b/cpdf.ml index 5e7dc99..8c79dcc 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -8,34 +8,6 @@ type color = | RGB of 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 *) let pagelabel pdf num = Pdfpagelabels.pagelabeltext_of_pagenumber diff --git a/cpdf.mli b/cpdf.mli index 8a59b3d..fd3036b 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -1,23 +1,13 @@ (** Coherent PDF Tools Core Routines *) open Pdfutil - type color = Grey of float | RGB of 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} *) -(** 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 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) -> @@ -46,8 +36,6 @@ val add_bookmarks : json:bool -> bool -> Pdfio.input -> Pdf.t -> Pdf.t output in the format specified in cpdfmanual.pdf *) val list_bookmarks : json:bool -> Cpdfmetadata.encoding -> int list -> Pdf.t -> Pdfio.output -> unit - - (** {2 Stamping} *) (** [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 - (** {2 Annotations} *) (** 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. *) val draft : string option -> bool -> 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 debug : bool ref - val extract_text : float option -> Pdf.t -> int list -> string 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 add_bookmark_title : string -> bool -> 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 -> string -> Cpdfmetadata.encoding -> bool -> bool -> Pdf.t -> int list -> string -> unit - - diff --git a/cpdfcommand.ml b/cpdfcommand.ml index eb8c18e..e11744b 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1298,7 +1298,6 @@ let setdebug () = set Pdfwrite.write_debug; set Pdfcrypt.crypt_debug; set Pdfops.debug; - set Cpdf.debug; args.debug <- true let setdebugcrypt () = diff --git a/cpdfcreate.ml b/cpdfcreate.ml index 9fc39fc..6c13cab 100644 --- a/cpdfcreate.ml +++ b/cpdfcreate.ml @@ -1,3 +1,5 @@ +open Pdfutil + let blank_document width height pages = let pdf_pages = map (fun () -> Pdfpage.blankpage (Pdfpaper.make Pdfunits.PdfPoint width height)) (many () pages) diff --git a/cpdfdebug.ml b/cpdfdebug.ml new file mode 100644 index 0000000..5c025ad --- /dev/null +++ b/cpdfdebug.ml @@ -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 diff --git a/cpdfdebug.mli b/cpdfdebug.mli new file mode 100644 index 0000000..aa62ce3 --- /dev/null +++ b/cpdfdebug.mli @@ -0,0 +1 @@ +val print_pdf_objs : Pdf.t -> unit