File: pdfdecomp.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 (21 lines) | stat: -rw-r--r-- 710 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
(* \chaptertitle{Pdfdecomp}{Decompress streams} *)

(* Summary: \texttt{pdfdecomp a.pdf b.pdf} decompresses all streams in \texttt{a.pdf},
writing the result to \texttt{b.pdf}. *)

let decompress_pdf pdf =
  Pdf.map_stream (fun x -> Pdfcodec.decode_pdfstream_until_unknown pdf x; x) pdf

let _ =
  match Array.to_list Sys.argv with
  | [_; in_file; out_file] ->
      begin try
        let pdf = Pdfread.pdf_of_file None in_file in
          Pdfwrite.pdf_to_file (decompress_pdf pdf) out_file
      with
        err ->
          Printf.printf "Failed to decompress file.\n%s\n\n" (Printexc.to_string err);
          exit 1
      end
  | _ ->
      print_string "Syntax: pdfdecomp <input> <output>\n\n"; exit 1