guard 2.x files against having version changed
This commit is contained in:
parent
c20411eb14
commit
06a0553568
|
@ -81,7 +81,7 @@ let attach_file ?memory keepversion topage pdf file =
|
||||||
let rootdict' = Pdf.add_dict_entry rootdict "/Names" namedict' in
|
let rootdict' = Pdf.add_dict_entry rootdict "/Names" namedict' in
|
||||||
let rootnum = Pdf.addobj pdf rootdict' in
|
let rootnum = Pdf.addobj pdf rootdict' in
|
||||||
{pdf with
|
{pdf with
|
||||||
Pdf.minor = if keepversion then pdf.Pdf.minor else max pdf.Pdf.minor 4;
|
Pdf.minor = if keepversion || pdf.Pdf.major > 1 then pdf.Pdf.minor else max pdf.Pdf.minor 4;
|
||||||
Pdf.root = rootnum;
|
Pdf.root = rootnum;
|
||||||
Pdf.trailerdict =
|
Pdf.trailerdict =
|
||||||
Pdf.add_dict_entry
|
Pdf.add_dict_entry
|
||||||
|
@ -114,7 +114,7 @@ let attach_file ?memory keepversion topage pdf file =
|
||||||
let pages' = replace_number pagenumber page' pages in
|
let pages' = replace_number pagenumber page' pages in
|
||||||
let pdf = Pdfpage.change_pages true pdf pages' in
|
let pdf = Pdfpage.change_pages true pdf pages' in
|
||||||
{pdf with
|
{pdf with
|
||||||
Pdf.minor = if keepversion then pdf.Pdf.minor else max pdf.Pdf.minor 4}
|
Pdf.minor = if keepversion || pdf.Pdf.major > 1 then pdf.Pdf.minor else max pdf.Pdf.minor 4}
|
||||||
|
|
||||||
type attachment =
|
type attachment =
|
||||||
{name : string;
|
{name : string;
|
||||||
|
|
|
@ -3198,7 +3198,7 @@ let really_write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf outna
|
||||||
|
|
||||||
let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
|
let write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf =
|
||||||
if args.debugcrypt then Printf.printf "write_pdf\n";
|
if args.debugcrypt then Printf.printf "write_pdf\n";
|
||||||
if args.create_objstm && not args.keepversion
|
if args.create_objstm && not (args.keepversion || pdf.Pdf.major > 1)
|
||||||
then pdf.Pdf.minor <- max pdf.Pdf.minor 5;
|
then pdf.Pdf.minor <- max pdf.Pdf.minor 5;
|
||||||
match args.out with
|
match args.out with
|
||||||
| NoOutputSpecified ->
|
| NoOutputSpecified ->
|
||||||
|
@ -3864,7 +3864,7 @@ let go () =
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
in
|
in
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
let version = if args.keepversion then pdf.Pdf.minor else version in
|
let version = if args.keepversion || pdf.Pdf.major > 1 then pdf.Pdf.minor else version in
|
||||||
write_pdf false
|
write_pdf false
|
||||||
(Cpdfmetadata.set_pdf_info
|
(Cpdfmetadata.set_pdf_info
|
||||||
~xmp_also:args.alsosetxml
|
~xmp_also:args.alsosetxml
|
||||||
|
@ -3887,7 +3887,7 @@ let go () =
|
||||||
| _ -> assert false
|
| _ -> assert false
|
||||||
in
|
in
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
let version = if args.keepversion then pdf.Pdf.minor else version in
|
let version = if args.keepversion || pdf.Pdf.major > 1 then pdf.Pdf.minor else version in
|
||||||
write_pdf false (Cpdfmetadata.set_viewer_preference (key, value, version) pdf)
|
write_pdf false (Cpdfmetadata.set_viewer_preference (key, value, version) pdf)
|
||||||
end
|
end
|
||||||
| Some (OpenAtPage str) ->
|
| Some (OpenAtPage str) ->
|
||||||
|
@ -3980,7 +3980,7 @@ let go () =
|
||||||
args.transition args.duration args.horizontal
|
args.transition args.duration args.horizontal
|
||||||
args.inward args.direction args.effect_duration pdf
|
args.inward args.direction args.effect_duration pdf
|
||||||
in
|
in
|
||||||
pdf.Pdf.minor <- if args.keepversion then pdf.Pdf.minor else max pdf.Pdf.minor 1;
|
pdf.Pdf.minor <- if args.keepversion || pdf.Pdf.major > 1 then pdf.Pdf.minor else max pdf.Pdf.minor 1;
|
||||||
write_pdf false pdf'
|
write_pdf false pdf'
|
||||||
| Some ChangeId ->
|
| Some ChangeId ->
|
||||||
if args.recrypt then
|
if args.recrypt then
|
||||||
|
@ -4262,7 +4262,7 @@ let go () =
|
||||||
"40bit" -> 1 | "128bit" -> 4 | "AES" -> 6 | "AES256" | "AES256ISO" -> 7 | _ -> 0
|
"40bit" -> 1 | "128bit" -> 4 | "AES" -> 6 | "AES256" | "AES256ISO" -> 7 | _ -> 0
|
||||||
in
|
in
|
||||||
let newversion = if args.create_objstm then 5 else newversion in
|
let newversion = if args.create_objstm then 5 else newversion in
|
||||||
pdf.Pdf.minor <- max pdf.Pdf.minor newversion
|
if pdf.Pdf.major = 1 then pdf.Pdf.minor <- max pdf.Pdf.minor newversion
|
||||||
end;
|
end;
|
||||||
write_pdf ~encryption:(Some encryption) false pdf
|
write_pdf ~encryption:(Some encryption) false pdf
|
||||||
| Some Decrypt ->
|
| Some Decrypt ->
|
||||||
|
|
|
@ -84,7 +84,7 @@ let set_metadata_from_bytes keepversion data pdf =
|
||||||
Pdf.trailerdict = trailerdict;
|
Pdf.trailerdict = trailerdict;
|
||||||
Pdf.root = rootnum;
|
Pdf.root = rootnum;
|
||||||
Pdf.minor =
|
Pdf.minor =
|
||||||
if keepversion then pdf.Pdf.minor else max 4 pdf.Pdf.minor}
|
if pdf.Pdf.major > 1 || keepversion then pdf.Pdf.minor else max 4 pdf.Pdf.minor}
|
||||||
|
|
||||||
let set_metadata keepversion filename pdf =
|
let set_metadata keepversion filename pdf =
|
||||||
let ch = open_in_bin filename in
|
let ch = open_in_bin filename in
|
||||||
|
@ -488,8 +488,7 @@ let set_pdf_info ?(xmp_also=false) ?(xmp_just_set=false) (key, value, version) p
|
||||||
begin
|
begin
|
||||||
pdf.Pdf.trailerdict <-
|
pdf.Pdf.trailerdict <-
|
||||||
Pdf.add_dict_entry pdf.Pdf.trailerdict "/Info" (Pdf.Indirect objnum);
|
Pdf.add_dict_entry pdf.Pdf.trailerdict "/Info" (Pdf.Indirect objnum);
|
||||||
pdf.Pdf.minor <-
|
if pdf.Pdf.major = 1 then pdf.Pdf.minor <- max pdf.Pdf.minor version
|
||||||
max pdf.Pdf.minor version
|
|
||||||
end;
|
end;
|
||||||
if xmp_also then
|
if xmp_also then
|
||||||
begin match get_metadata pdf with
|
begin match get_metadata pdf with
|
||||||
|
@ -546,7 +545,7 @@ let copy_id keepversion copyfrom copyto =
|
||||||
copyto.Pdf.trailerdict <-
|
copyto.Pdf.trailerdict <-
|
||||||
Pdf.add_dict_entry copyto.Pdf.trailerdict "/ID" id;
|
Pdf.add_dict_entry copyto.Pdf.trailerdict "/ID" id;
|
||||||
copyto.Pdf.minor <-
|
copyto.Pdf.minor <-
|
||||||
if keepversion then copyto.Pdf.minor else max copyto.Pdf.minor 1;
|
if copyto.Pdf.major > 1 || keepversion then copyto.Pdf.minor else max copyto.Pdf.minor 1;
|
||||||
copyto
|
copyto
|
||||||
|
|
||||||
let replacements pdf =
|
let replacements pdf =
|
||||||
|
|
Loading…
Reference in New Issue