Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api: merge pdf error #850

Closed
iyichen opened this issue Apr 13, 2024 · 3 comments
Closed

Api: merge pdf error #850

iyichen opened this issue Apr 13, 2024 · 3 comments
Assignees

Comments

@iyichen
Copy link

iyichen commented Apr 13, 2024

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:

@hhrutter
Copy link
Collaborator

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!

@iyichen
Copy link
Author

iyichen commented Apr 14, 2024

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.

@iyichen iyichen closed this as completed Apr 14, 2024
hhrutter added a commit that referenced this issue Jun 30, 2024
@hhrutter
Copy link
Collaborator

The latest commit repairs this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants