Add header for files with no struct tree
This commit is contained in:
parent
9af12f1ae0
commit
17762e35a0
36
cpdfua.ml
36
cpdfua.ml
|
@ -334,24 +334,24 @@ let mark pdf =
|
||||||
let extract_struct_tree pdf =
|
let extract_struct_tree pdf =
|
||||||
match Pdf.lookup_obj pdf pdf.Pdf.root with
|
match Pdf.lookup_obj pdf pdf.Pdf.root with
|
||||||
| Pdf.Dictionary d ->
|
| Pdf.Dictionary d ->
|
||||||
begin match lookup "/StructTreeRoot" d with
|
let zero =
|
||||||
| None -> `List []
|
`List [`Int 0;
|
||||||
| Some x ->
|
`Assoc [("/CPDFJSONformatversion", `Int 1);
|
||||||
let objs = Pdf.objects_referenced ["/Pg"; "/Obj"; "/Stm"; "/StmOwn"] [] pdf x in
|
("/CPDFJSONpageobjnumbers", `List (map (fun x -> `Int (unopt (Pdfpage.page_object_number pdf x))) (ilist 1 (Pdfpage.endpage pdf))))]]
|
||||||
let zero =
|
in
|
||||||
`List [`Int 0;
|
begin match lookup "/StructTreeRoot" d with
|
||||||
`Assoc [("/CPDFJSONformatversion", `Int 1);
|
| None -> `List [zero]
|
||||||
("/CPDFJSONpageobjnumbers", `List (map (fun x -> `Int (unopt (Pdfpage.page_object_number pdf x))) (ilist 1 (Pdfpage.endpage pdf))))]]
|
| Some x ->
|
||||||
in
|
let objs = Pdf.objects_referenced ["/Pg"; "/Obj"; "/Stm"; "/StmOwn"] [] pdf x in
|
||||||
`List
|
`List
|
||||||
(zero::map
|
(zero::map
|
||||||
(fun objnum ->
|
(fun objnum ->
|
||||||
let jsonobj =
|
let jsonobj =
|
||||||
Cpdfjson.json_of_object ~utf8:true ~no_stream_data:false ~parse_content:false pdf (function _ -> ()) (Pdf.lookup_obj pdf objnum)
|
Cpdfjson.json_of_object ~utf8:true ~no_stream_data:false ~parse_content:false pdf (function _ -> ()) (Pdf.lookup_obj pdf objnum)
|
||||||
in
|
in
|
||||||
`List [`Int objnum; jsonobj])
|
`List [`Int objnum; jsonobj])
|
||||||
objs)
|
objs)
|
||||||
end
|
end
|
||||||
| _ -> error "extract_struct_tree: no root"
|
| _ -> error "extract_struct_tree: no root"
|
||||||
|
|
||||||
(* Use JSON data to replace objects in a file. Negative objects are new ones,
|
(* Use JSON data to replace objects in a file. Negative objects are new ones,
|
||||||
|
|
Loading…
Reference in New Issue