Dont parse twice in test, fix some bugs with special pdfs

This commit is contained in:
Jeroen Bobbeldijk
2017-09-17 15:24:57 +02:00
parent b8f3cee07c
commit 8c60336e04
6 changed files with 32 additions and 44 deletions

View File

@@ -14,8 +14,15 @@ import (
func findFirstPage(parent pdf.Value) (pdf.Value, error) {
value_type := parent.Key("Type").String()
if value_type == "/Pages" {
recurse_parent, recurse_err := findFirstPage(parent.Key("Kids").Index(0))
return recurse_parent, recurse_err
for i := 0; i < parent.Key("Kids").Len(); i++ {
recurse_parent, recurse_err := findFirstPage(parent.Key("Kids").Index(i))
if recurse_err == nil {
return recurse_parent, recurse_err
}
}
return parent, errors.New("Could not find first page.")
}
if value_type == "/Page" {
@@ -83,6 +90,10 @@ func writePartFromSourceFileToTargetFile(input_file *os.File, output_file *os.Fi
// Track read/written bytes so we know when we're done.
read_bytes := int64(0)
if length <= 0 {
return nil
}
// Create a buffer for the chunks.
buf := make([]byte, max_chunk_length)
for {