pdfcpu / pdfcpu

A PDF processor written in Go.

Home Page:http://pdfcpu.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Api: merge pdf error

iyichen opened this issue · comments

commented

issue

api.MergeCreateFile() error: validatePageContents: page content must be stream dict or array

description

I'm using api.MergeCreateFile() to merge pdf files, I found it will report an error when a pdf file contains blank pages, and after I delete the blank pages, it works fine.
However when I use QuickLook open a pdf file and append a blank page, MergeCreateFile() works fine. So I feel confused why this is happening.

code

package main

import (
	"fmt"
	"github.com/pdfcpu/pdfcpu/pkg/api"
)

func main() {
	err := api.MergeCreateFile([]string{"with_blank_page.pdf", "without_blank_page.pdf"}, "merge.pdf", false, nil)
	fmt.Println(err)
}

  • OS: macOs 14.1.2
  • GO: go1.20.3

PDF files:

In situation like these always validate your input files before merging: pdfcpu val test.pdf

Your input file is violating the PDF spec:

13:   offset=    6628 generation=0 types.Dict type=Page
<<
	<Contents, ()>
	<Parent, (2 0 R)>
	<Resources, (4 0 R)>
	<Type, Page>
>>

Content is supposed to be a stream dict or an array.
An empty string literal is not allowed!

commented

In situation like these always validate your input files before merging: pdfcpu val test.pdf

Your input file is violating the PDF spec:

13:   offset=    6628 generation=0 types.Dict type=Page
<<
	<Contents, ()>
	<Parent, (2 0 R)>
	<Resources, (4 0 R)>
	<Type, Page>
>>

Content is supposed to be a stream dict or an array. An empty string literal is not allowed!

Thanks, I'll go back and look at the pdf spec.