mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-03-02 18:47:54 +01:00
Implement -cm -in -mm
This commit is contained in:
parent
d6cb70d4f9
commit
86281f05f1
@ -243,6 +243,14 @@ let is_xfa pdf =
|
|||||||
Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/AcroForm"; "/XFA"] <> None
|
Pdf.lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/AcroForm"; "/XFA"] <> None
|
||||||
|
|
||||||
let output_info ?(json=ref [("none", `Null)]) encoding unit pdf =
|
let output_info ?(json=ref [("none", `Null)]) encoding unit pdf =
|
||||||
|
let ugetnum pdf o =
|
||||||
|
let n = Pdf.getnum pdf o in
|
||||||
|
match unit with
|
||||||
|
| Pdfunits.PdfPoint -> n
|
||||||
|
| Pdfunits.Inch -> Pdfunits.inches n Pdfunits.PdfPoint
|
||||||
|
| Pdfunits.Centimetre -> Pdfunits.centimetres n Pdfunits.PdfPoint
|
||||||
|
| Pdfunits.Millimetre -> Pdfunits.millimetres n Pdfunits.PdfPoint
|
||||||
|
in
|
||||||
let notjson = !json = [("none", `Null)] in
|
let notjson = !json = [("none", `Null)] in
|
||||||
let getstring = getstring encoding pdf in
|
let getstring = getstring encoding pdf in
|
||||||
let pages = Pdfpage.pages_of_pagetree pdf in
|
let pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
@ -308,7 +316,7 @@ let output_info ?(json=ref [("none", `Null)]) encoding unit pdf =
|
|||||||
Printf.printf "MediaBox: ";
|
Printf.printf "MediaBox: ";
|
||||||
begin if length (setify mediaboxes) = 1 then
|
begin if length (setify mediaboxes) = 1 then
|
||||||
match hd mediaboxes with
|
match hd mediaboxes with
|
||||||
| Pdf.Array [a; b; c; d] -> Printf.printf "%f %f %f %f\n" (Pdf.getnum pdf a) (Pdf.getnum pdf b) (Pdf.getnum pdf c) (Pdf.getnum pdf d)
|
| Pdf.Array [a; b; c; d] -> Printf.printf "%f %f %f %f\n" (ugetnum pdf a) (ugetnum pdf b) (ugetnum pdf c) (ugetnum pdf d)
|
||||||
| _ -> Printf.printf "\n"
|
| _ -> Printf.printf "\n"
|
||||||
else
|
else
|
||||||
Printf.printf "various\n"
|
Printf.printf "various\n"
|
||||||
@ -319,7 +327,7 @@ let output_info ?(json=ref [("none", `Null)]) encoding unit pdf =
|
|||||||
if length (setify boxes) = 1 then
|
if length (setify boxes) = 1 then
|
||||||
begin
|
begin
|
||||||
match hd boxes with
|
match hd boxes with
|
||||||
| Some (Pdf.Array [a; b; c; d]) -> Printf.printf "%f %f %f %f\n" (Pdf.getnum pdf a) (Pdf.getnum pdf b) (Pdf.getnum pdf c) (Pdf.getnum pdf d)
|
| Some (Pdf.Array [a; b; c; d]) -> Printf.printf "%f %f %f %f\n" (ugetnum pdf a) (ugetnum pdf b) (ugetnum pdf c) (ugetnum pdf d)
|
||||||
| _ -> Printf.printf "\n"
|
| _ -> Printf.printf "\n"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -336,7 +344,7 @@ let output_info ?(json=ref [("none", `Null)]) encoding unit pdf =
|
|||||||
if length (setify mediaboxes) = 1 then
|
if length (setify mediaboxes) = 1 then
|
||||||
match hd mediaboxes with
|
match hd mediaboxes with
|
||||||
| Pdf.Array [a; b; c; d] ->
|
| Pdf.Array [a; b; c; d] ->
|
||||||
`List [`Float (Pdf.getnum pdf a); `Float (Pdf.getnum pdf b); `Float (Pdf.getnum pdf c); `Float (Pdf.getnum pdf d)]
|
`List [`Float (ugetnum pdf a); `Float (ugetnum pdf b); `Float (ugetnum pdf c); `Float (ugetnum pdf d)]
|
||||||
| _ -> `Null
|
| _ -> `Null
|
||||||
else
|
else
|
||||||
`String "various"
|
`String "various"
|
||||||
@ -345,7 +353,7 @@ let output_info ?(json=ref [("none", `Null)]) encoding unit pdf =
|
|||||||
if length (setify boxes) = 1 then
|
if length (setify boxes) = 1 then
|
||||||
match hd boxes with
|
match hd boxes with
|
||||||
| Some (Pdf.Array [a; b; c; d]) ->
|
| Some (Pdf.Array [a; b; c; d]) ->
|
||||||
`List [`Float (Pdf.getnum pdf a); `Float (Pdf.getnum pdf b); `Float (Pdf.getnum pdf c); `Float (Pdf.getnum pdf d)]
|
`List [`Float (ugetnum pdf a); `Float (ugetnum pdf b); `Float (ugetnum pdf c); `Float (ugetnum pdf d)]
|
||||||
| _ -> `Null
|
| _ -> `Null
|
||||||
else
|
else
|
||||||
`String "various"
|
`String "various"
|
||||||
|
12
cpdfpage.ml
12
cpdfpage.ml
@ -157,6 +157,14 @@ let change_pattern_matrices_page pdf tr page =
|
|||||||
exception Exceptjson of Cpdfyojson.Safe.t
|
exception Exceptjson of Cpdfyojson.Safe.t
|
||||||
|
|
||||||
let output_page_info ?(json=false) ?(raisejson=false) unit pdf range =
|
let output_page_info ?(json=false) ?(raisejson=false) unit pdf range =
|
||||||
|
let ugetnum pdf o =
|
||||||
|
let n = Pdf.getnum pdf o in
|
||||||
|
match unit with
|
||||||
|
| Pdfunits.PdfPoint -> n
|
||||||
|
| Pdfunits.Inch -> Pdfunits.inches n Pdfunits.PdfPoint
|
||||||
|
| Pdfunits.Centimetre -> Pdfunits.centimetres n Pdfunits.PdfPoint
|
||||||
|
| Pdfunits.Millimetre -> Pdfunits.millimetres n Pdfunits.PdfPoint
|
||||||
|
in
|
||||||
let pages = Pdfpage.pages_of_pagetree pdf in
|
let pages = Pdfpage.pages_of_pagetree pdf in
|
||||||
let labels = Pdfpagelabels.read pdf in
|
let labels = Pdfpagelabels.read pdf in
|
||||||
let getbox page box =
|
let getbox page box =
|
||||||
@ -164,13 +172,13 @@ let output_page_info ?(json=false) ?(raisejson=false) unit pdf range =
|
|||||||
match page.Pdfpage.mediabox with
|
match page.Pdfpage.mediabox with
|
||||||
| Pdf.Array [a; b; c; d] ->
|
| Pdf.Array [a; b; c; d] ->
|
||||||
Printf.sprintf "%f %f %f %f"
|
Printf.sprintf "%f %f %f %f"
|
||||||
(Pdf.getnum pdf a) (Pdf.getnum pdf b) (Pdf.getnum pdf c) (Pdf.getnum pdf d)
|
(ugetnum pdf a) (ugetnum pdf b) (ugetnum pdf c) (ugetnum pdf d)
|
||||||
| _ -> ""
|
| _ -> ""
|
||||||
else
|
else
|
||||||
match Pdf.lookup_direct pdf box page.Pdfpage.rest with
|
match Pdf.lookup_direct pdf box page.Pdfpage.rest with
|
||||||
| Some (Pdf.Array [a; b; c; d]) ->
|
| Some (Pdf.Array [a; b; c; d]) ->
|
||||||
Printf.sprintf "%f %f %f %f"
|
Printf.sprintf "%f %f %f %f"
|
||||||
(Pdf.getnum pdf a) (Pdf.getnum pdf b) (Pdf.getnum pdf c) (Pdf.getnum pdf d)
|
(ugetnum pdf a) (ugetnum pdf b) (ugetnum pdf c) (ugetnum pdf d)
|
||||||
| _ -> ""
|
| _ -> ""
|
||||||
in
|
in
|
||||||
let rotation page =
|
let rotation page =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user