tidying
This commit is contained in:
parent
9c5a905cc7
commit
962e27dd14
|
@ -6,7 +6,7 @@ type color =
|
||||||
| RGB of float * float * float
|
| RGB of float * float * float
|
||||||
| CYMK of float * float * float * float
|
| CYMK of float * float * float * float
|
||||||
|
|
||||||
(* \section{Superimpose text, page numbers etc.} *)
|
(* Superimpose text, page numbers etc. *)
|
||||||
|
|
||||||
(* Process UTF8 text to /WinAnsiEncoding string (for standard 14) or whatever
|
(* Process UTF8 text to /WinAnsiEncoding string (for standard 14) or whatever
|
||||||
is in the font (for existing fonts). *)
|
is in the font (for existing fonts). *)
|
||||||
|
|
|
@ -206,7 +206,7 @@ let list_attached_files pdf =
|
||||||
in
|
in
|
||||||
toplevel @ pagelevel
|
toplevel @ pagelevel
|
||||||
|
|
||||||
(* \section{Remove Attached files} *)
|
(* Remove Attached files *)
|
||||||
let remove_attached_files_on_pages pdf =
|
let remove_attached_files_on_pages pdf =
|
||||||
let remove_from_page page =
|
let remove_from_page page =
|
||||||
{page with Pdfpage.rest =
|
{page with Pdfpage.rest =
|
||||||
|
@ -301,4 +301,3 @@ let dump_attached_files pdf out =
|
||||||
iter (dump_attached_page pdf out) (Pdfpage.pages_of_pagetree pdf)
|
iter (dump_attached_page pdf out) (Pdfpage.pages_of_pagetree pdf)
|
||||||
with
|
with
|
||||||
e -> error (Printf.sprintf "Couldn't dump attached files: %s\n" (Printexc.to_string e))
|
e -> error (Printf.sprintf "Couldn't dump attached files: %s\n" (Printexc.to_string e))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
open Pdfio
|
open Pdfio
|
||||||
|
|
||||||
(* \section{Making draft documents} *)
|
(* Making draft documents *)
|
||||||
|
|
||||||
(* Predicate on an xobject: true if an image xobject. *)
|
(* Predicate on an xobject: true if an image xobject. *)
|
||||||
let isimage pdf (_, xobj) =
|
let isimage pdf (_, xobj) =
|
||||||
|
|
|
@ -56,7 +56,7 @@ let xmp_template =
|
||||||
|
|
||||||
<?xpacket end='r'?>|}
|
<?xpacket end='r'?>|}
|
||||||
|
|
||||||
(* \section{Set or replace metadata} *)
|
(* Set or replace metadata *)
|
||||||
let set_metadata_from_bytes keepversion data pdf =
|
let set_metadata_from_bytes keepversion data pdf =
|
||||||
let metadata_stream =
|
let metadata_stream =
|
||||||
Pdf.Stream
|
Pdf.Stream
|
||||||
|
@ -94,9 +94,7 @@ let set_metadata keepversion filename pdf =
|
||||||
done;
|
done;
|
||||||
set_metadata_from_bytes keepversion data pdf
|
set_metadata_from_bytes keepversion data pdf
|
||||||
|
|
||||||
|
(* Remove metadata *)
|
||||||
|
|
||||||
(* \section{Remove metadata} *)
|
|
||||||
let remove_metadata pdf =
|
let remove_metadata pdf =
|
||||||
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
||||||
| None -> error "malformed file"
|
| None -> error "malformed file"
|
||||||
|
@ -108,6 +106,7 @@ let remove_metadata pdf =
|
||||||
Pdf.add_dict_entry pdf.Pdf.trailerdict "/Root" (Pdf.Indirect rootnum);
|
Pdf.add_dict_entry pdf.Pdf.trailerdict "/Root" (Pdf.Indirect rootnum);
|
||||||
Pdf.root =
|
Pdf.root =
|
||||||
rootnum}
|
rootnum}
|
||||||
|
|
||||||
(* Print metadata *)
|
(* Print metadata *)
|
||||||
let get_metadata pdf =
|
let get_metadata pdf =
|
||||||
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
||||||
|
@ -353,8 +352,7 @@ let set_pdf_info_xml_many changes value xmldata pdf =
|
||||||
changes;
|
changes;
|
||||||
!xmldata
|
!xmldata
|
||||||
|
|
||||||
|
(* Set an entry in the /Info dictionary *)
|
||||||
(* \section{Set an entry in the /Info dictionary} *)
|
|
||||||
|
|
||||||
(* We must parse the date to get its components, then use strftime to build the
|
(* We must parse the date to get its components, then use strftime to build the
|
||||||
* new string in XMP format *)
|
* new string in XMP format *)
|
||||||
|
@ -528,7 +526,7 @@ let set_metadata_date pdf date =
|
||||||
pdf
|
pdf
|
||||||
|
|
||||||
|
|
||||||
(* \section{Copy an /ID from one file to another} *)
|
(* Copy an /ID from one file to another *)
|
||||||
let copy_id keepversion copyfrom copyto =
|
let copy_id keepversion copyfrom copyto =
|
||||||
match Pdf.lookup_direct copyfrom "/ID" copyfrom.Pdf.trailerdict with
|
match Pdf.lookup_direct copyfrom "/ID" copyfrom.Pdf.trailerdict with
|
||||||
| None -> copyto (* error "Source PDF file has no /ID entry to copy from" *)
|
| None -> copyto (* error "Source PDF file has no /ID entry to copy from" *)
|
||||||
|
@ -559,7 +557,7 @@ let create_metadata pdf =
|
||||||
(replacements pdf);
|
(replacements pdf);
|
||||||
set_metadata_from_bytes false (bytes_of_string !xmp) pdf
|
set_metadata_from_bytes false (bytes_of_string !xmp) pdf
|
||||||
|
|
||||||
(* \section{Set viewer preferences} *)
|
(* Set viewer preferences *)
|
||||||
let set_viewer_preference (key, value, version) pdf =
|
let set_viewer_preference (key, value, version) pdf =
|
||||||
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
match Pdf.lookup_direct pdf "/Root" pdf.Pdf.trailerdict with
|
||||||
| Some catalog ->
|
| Some catalog ->
|
||||||
|
@ -584,9 +582,7 @@ let set_viewer_preference (key, value, version) pdf =
|
||||||
Pdf.trailerdict = trailerdict'}
|
Pdf.trailerdict = trailerdict'}
|
||||||
| None -> error "bad root"
|
| None -> error "bad root"
|
||||||
|
|
||||||
|
(* Set page layout *)
|
||||||
|
|
||||||
(* \section{Set page layout} *)
|
|
||||||
let set_page_layout pdf s =
|
let set_page_layout pdf s =
|
||||||
match s with
|
match s with
|
||||||
| "SinglePage" | "OneColumn" | "TwoColumnLeft"
|
| "SinglePage" | "OneColumn" | "TwoColumnLeft"
|
||||||
|
@ -607,8 +603,7 @@ let set_page_layout pdf s =
|
||||||
end
|
end
|
||||||
| _ -> error "Unknown page layout"
|
| _ -> error "Unknown page layout"
|
||||||
|
|
||||||
|
(* Set page mode *)
|
||||||
(* \section{Set page mode} *)
|
|
||||||
let set_page_mode pdf s =
|
let set_page_mode pdf s =
|
||||||
match s with
|
match s with
|
||||||
| "UseNone" | "UseOutlines" | "UseThumbs"
|
| "UseNone" | "UseOutlines" | "UseThumbs"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
open Pdfutil
|
open Pdfutil
|
||||||
|
|
||||||
(* \section{Padding with blank pages.} *)
|
(* Padding with blank pages. *)
|
||||||
let insert_after pos page pages =
|
let insert_after pos page pages =
|
||||||
let before, after = cleave pages pos in
|
let before, after = cleave pages pos in
|
||||||
before @ [page] @ after
|
before @ [page] @ after
|
||||||
|
|
12
cpdfpage.ml
12
cpdfpage.ml
|
@ -97,7 +97,7 @@ let shift_page ?(fast=false) dxdylist pdf pnum page =
|
||||||
let shift_pdf ?(fast=false) dxdylist pdf range =
|
let shift_pdf ?(fast=false) dxdylist pdf range =
|
||||||
process_pages (shift_page ~fast dxdylist pdf) pdf range
|
process_pages (shift_page ~fast dxdylist pdf) pdf range
|
||||||
|
|
||||||
(* \section{Shift page data} *)
|
(* Shift page data *)
|
||||||
let make_mediabox (xmin, ymin, xmax, ymax) =
|
let make_mediabox (xmin, ymin, xmax, ymax) =
|
||||||
Pdf.Array
|
Pdf.Array
|
||||||
[Pdf.Real xmin; Pdf.Real ymin; Pdf.Real xmax; Pdf.Real ymax]
|
[Pdf.Real xmin; Pdf.Real ymin; Pdf.Real xmax; Pdf.Real ymax]
|
||||||
|
@ -183,7 +183,7 @@ let scale_page_contents ?(fast=false) scale position pdf pnum page =
|
||||||
let scale_contents ?(fast=false) position scale pdf range =
|
let scale_contents ?(fast=false) position scale pdf range =
|
||||||
process_pages (scale_page_contents ~fast scale position pdf) pdf range
|
process_pages (scale_page_contents ~fast scale position pdf) pdf range
|
||||||
|
|
||||||
(* \section{Set media box} *)
|
(* Set media box *)
|
||||||
let set_mediabox xywhlist pdf range =
|
let set_mediabox xywhlist pdf range =
|
||||||
let crop_page pnum page =
|
let crop_page pnum page =
|
||||||
let x, y, w, h = List.nth xywhlist (pnum - 1) in
|
let x, y, w, h = List.nth xywhlist (pnum - 1) in
|
||||||
|
@ -287,7 +287,7 @@ let upright ?(fast=false) range pdf =
|
||||||
in
|
in
|
||||||
process_pages (upright_page pdf) pdf range
|
process_pages (upright_page pdf) pdf range
|
||||||
|
|
||||||
(* \section{Rotating pages} *)
|
(* Rotating pages *)
|
||||||
let rotate_pdf r pdf range =
|
let rotate_pdf r pdf range =
|
||||||
let rotate_page _ page =
|
let rotate_page _ page =
|
||||||
{page with Pdfpage.rotate =
|
{page with Pdfpage.rotate =
|
||||||
|
@ -325,7 +325,7 @@ let rotate_page_contents ~fast rotpoint r pdf pnum page =
|
||||||
let rotate_contents ?(fast=false) r pdf range =
|
let rotate_contents ?(fast=false) r pdf range =
|
||||||
process_pages (rotate_page_contents ~fast None r pdf) pdf range
|
process_pages (rotate_page_contents ~fast None r pdf) pdf range
|
||||||
|
|
||||||
(* \section{Scale page data} *)
|
(* Scale page data *)
|
||||||
let scale_pdf ?(fast=false) sxsylist pdf range =
|
let scale_pdf ?(fast=false) sxsylist pdf range =
|
||||||
let scale_page pnum page =
|
let scale_page pnum page =
|
||||||
let sx, sy = List.nth sxsylist (pnum - 1) in
|
let sx, sy = List.nth sxsylist (pnum - 1) in
|
||||||
|
@ -413,7 +413,7 @@ let hasbox pdf page boxname =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(* \section{Flip pages} *)
|
(* Flip pages *)
|
||||||
let flip_page ?(fast=false) transform_op pdf pnum page =
|
let flip_page ?(fast=false) transform_op pdf pnum page =
|
||||||
let minx, miny, maxx, maxy =
|
let minx, miny, maxx, maxy =
|
||||||
Pdf.parse_rectangle page.Pdfpage.mediabox
|
Pdf.parse_rectangle page.Pdfpage.mediabox
|
||||||
|
@ -658,7 +658,7 @@ let setBox box minx maxx miny maxy pdf range =
|
||||||
in
|
in
|
||||||
process_pages (Cpdfutil.ppstub set_box_page) pdf range
|
process_pages (Cpdfutil.ppstub set_box_page) pdf range
|
||||||
|
|
||||||
(* \section{Cropping} *)
|
(* Cropping *)
|
||||||
let crop_pdf ?(box="/CropBox") xywhlist pdf range =
|
let crop_pdf ?(box="/CropBox") xywhlist pdf range =
|
||||||
let crop_page pagenum page =
|
let crop_page pagenum page =
|
||||||
{page with
|
{page with
|
||||||
|
|
10
cpdftweak.ml
10
cpdftweak.ml
|
@ -2,10 +2,9 @@ open Pdfutil
|
||||||
open Pdfio
|
open Pdfio
|
||||||
open Cpdferror
|
open Cpdferror
|
||||||
|
|
||||||
(* \section{Blacken text} *)
|
(* Blacken text *)
|
||||||
|
|
||||||
(*
|
(*
|
||||||
\begin{verbatim}
|
|
||||||
Algorithm: Change
|
Algorithm: Change
|
||||||
BT
|
BT
|
||||||
<ops>
|
<ops>
|
||||||
|
@ -18,7 +17,6 @@ open Cpdferror
|
||||||
<ops minus any color, shading or gs operators>
|
<ops minus any color, shading or gs operators>
|
||||||
ET
|
ET
|
||||||
<ops minus any text positioning or text rendering ones>
|
<ops minus any text positioning or text rendering ones>
|
||||||
\end{verbatim}
|
|
||||||
*)
|
*)
|
||||||
let blacktext_ops colour pdf resources content =
|
let blacktext_ops colour pdf resources content =
|
||||||
let not_text = function
|
let not_text = function
|
||||||
|
@ -94,7 +92,7 @@ let blacktext c range pdf =
|
||||||
in
|
in
|
||||||
Cpdfpage.process_pages (Cpdfutil.ppstub blacktext_page) pdf range
|
Cpdfpage.process_pages (Cpdfutil.ppstub blacktext_page) pdf range
|
||||||
|
|
||||||
(* \section{Blacken lines} *)
|
(* Blacken lines *)
|
||||||
let blacklines_ops c pdf resources content =
|
let blacklines_ops c pdf resources content =
|
||||||
let rec blacken_strokeops prev = function
|
let rec blacken_strokeops prev = function
|
||||||
| [] -> rev prev
|
| [] -> rev prev
|
||||||
|
@ -120,7 +118,7 @@ let blacklines c range pdf =
|
||||||
in
|
in
|
||||||
Cpdfpage.process_pages (Cpdfutil.ppstub blacklines_page) pdf range
|
Cpdfpage.process_pages (Cpdfutil.ppstub blacklines_page) pdf range
|
||||||
|
|
||||||
(* \section{Blacken Fills} *)
|
(* Blacken Fills *)
|
||||||
let blackfills_ops c pdf resources content =
|
let blackfills_ops c pdf resources content =
|
||||||
let rec blacken_fillops prev = function
|
let rec blacken_fillops prev = function
|
||||||
| [] -> rev prev
|
| [] -> rev prev
|
||||||
|
@ -146,7 +144,7 @@ let blackfills c range pdf =
|
||||||
in
|
in
|
||||||
Cpdfpage.process_pages (Cpdfutil.ppstub blackfills_page) pdf range
|
Cpdfpage.process_pages (Cpdfutil.ppstub blackfills_page) pdf range
|
||||||
|
|
||||||
(* \section{Set a minimum line width to avoid dropout} *)
|
(* Set a minimum line width to avoid dropout *)
|
||||||
let thinlines range width pdf =
|
let thinlines range width pdf =
|
||||||
let thinpage _ page =
|
let thinpage _ page =
|
||||||
let operators =
|
let operators =
|
||||||
|
|
Loading…
Reference in New Issue