Linearization on outputs done.

This commit is contained in:
John Whitington 2014-10-02 14:19:05 +01:00
parent f3f11f1343
commit 2062d0fb27
1 changed files with 19 additions and 30 deletions

View File

@ -8,8 +8,6 @@ let version_date = "(unreleased, 16th September 2014)"
open Pdfutil open Pdfutil
open Pdfio open Pdfio
(* Wrap up the file reading functions to exit with code 1 when an encryption (* Wrap up the file reading functions to exit with code 1 when an encryption
problem occurs. This happens when object streams are in an encrypted document problem occurs. This happens when object streams are in an encrypted document
and so it can't be read without the right password... The existing error and so it can't be read without the right password... The existing error
@ -1797,7 +1795,7 @@ let really_write_pdf ?(encryption = None) mk_id pdf outname =
raise (Pdf.PDFError "linearizer failed") raise (Pdf.PDFError "linearizer failed")
end end
let write_pdf ?(encryption = None) mk_id pdf = let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
if args.create_objstm && not args.keepversion if args.create_objstm && not args.keepversion
then pdf.Pdf.minor <- max pdf.Pdf.minor 5; then pdf.Pdf.minor <- max pdf.Pdf.minor 5;
let mk_id = args.makenewid || mk_id in let mk_id = args.makenewid || mk_id in
@ -1808,10 +1806,14 @@ let write_pdf ?(encryption = None) mk_id pdf =
let outname = writing_ok outname in let outname = writing_ok outname in
begin match encryption with begin match encryption with
None -> None ->
let pdf = Cpdf.recompress_pdf <| nobble pdf in ignore (nobble pdf);
if args.squeeze then Cpdf.squeeze pdf; if not is_decompress then
Pdf.remove_unreferenced pdf; begin
really_write_pdf mk_id pdf outname ignore (Cpdf.recompress_pdf pdf);
if args.squeeze then Cpdf.squeeze pdf;
Pdf.remove_unreferenced pdf
end;
really_write_pdf mk_id pdf outname
| Some _ -> | Some _ ->
really_write_pdf ~encryption mk_id pdf outname really_write_pdf ~encryption mk_id pdf outname
end end
@ -1819,9 +1821,13 @@ let write_pdf ?(encryption = None) mk_id pdf =
let temp = Filename.temp_file "cpdflin" ".pdf" in let temp = Filename.temp_file "cpdflin" ".pdf" in
begin match encryption with begin match encryption with
None -> None ->
let pdf = Cpdf.recompress_pdf <| nobble pdf in ignore (nobble pdf);
if args.squeeze then Cpdf.squeeze pdf; if not is_decompress then
Pdf.remove_unreferenced pdf; begin
ignore (Cpdf.recompress_pdf pdf);
if args.squeeze then Cpdf.squeeze pdf;
Pdf.remove_unreferenced pdf
end;
really_write_pdf ~encryption mk_id pdf temp; really_write_pdf ~encryption mk_id pdf temp;
| Some _ -> | Some _ ->
really_write_pdf ~encryption mk_id pdf temp really_write_pdf ~encryption mk_id pdf temp
@ -2949,16 +2955,7 @@ let go () =
try Pdfcodec.decode_pdfstream_until_unknown pdf stream with try Pdfcodec.decode_pdfstream_until_unknown pdf stream with
e -> Printf.eprintf "Decode failure: %s. Carrying on...\n" (Printexc.to_string e); ()) e -> Printf.eprintf "Decode failure: %s. Carrying on...\n" (Printexc.to_string e); ())
pdf; pdf;
begin match args.out with write_pdf ~is_decompress:true args.makenewid pdf
| NoOutputSpecified ->
error "no output specified"
| File outname ->
let outname = writing_ok outname in
Pdfwrite.pdf_to_file_options (*FIXLIN args.linearize*) false None args.makenewid pdf outname
| Stdout ->
Pdfwrite.pdf_to_channel (*FIXLIN args.linearize *) false None args.makenewid pdf stdout;
flush stdout
end
| Some Compress -> | Some Compress ->
let pdf = get_single_pdf (Some Compress) false in let pdf = get_single_pdf (Some Compress) false in
if args.remove_duplicate_streams then if args.remove_duplicate_streams then
@ -3129,18 +3126,10 @@ let go () =
begin match args.inputs, args.out with begin match args.inputs, args.out with
| [(k, _, _, _, _) as input], File s -> | [(k, _, _, _, _) as input], File s ->
let pdf = get_pdf_from_input_kind input args.op k in let pdf = get_pdf_from_input_kind input args.op k in
let s = writing_ok s in write_pdf true pdf
Pdfwrite.pdf_to_file_options
~preserve_objstm:args.preserve_objstm
~generate_objstm:args.create_objstm
(*FIXLIN args.linearize*) false None true pdf s
| [(k, _, _, _, _) as input], Stdout -> | [(k, _, _, _, _) as input], Stdout ->
let pdf = get_pdf_from_input_kind input args.op k in let pdf = get_pdf_from_input_kind input args.op k in
Pdfwrite.pdf_to_channel write_pdf true pdf
~preserve_objstm:args.preserve_objstm
~generate_objstm:args.create_objstm
(*FIXLIN args.linearize*) false None true pdf stdout;
flush stdout
| _ -> error "ChangeId: exactly one input file and output file required." | _ -> error "ChangeId: exactly one input file and output file required."
end end
| Some RemoveId -> | Some RemoveId ->