ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Trouble setting PDF boxes
@ 2020-04-25 12:37 Jack Steyn
  2020-04-25 16:42 ` Jack Steyn
  2020-04-26  9:46 ` bug in PDF boxes? (was: Re: Trouble setting PDF boxes)) Pablo Rodriguez
  0 siblings, 2 replies; 7+ messages in thread
From: Jack Steyn @ 2020-04-25 12:37 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 635 bytes --]

Hi,

I am having trouble setting the PDF boxes to my desired dimensions. Suppose
I have \setuppapersize[*a*][*b*]. I want CropBox = MediaBox = *b*. So far,
so good: I can just use cropoffset=0mm in \setuplayout. But I want TrimBox
= *a*. However, as far as I can see, I can't achieve this using trimoffset
in \setuplayout unless (width of *b*) – (width of *a*) = (height of *b*) –
(height of *a*), which does not hold in my case. So it looks like I need to
find another way to set the TrimBox (and the BleedBox, which I want to be
3mm wider and taller than the TrimBox). Does anyone know how to do this?

Best,

Jack

[-- Attachment #1.2: Type: text/html, Size: 794 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Trouble setting PDF boxes
  2020-04-25 12:37 Trouble setting PDF boxes Jack Steyn
@ 2020-04-25 16:42 ` Jack Steyn
  2020-04-30 15:51   ` Jack Steyn
  2020-04-26  9:46 ` bug in PDF boxes? (was: Re: Trouble setting PDF boxes)) Pablo Rodriguez
  1 sibling, 1 reply; 7+ messages in thread
From: Jack Steyn @ 2020-04-25 16:42 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 1723 bytes --]

After much searching, my probably laughable attempt consists of combining
the answer to the question at
https://tex.stackexchange.com/questions/433110/setting-page-attributes-of-every-page-in-a-generated-context-file
with
what I can see in the source at
https://source.contextgarden.net/tex/context/base/mkiv/lpdf-mis.lua:

\appendtoks
  \startluacode
      local formatters = string.formatters

      local pdfverbose = lpdf.verbose
      local pdfarray = lpdf.array

      local factor  = number.dimenfactors.bp
      local f_value = formatters["\letterpercent.6N"]

      local function boxvalue(n)
          return pdfverbose(f_value(factor * n))
      end

      lpdf.addtopageattributes("TrimBox", pdfarray {
          boxvalue(30),
          boxvalue(30),
          boxvalue(180),
          boxvalue(267),})
  \stopluacode
\to \aftereverypage

This code throws no errors, but unfortunately it also has no effect. What
am I doing wrong?

Jack

On Sat, 25 Apr 2020 at 22:37, Jack Steyn <steynjack@gmail.com> wrote:

> Hi,
>
> I am having trouble setting the PDF boxes to my desired dimensions.
> Suppose I have \setuppapersize[*a*][*b*]. I want CropBox = MediaBox = *b*.
> So far, so good: I can just use cropoffset=0mm in \setuplayout. But I want
> TrimBox = *a*. However, as far as I can see, I can't achieve this using
> trimoffset in \setuplayout unless (width of *b*) – (width of *a*) =
> (height of *b*) – (height of *a*), which does not hold in my case. So it
> looks like I need to find another way to set the TrimBox (and the BleedBox,
> which I want to be 3mm wider and taller than the TrimBox). Does anyone know
> how to do this?
>
> Best,
>
> Jack
>

[-- Attachment #1.2: Type: text/html, Size: 2562 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug in PDF boxes? (was: Re: Trouble setting PDF boxes))
  2020-04-25 12:37 Trouble setting PDF boxes Jack Steyn
  2020-04-25 16:42 ` Jack Steyn
@ 2020-04-26  9:46 ` Pablo Rodriguez
  2020-04-26 14:43   ` Jack Steyn
  1 sibling, 1 reply; 7+ messages in thread
From: Pablo Rodriguez @ 2020-04-26  9:46 UTC (permalink / raw)
  To: ntg-context

On 4/25/20 2:37 PM, Jack Steyn wrote:
> Hi,
>
> I am having trouble setting the PDF boxes to my desired dimensions.
> Suppose I have \setuppapersize[/a/][/b/]. I want CropBox = MediaBox
> =/ //b/. So far, so good: I can just use cropoffset=0mm in \setuplayout.
> But I want TrimBox = /a/. However, as far as I can see, I can't achieve
> this using trimoffset in \setuplayout unless (width of /b/) – (width of
> /a/) = (height of /b/) – (height of /a/), which does not hold in my
> case. So it looks like I need to find another way to set the TrimBox
> (and the BleedBox, which I want to be 3mm wider and taller than the
> TrimBox). Does anyone know how to do this?

Hi Jack,

there seems to be a bug in ConTeXt (both in MkXL and MkIV).

From this code:

    \setuplayout
     [cropoffset=15ex,
      trimoffset=20ex,
      bleedoffset=25ex,
      artoffset=30ex]

    \starttext
    \input zapf
    \stoptext

I get the relevant code:

  /CropBox [ 0 0 595.2756 841.8898 ]
  /MediaBox [ 0 0 595.2756 841.8898 ]
  /TrimBox [ 0 0 595.2756 841.8898 ]

I think it might be a bug that prevents this from working properly.
(ArtBox is simply disabled.)

Hans, could you check this? Many thanks for your help.

Pablo

PS: sorry for having changed the subject, Jack. It intends only to
increase visibility about code that may need to be improved.
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: bug in PDF boxes? (was: Re: Trouble setting PDF boxes))
  2020-04-26  9:46 ` bug in PDF boxes? (was: Re: Trouble setting PDF boxes)) Pablo Rodriguez
@ 2020-04-26 14:43   ` Jack Steyn
  0 siblings, 0 replies; 7+ messages in thread
