File: pdftest.ml

package info (click to toggle)
camlpdf 0.5-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze, wheezy
  • size: 1,516 kB
  • ctags: 2,689
  • sloc: ml: 18,229; ansic: 139; makefile: 139
file content (32 lines) | stat: -rw-r--r-- 1,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(* \chaptertitle{Pdftest}{Test on a document} *)

(* Summary: \texttt{pdftest in.pdf out.pdf} reads, lexes, parses a document
\texttt{in.pdf} and its graphics streams, then writes it to \texttt{out.pdf}.
*)
open Utility

let _ =
  let in_name, out_name =
    match tl (Array.to_list Sys.argv) with
    | [i; o] -> i, o
    | _ -> print_string "Syntax: pdftest <input> <output>\n\n"; exit 1
  in
    try
      let pdf = Pdfread.pdf_of_file None in_name in
        let pages = Pdfdoc.pages_of_pagetree pdf in
          let pages' = 
            map 
              (fun page -> page)
                 (*i let graphic = Pdfgraphics.graphic_of_page pdf page in
                     (*i flprint (Pdfgraphics.string_of_graphic graphic); i*)
                     Pdfgraphics.page_of_graphic pdf (Pdf.parse_rectangle page.Pdfdoc.mediabox) graphic) i*)
              pages
          in
            let pdf = Pdfdoc.change_pages true pdf pages' in
              Pdf.remove_unreferenced pdf;
              Pdfwrite.pdf_to_file pdf out_name
    with
      err ->
        Printf.printf "Test failed:\n%s\n\n" (Printexc.to_string err);
        exit 1