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 rootnum = Pdf.addobj pdf rootdict' in
|
||||
{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.trailerdict =
|
||||
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 pdf = Pdfpage.change_pages true pdf pages' in
|
||||
{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 =
|
||||
{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 =
|
||||
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;
|
||||
match args.out with
|
||||
| NoOutputSpecified ->
|
||||
|
@ -3864,7 +3864,7 @@ let go () =
|
|||
| _ -> assert 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_pdf_info
|
||||
~xmp_also:args.alsosetxml
|
||||
|
@ -3887,7 +3887,7 @@ let go () =
|
|||
| _ -> assert 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)
|
||||
end
|
||||
| Some (OpenAtPage str) ->
|
||||
|
@ -3980,7 +3980,7 @@ let go () =
|
|||
args.transition args.duration args.horizontal
|
||||
args.inward args.direction args.effect_duration pdf
|
||||
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'
|
||||
| Some ChangeId ->
|
||||
if args.recrypt then
|
||||
|
@ -4262,7 +4262,7 @@ let go () =
|
|||
"40bit" -> 1 | "128bit" -> 4 | "AES" -> 6 | "AES256" | "AES256ISO" -> 7 | _ -> 0
|
||||
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;
|
||||
write_pdf ~encryption:(Some encryption) false pdf
|
||||
| Some Decrypt ->
|
||||
|
|
|
@ -84,7 +84,7 @@ let set_metadata_from_bytes keepversion data pdf =
|
|||
Pdf.trailerdict = trailerdict;
|
||||
Pdf.root = rootnum;
|
||||
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 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
|
||||
pdf.Pdf.trailerdict <-
|
||||
Pdf.add_dict_entry pdf.Pdf.trailerdict "/Info" (Pdf.Indirect objnum);
|
||||
pdf.Pdf.minor <-
|
||||
max pdf.Pdf.minor version
|
||||
if pdf.Pdf.major = 1 then pdf.Pdf.minor <- max pdf.Pdf.minor version
|
||||
end;
|
||||
if xmp_also then
|
||||
begin match get_metadata pdf with
|
||||
|
@ -546,7 +545,7 @@ let copy_id keepversion copyfrom copyto =
|
|||
copyto.Pdf.trailerdict <-
|
||||
Pdf.add_dict_entry copyto.Pdf.trailerdict "/ID" id;
|
||||
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
|
||||
|
||||
let replacements pdf =
|
||||
|
|
Loading…
Reference in New Issue