From: Jack Steyn @ 2020-04-26 14:43 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 2447 bytes --]

I would like to add though that even if the code you posted did work
properly, Pablo, it wouldn't solve my original problem. It would be good if
cropoffset, trimoffset etc. took two dimensions, one for the x direction
and one for the y direction, instead of one for both. But I appreciate you
changing the subject to increase visibility.

Jack

On Sun, 26 Apr 2020 at 19:47, Pablo Rodriguez <oinos@gmx.es> wrote:

> On 4/25/20 2:37 PM, Jack Steyn wrote:
> > Hi,
> >
> > I am having trouble setting the PDF boxes to my desired dimensions.
> > Suppose I have \setuppapersize[/a/][/b/]. I want CropBox = MediaBox
> > =/ //b/. So far, so good: I can just use cropoffset=0mm in \setuplayout.
> > But I want TrimBox = /a/. However, as far as I can see, I can't achieve
> > this using trimoffset in \setuplayout unless (width of /b/) – (width of
> > /a/) = (height of /b/) – (height of /a/), which does not hold in my
> > case. So it looks like I need to find another way to set the TrimBox
> > (and the BleedBox, which I want to be 3mm wider and taller than the
> > TrimBox). Does anyone know how to do this?
>
> Hi Jack,
>
> there seems to be a bug in ConTeXt (both in MkXL and MkIV).
>
> From this code:
>
>     \setuplayout
>      [cropoffset=15ex,
>       trimoffset=20ex,
>       bleedoffset=25ex,
>       artoffset=30ex]
>
>     \starttext
>     \input zapf
>     \stoptext
>
> I get the relevant code:
>
>   /CropBox [ 0 0 595.2756 841.8898 ]
>   /MediaBox [ 0 0 595.2756 841.8898 ]
>   /TrimBox [ 0 0 595.2756 841.8898 ]
>
> I think it might be a bug that prevents this from working properly.
> (ArtBox is simply disabled.)
>
> Hans, could you check this? Many thanks for your help.
>
> Pablo
>
> PS: sorry for having changed the subject, Jack. It intends only to
> increase visibility about code that may need to be improved.
> --
> http://www.ousia.tk
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________
>

