mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
-draft-remove-only finished
This commit is contained in:
21
cpdf.ml
21
cpdf.ml
@@ -3899,8 +3899,8 @@ let rec remove_images_stream onlyremove boxes pdf resources prev = function
|
|||||||
| [] -> rev prev
|
| [] -> rev prev
|
||||||
| (Pdfops.Op_Do name) as h::t ->
|
| (Pdfops.Op_Do name) as h::t ->
|
||||||
if xobject_isimage pdf resources name && (match onlyremove with None -> true | Some x -> x = name)
|
if xobject_isimage pdf resources name && (match onlyremove with None -> true | Some x -> x = name)
|
||||||
then remove_images_stream onlyremove boxes pdf resources (substitute boxes @ prev) t
|
then remove_images_stream onlyremove boxes pdf resources (substitute boxes @ prev) t
|
||||||
else remove_images_stream onlyremove boxes pdf resources (h::prev) t
|
else remove_images_stream onlyremove boxes pdf resources (h::prev) t
|
||||||
| Pdfops.InlineImage _ as h::t ->
|
| Pdfops.InlineImage _ as h::t ->
|
||||||
if onlyremove <> None
|
if onlyremove <> None
|
||||||
then remove_images_stream onlyremove boxes pdf resources (h::prev) t
|
then remove_images_stream onlyremove boxes pdf resources (h::prev) t
|
||||||
@@ -3947,12 +3947,16 @@ and remove_images_page onlyremove boxes pdf page =
|
|||||||
let isform pdf xobj =
|
let isform pdf xobj =
|
||||||
match Pdf.lookup_direct pdf "/Subtype" xobj with Some (Pdf.Name "/Form") -> true | _ -> false
|
match Pdf.lookup_direct pdf "/Subtype" xobj with Some (Pdf.Name "/Form") -> true | _ -> false
|
||||||
in
|
in
|
||||||
|
let isimage pdf xobj =
|
||||||
|
match Pdf.lookup_direct pdf "/Subtype" xobj with Some (Pdf.Name "/Image") -> true | _ -> false
|
||||||
|
in
|
||||||
(* Remove image xobjects and look into form ones *)
|
(* Remove image xobjects and look into form ones *)
|
||||||
let form_xobjects =
|
let form_xobjects, image_xobjects =
|
||||||
match Pdf.lookup_direct pdf "/XObject" page.Pdfpage.resources with
|
match Pdf.lookup_direct pdf "/XObject" page.Pdfpage.resources with
|
||||||
| Some (Pdf.Dictionary elts) ->
|
| Some (Pdf.Dictionary elts) ->
|
||||||
keep (function (_, p) -> isform pdf p) elts
|
keep (function (_, p) -> isform pdf p) elts,
|
||||||
| _ -> []
|
keep (function (_, p) -> isimage pdf p) elts
|
||||||
|
| _ -> [], []
|
||||||
in
|
in
|
||||||
let resources', pdf =
|
let resources', pdf =
|
||||||
let names, pointers = split form_xobjects in
|
let names, pointers = split form_xobjects in
|
||||||
@@ -3973,8 +3977,13 @@ and remove_images_page onlyremove boxes pdf page =
|
|||||||
let objnum = Pdf.addobj pdf xobj in
|
let objnum = Pdf.addobj pdf xobj in
|
||||||
nums =| objnum)
|
nums =| objnum)
|
||||||
form_xobjects';
|
form_xobjects';
|
||||||
|
let image_xobjects' =
|
||||||
|
match onlyremove with
|
||||||
|
None -> image_xobjects
|
||||||
|
| Some n -> option_map (function (n', _) as xobj -> if n = n' then None else Some xobj) image_xobjects
|
||||||
|
in
|
||||||
let newdict =
|
let newdict =
|
||||||
Pdf.Dictionary (combine names (map (fun x -> Pdf.Indirect x) (rev !nums)))
|
Pdf.Dictionary (image_xobjects' @ combine names (map (fun x -> Pdf.Indirect x) (rev !nums)))
|
||||||
in
|
in
|
||||||
Pdf.add_dict_entry page.Pdfpage.resources "/XObject" newdict, pdf
|
Pdf.add_dict_entry page.Pdfpage.resources "/XObject" newdict, pdf
|
||||||
in
|
in
|
||||||
|
Reference in New Issue
Block a user