Skip to content

Commit

Permalink
Fix issue with TOC containing break returns.
Browse files Browse the repository at this point in the history
  • Loading branch information
symac committed Oct 30, 2019
1 parent 94fe5f6 commit 985563e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Job/ExtractToc.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ protected function pdfToToc($path)
return preg_match("/.*Bookmark.*/", $var);
});
// If a title contains a \n the end of the Toc will be crashed
$dump_data_array = array_map(function($a) { return chop($a); }, $dump_data_array);
// ExtractContent expects an array that is contiguous so in case we have filtered
// something we need to rebuild the keys to be consecutive
$dump_data_array = array_values($dump_data_array );
$content = [];
$i = 0;
$this->extractContent($i, 1, $content, $dump_data_array, $content);
$toc = $this->formatContent($content, "");

$this->logger->info($toc);
return json_encode($toc );
} else {
return json_encode([]);
Expand Down Expand Up @@ -102,7 +111,7 @@ protected function extractContent(&$i, $level, &$content, $data, &$parent ) {
$bm_title = str_replace("BookmarkTitle: ", "", $data[$i+1]);
$bm_level = str_replace("BookmarkLevel: ", "", $data[$i + 2]);
$bm_page = str_replace("BookmarkPageNumber: ", "", $data[$i + 3]);

$this->logger->info("TITLE : ".$bm_title);

$newContent['title'] = $bm_title;
$newContent['level'] = $bm_level;
Expand Down

0 comments on commit 985563e

Please sign in to comment.