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: Add support for page boundaries #216

Closed
zanmato opened this issue Aug 19, 2020 · 7 comments
Closed

api: Add support for page boundaries #216

zanmato opened this issue Aug 19, 2020 · 7 comments
Assignees

Comments

@zanmato
Copy link

zanmato commented Aug 19, 2020

Recently I had to define a TrimBox and a BleedBox for PDFs going to a print shop. I did this by essentially copying the ImportImages func to be able to access the dict of the newly created image page.
I guess another way to accomplish this is by running ReadContext afterwards to access the context, but it's still a bit clunky to me.
I think a better way would be to allow a callback func in the Import config that passes references to the page dict allowing you to insert/modify these boundary boxes. This way you don't have to change the method signature and thus won't break any compatibility with previous versions.

Something like this:

type ImportCallback func(int, Dict) error

// Import represents the command details for the command "ImportImage".
type Import struct {
	// .... Omitted the rest
        Callback ImportCallback
}
&pdfcpu.Import{
  DPI: 300,
  Callback: func(i int, pageDict pdfcpu.Dict) error {
     // Omitted part of getting the MediaBox to get the width and height for brevity
     pageDict.Insert("TrimBox", pdfcpu.NewNumberArray(0, 0, width - someMargin, height - someMargin))
     return nil
  }
}

I guess something like this could also solve #210 by enabling insertion of a CropBox
I would be happy to submit a PR for this, although I haven't considered the CLI part of the project with this feature proposal.

@hhrutter hhrutter self-assigned this Aug 20, 2020
@hhrutter
Copy link
Collaborator

Hi there!

I am aware proper support for PDF's page boundaries is lacking.
Consider me inspired by your proposal but this needs to be adressed across the board.

Thanks for using pdfcpu 💚

@hhrutter hhrutter changed the title api: add support for defining boundary boxes when importing api: support all page boundaries Aug 20, 2020
@hhrutter hhrutter changed the title api: support all page boundaries api: Add support for page boundaries Aug 20, 2020
@kpym
Copy link

kpym commented Nov 23, 2020

It will be nice if the cli tool also has the ability to manage all the boxes, not only the cropbox (as requested in #210).
For example something like

> pdfcpu boxe -pages '!2-4,!12-' media,trim="0 0 300 450" crop="50 50 250 400" 

would be nice. Other possible commands for pdfcpu boxe arelist and delete.

@hhrutter
Copy link
Collaborator

hhrutter commented Nov 24, 2020

For now the plan is to extend the pdfcpu import command because that's where this is really needed per described usecase.

I am hesitant to provide a separate cli command for juggling around with page boundaries for a given PDF because the consequences can be brutal and irreversible. Basically this is smth for the api but necessarily for the cli.

Can you describe your specific usecase for this cli feature?

@kpym
Copy link

kpym commented Nov 24, 2020

Can you describe your specific usecase for this cli feature?

If for example you have a software that requires trimbox and your pdf do not have one.
Or if some software (like pdfcpu before the correction of #245) ignore the cropbox and use the mediabox in place, we can modify the mediabox to be equal to the current cropbox to get around this.

@hhrutter
Copy link
Collaborator

Please be specific?
Which software requires a trimbox and for what reason?
I am learning here..

@kpym
Copy link

kpym commented Nov 24, 2020

Please be specific?
Which software requires a trimbox and for what reason?
I am learning here..

I'm not pdf-boxes specialist neither ;)

As far as I know all "standard" applications (viewers, home printers) use only the mediabox and the cropbox. But all professional prepress drivers and softwares use mainly the other boxes (has to be verified). For this reason PDF/X standards require the trimbox, and the bleedbox but not the cropbox.

You can check some info about the pdf boxes here.

@kpym kpym mentioned this issue Nov 25, 2020
hhrutter added a commit that referenced this issue Dec 24, 2020
@hhrutter
Copy link
Collaborator

This is fixed with the latest commit including the two new commands:

  • pdfcpu crop
  • pdfcpu boxes

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

3 participants