[-- Attachment #1.2: Type: text/html, Size: 3442 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Trouble setting PDF boxes
  2020-04-25 16:42 ` Jack Steyn
@ 2020-04-30 15:51   ` Jack Steyn
  2020-04-30 19:44     ` Hans Hagen
  0 siblings, 1 reply; 7+ messages in thread
From: Jack Steyn @ 2020-04-30 15:51 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 4411 bytes --]

Hello, I'm happy to report that I got this working after much trawling
through the source and documentation. The code below produces a pdf with
the MediaBox, CropBox, BleedBox and TrimBox all in the places I specified
in my original message. I hope it helps illustrate how to set these PDF
boxes using Lua. I would much appreciate any feedback on how the Lua code
can be cleaned up or made more flexible (the bleed is hard-coded in because
I didn't know how to obtain the user-specified bleedoffset, for example),
or made better in any other way.

Jack

\setuppapersize[A5][A4]

\setuplayout[location=middle, marking=on]

\setupinteraction
  [title={TestDoc},
   author={Anon}]

\setupbackend
  [format=PDF/X-1a:2003,
   intent={ISO Coated v2 300\letterpercent\space (ECI)}]

\setupinteractionscreen[width=max,height=max]

\startluacode
moduledata.mystuff={}
respecify_pdf_boxes = function()
    local pdfverbose = lpdf.verbose
    local factor = number.dimenfactors.bp
    local f_value = string.formatters["\letterpercent.6N"]

    local function boxvalue(n)
        return pdfverbose(f_value(factor * n))
    end

    local paperwidth = tex.dimen.printpaperwidth
    local paperheight = tex.dimen.printpaperheight
    local pagewidth = tex.dimen.paperwidth
    local pageheight = tex.dimen.paperheight
    local bleedoffset = 3 / number.dimenfactors.mm
    local pdfarray = lpdf.array

    lpdf.addtopageattributes("MediaBox", pdfarray {
        boxvalue(0),
        boxvalue(0),
        boxvalue(paperwidth),
        boxvalue(paperheight),})

    lpdf.addtopageattributes("CropBox", pdfarray {
        boxvalue(0),
        boxvalue(0),
        boxvalue(paperwidth),
        boxvalue(paperheight),})

    lpdf.addtopageattributes("TrimBox", pdfarray {
        boxvalue((paperwidth - pagewidth) / 2),
        boxvalue((paperheight - pageheight) / 2),
        boxvalue((paperwidth + pagewidth) / 2),
        boxvalue((paperheight + pageheight) / 2),})

    lpdf.addtopageattributes("BleedBox", pdfarray {
        boxvalue((paperwidth - pagewidth) / 2 - bleedoffset),
        boxvalue((paperheight - pageheight) / 2 - bleedoffset),
        boxvalue((paperwidth + pagewidth) / 2 + bleedoffset),
        boxvalue((paperheight + pageheight) / 2 + bleedoffset),})
end

moduledata.mystuff.respecify_pdf_boxes = respecify_pdf_boxes

lpdf.registerpagefinalizer(moduledata.mystuff.respecify_pdf_boxes,
"respecify pdf boxes")
\stopluacode

\starttext
test
\stoptext

On Sun, 26 Apr 2020 at 02:42, Jack Steyn <steynjack@gmail.com> wrote:

> After much searching, my probably laughable attempt consists of combining
> the answer to the question at
> https://tex.stackexchange.com/questions/433110/setting-page-attributes-of-every-page-in-a-generated-context-file with
> what I can see in the source at
> https://source.contextgarden.net/tex/context/base/mkiv/lpdf-mis.lua:
>
> \appendtoks
>   \startluacode
>       local formatters = string.formatters
>
>       local pdfverbose = lpdf.verbose
>       local pdfarray = lpdf.array
>
>       local factor  = number.dimenfactors.bp
>       local f_value = formatters["\letterpercent.6N"]
>
>       local function boxvalue(n)
>           return pdfverbose(f_value(factor * n))
>       end
>
>       lpdf.addtopageattributes("TrimBox", pdfarray {
>           boxvalue(30),
>           boxvalue(30),
>           boxvalue(180),
>           boxvalue(267),})
>   \stopluacode
> \to \aftereverypage
>
> This code throws no errors, but unfortunately it also has no effect. What
> am I doing wrong?
>
> Jack
>
> On Sat, 25 Apr 2020 at 22:37, Jack Steyn <steynjack@gmail.com> wrote:
>
>> Hi,
>>
>> I am having trouble setting the PDF boxes to my desired dimensions.
>> Suppose I have \setuppapersize[*a*][*b*]. I want CropBox = MediaBox = *b*.
>> So far, so good: I can just use cropoffset=0mm in \setuplayout. But I want
>> TrimBox = *a*. However, as far as I can see, I can't achieve this using
>> trimoffset in \setuplayout unless (width of *b*) – (width of *a*) =
>> (height of *b*) – (height of *a*), which does not hold in my case. So it
>> looks like I need to find another way to set the TrimBox (and the BleedBox,
>> which I want to be 3mm wider and taller than the TrimBox). Does anyone know
>> how to do this?
>>
>> Best,
>>
>> Jack
>>
>

[-- Attachment #1.2: Type: text/html, Size: 5858 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Trouble setting PDF boxes
  2020-04-30 15:51   ` Jack Steyn
@ 2020-04-30 19:44     ` Hans Hagen
  2020-05-01  1:55       ` Jack Steyn
  0 siblings, 1 reply; 7+ messages in thread
From: Hans Hagen @ 2020-04-30 19:44 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Jack Steyn

On 4/30/2020 5:51 PM, Jack Steyn wrote:
> Hello, I'm happy to report that I got this working after much trawling 
> through the source and documentation. The code below produces a pdf with 
> the MediaBox, CropBox, BleedBox and TrimBox all in the places I 
> specified in my original message. I hope it helps illustrate how to set 
> these PDF boxes using Lua. I would much appreciate any feedback on how 
> the Lua code can be cleaned up or made more flexible (the bleed is 
> hard-coded in because I didn't know how to obtain the user-specified 
> bleedoffset, for example), or made better in any other way.
can you try this

\setuplayout
   [cropoffset=30pt,
    bleedoffset=20pt,
    trimoffset=10pt]

\setupinteractionscreen
   [width=max,height=max]

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Trouble setting PDF boxes
  2020-04-30 19:44     ` Hans Hagen
@ 2020-05-01  1:55       ` Jack Steyn
  0 siblings, 0 replies; 7+ messages in thread
From: Jack Steyn @ 2020-05-01  1:55 UTC (permalink / raw)
  To: Hans Hagen; +Cc: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1682 bytes --]

