Skip to content

Commit

Permalink
Better merge behaviour with dests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwhitington committed Nov 23, 2016
1 parent fcc29b7 commit c3b659f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
24 changes: 16 additions & 8 deletions pdfmerge.ml
Expand Up @@ -114,9 +114,11 @@ let debug_pagelabels ls =
let debug_collection_of_pagelabels =
iter (fun ls -> debug_pagelabels ls; flprint "\n")

(* Merging /Dests (Named destinations). Since the new /Dests must be an indirect
reference, we add the new object to the pdf, returning the new pdf and the
reference. *)
(* Merging /Dests (Named destinations) in the catalog (PDF v1.1 style, rather
* than in the PDF 1.3 style in the name tree). Since the new /Dests must be an
* indirect reference, we add the new object to the pdf, returning the new pdf
* and the reference.
FIXME: merging a v1.1 file with a v1.2 file will result in both sets of dests, confusing the reader...*)
let new_dests pdf pdfs =
let dests =
option_map
Expand All @@ -127,10 +129,11 @@ let new_dests pdf pdfs =
| _ -> None)
pdfs
in
let new_dests =
Pdf.Dictionary (flatten dests)
in
Pdf.addobj pdf new_dests
if dests = [] then None else
let new_dests =
Pdf.Dictionary (flatten dests)
in
Some (Pdf.addobj pdf new_dests)

(* Names distinguish PDFs which are actually the same. So we only use the first
of each group of same ones. Then renumber them. and return. *)
Expand Down Expand Up @@ -256,9 +259,14 @@ let merge_pdfs retain_numbering do_remove_duplicate_fonts names pdfs ranges =
let dests = new_dests pdf pdfs in
let namedict = merge_namedicts pdf pdfs in
let extra_catalog_entries =
add "/Dests" (Pdf.Indirect dests)
let with_names =
(add "/Names" (Pdf.Indirect namedict)
(catalog_items_from_original_documents pdfs))
in
match dests with
None -> with_names
| Some dests ->
add "/Dests" (Pdf.Indirect dests) with_names
in
let pdf = Pdfpage.add_root pagetree_num extra_catalog_entries pdf in
(* To sort out annotations etc. *)
Expand Down
11 changes: 0 additions & 11 deletions pdfpage.ml
Expand Up @@ -929,17 +929,6 @@ let postpend_operators pdf ops ?(fast=false) page =
{page with content =
[Pdfops.stream_of_ops (beforeops @ Pdfops.parse_operators pdf page.resources page.content @ afterops)]}

(* (* Ensure that there are no inherited attributes in the page tree --- in other
words they are all explicit. This is required before writing a file with
linearization *)
let pagetree_make_explicit pdf =
let pages = pages_of_pagetree pdf in
change_pages true pdf pages*)

(* Set the reference in Pdfwrite for inter-module recursion. *)
(*let _ =
Pdfwrite.pagetree_make_explicit := pagetree_make_explicit*)

(* Source of possible prefix strings. String is always copied. *)
let next_string s =
if s = "" then "a" else
Expand Down

0 comments on commit c3b659f

Please sign in to comment.