diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 0a0447f..d8e1236 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -570,7 +570,8 @@ type args = mutable rast_antialias : bool; mutable rast_jpeg_quality : int; mutable rast_downsample : bool; - mutable replace_stream_with : string} + mutable replace_stream_with : string; + mutable output_unit : Pdfunits.t} let args = {op = None; @@ -718,7 +719,8 @@ let args = rast_antialias = true; rast_jpeg_quality = 75; rast_downsample = false; - replace_stream_with = ""} + replace_stream_with = ""; + output_unit = Pdfunits.PdfPoint} (* Do not reset original_filename or cpdflin or was_encrypted or was_decrypted_with_owner or recrypt or producer or creator or path_to_* or @@ -852,7 +854,8 @@ let reset_arguments () = args.rast_antialias <- true; args.rast_jpeg_quality <- 75; args.rast_downsample <- false; - args.replace_stream_with <- "" + args.replace_stream_with <- ""; + args.output_unit <- Pdfunits.PdfPoint (* Prefer a) the one given with -cpdflin b) a local cpdflin, c) otherwise assume installed at a system place *) @@ -3030,6 +3033,9 @@ let specs = ("-rasterize-downsample", Arg.Unit (fun () -> args.rast_downsample <- true), " Antialias by downsampling"); ("-rasterize-jpeg-quality", Arg.Int (fun i -> args.rast_jpeg_quality <- i), " Set JPEG quality"); ("-output-image", Arg.Unit (fun () -> args.op <- Some OutputImage), " Output pages as images"); + ("-in", Arg.Unit (fun () -> args.output_unit <- Pdfunits.Inch), " Output dimensions in inches"); + ("-cm", Arg.Unit (fun () -> args.output_unit <- Pdfunits.Centimetre), " Output dimensions in centimetres"); + ("-mm", Arg.Unit (fun () -> args.output_unit <- Pdfunits.Millimetre), " Output dimensions in millimetres"); (* These items are undocumented *) ("-debug", Arg.Unit setdebug, ""); ("-debug-crypt", Arg.Unit (fun () -> args.debugcrypt <- true), ""); @@ -3962,21 +3968,21 @@ let go () = let pdf = decrypt_if_necessary input (Some Info) pdf in if args.format_json then begin - Cpdfmetadata.output_info ~json Cpdfmetadata.UTF8 pdf; - Cpdfmetadata.output_xmp_info ~json Cpdfmetadata.UTF8 pdf; + Cpdfmetadata.output_info ~json Cpdfmetadata.UTF8 args.output_unit pdf; + Cpdfmetadata.output_xmp_info ~json Cpdfmetadata.UTF8 args.output_unit pdf; flprint (Cpdfyojson.Safe.pretty_to_string (`Assoc (rev !json))) end else begin - Cpdfmetadata.output_info args.encoding pdf; - Cpdfmetadata.output_xmp_info args.encoding pdf + Cpdfmetadata.output_info args.encoding args.output_unit pdf; + Cpdfmetadata.output_xmp_info args.encoding args.output_unit pdf end | Some PageInfo -> begin match args.inputs, args.out with | (_, pagespec, _, _, _, _)::_, _ -> let pdf = get_single_pdf args.op true in let range = parse_pagespec_allow_empty pdf pagespec in - Cpdfpage.output_page_info ~json:args.format_json pdf range + Cpdfpage.output_page_info ~json:args.format_json args.output_unit pdf range | _ -> error "list-bookmarks: bad command line" end | Some Metadata -> diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index d57225f..ca4d122 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index fffe240..362b72a 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1,4 +1,5 @@ %Document -replace-stream +%Document -cm -in -mm \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc. @@ -1176,6 +1177,10 @@ processing. The default unless specified in the documentation for an individual In modern usage, \texttt{-utf8} is almost always the sensible option. But for historical reasons it would be the default. +\section{Line Endings} + +For historical reasons, Cpdf uses the Unix line ending character (LF) when writing text files on Microsoft Windows. For example, bookmark files. + \begin{cpdflib} \clearpage \section*{C Interface} diff --git a/cpdfmetadata.ml b/cpdfmetadata.ml index 0099fd7..d809b56 100644 --- a/cpdfmetadata.ml +++ b/cpdfmetadata.ml @@ -242,7 +242,7 @@ let get_open_action_string pdf = let is_xfa pdf = Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/AcroForm"; "/XFA"] <> None -let output_info ?(json=ref [("none", `Null)]) encoding pdf = +let output_info ?(json=ref [("none", `Null)]) encoding unit pdf = let notjson = !json = [("none", `Null)] in let getstring = getstring encoding pdf in let pages = Pdfpage.pages_of_pagetree pdf in @@ -511,7 +511,7 @@ let language pdf = let set_language pdf s = Pdf.replace_chain pdf ["/Root"; "/Lang"] (Pdf.String s) -let output_xmp_info ?(json=ref [("none", `Null)]) encoding pdf = +let output_xmp_info ?(json=ref [("none", `Null)]) encoding unit pdf = let notjson = !json = [("none", `Null)] in let print_out tree title namespace name = match get_data_for namespace name tree with diff --git a/cpdfmetadata.mli b/cpdfmetadata.mli index 89f348a..63efd7f 100644 --- a/cpdfmetadata.mli +++ b/cpdfmetadata.mli @@ -49,10 +49,10 @@ from the /Info dictionary, returning it as a UTF8 string *) val get_info_utf8 : Pdf.t -> string -> string (** Output to standard output general information about a PDF. *) -val output_info : ?json:(string * Cpdfyojson.Safe.t) list ref -> encoding -> Pdf.t -> unit +val output_info : ?json:(string * Cpdfyojson.Safe.t) list ref -> encoding -> Pdfunits.t -> Pdf.t -> unit (** Output to standard output information from any XMP metadata stream in a PDF. *) -val output_xmp_info : ?json:(string * Cpdfyojson.Safe.t) list ref -> encoding -> Pdf.t -> unit +val output_xmp_info : ?json:(string * Cpdfyojson.Safe.t) list ref -> encoding -> Pdfunits.t -> Pdf.t -> unit (** Create XMP metadata from scratch *) val create_metadata : Pdf.t -> Pdf.t diff --git a/cpdfpage.ml b/cpdfpage.ml index f73a418..0760fdc 100644 --- a/cpdfpage.ml +++ b/cpdfpage.ml @@ -156,7 +156,7 @@ let change_pattern_matrices_page pdf tr page = (* Output information for each page *) exception Exceptjson of Cpdfyojson.Safe.t -let output_page_info ?(json=false) ?(raisejson=false) pdf range = +let output_page_info ?(json=false) ?(raisejson=false) unit pdf range = let pages = Pdfpage.pages_of_pagetree pdf in let labels = Pdfpagelabels.read pdf in let getbox page box = @@ -223,8 +223,8 @@ let output_page_info ?(json=false) ?(raisejson=false) pdf range = Printf.printf "Annotations: %i\n" (num_annots page)) range -let json_page_info pdf range = - try output_page_info ~json:true ~raisejson:true pdf range; `List [] with +let json_page_info pdf range unit = + try output_page_info ~json:true ~raisejson:true unit pdf range; `List [] with Exceptjson j -> j let process_pages f pdf range = diff --git a/cpdfpage.mli b/cpdfpage.mli index d67e937..17ac14d 100644 --- a/cpdfpage.mli +++ b/cpdfpage.mli @@ -1,10 +1,10 @@ (** Working with pages *) (** Print page info (Mediabox etc) to standard output. *) -val output_page_info : ?json:bool -> ?raisejson:bool -> Pdf.t -> int list -> unit +val output_page_info : ?json:bool -> ?raisejson:bool -> Pdfunits.t -> Pdf.t -> int list -> unit (** Return page info for selected pages in JSON format. *) -val json_page_info : Pdf.t -> int list -> Cpdfyojson.Safe.t +val json_page_info : Pdf.t -> int list -> Pdfunits.t -> Cpdfyojson.Safe.t (** 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. *)