Hi Hans, using that produces a pdf which fails compliance with PDF/X-1a as
the BleedBox is not set. But notice that if it did work, the sizes of
TrimBox and BleedBox would be based off printpaperwidth and
printpaperheight. I need them to be based off paperwidth and paperheight
(for my documents all have printpaperwidth – paperwidth ≠ printpaperheight
– paperheight).

(Apologies, I initially replied to just you and not the list as well.)

On Fri, 1 May 2020 at 05:44, Hans Hagen <j.hagen@xs4all.nl> wrote:

> On 4/30/2020 5:51 PM, Jack Steyn wrote:
> > Hello, I'm happy to report that I got this working after much trawling
> > through the source and documentation. The code below produces a pdf with
> > the MediaBox, CropBox, BleedBox and TrimBox all in the places I
> > specified in my original message. I hope it helps illustrate how to set
> > these PDF boxes using Lua. I would much appreciate any feedback on how
> > the Lua code can be cleaned up or made more flexible (the bleed is
> > hard-coded in because I didn't know how to obtain the user-specified
> > bleedoffset, for example), or made better in any other way.
> can you try this
>
> \setuplayout
>    [cropoffset=30pt,
>     bleedoffset=20pt,
>     trimoffset=10pt]
>
> \setupinteractionscreen
>    [width=max,height=max]
>
> -----------------------------------------------------------------
>                                            Hans Hagen | PRAGMA ADE
>                Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>         tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
>

[-- Attachment #1.2: Type: text/html, Size: 2251 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-01  1:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-25 12:37 Trouble setting PDF boxes Jack Steyn
2020-04-25 16:42 ` Jack Steyn
2020-04-30 15:51   ` Jack Steyn
2020-04-30 19:44     ` Hans Hagen
2020-05-01  1:55       ` Jack Steyn
2020-04-26  9:46 ` bug in PDF boxes? (was: Re: Trouble setting PDF boxes)) Pablo Rodriguez
2020-04-26 14:43   ` Jack Steyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).