From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107129 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Jack Steyn Newsgroups: gmane.comp.tex.context Subject: Re: Trouble setting PDF boxes Date: Fri, 1 May 2020 01:51:29 +1000 Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3974143481351532805==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="31257"; mail-complaints-to="usenet@ciao.gmane.io" To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Apr 30 17:52:36 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jUBUJ-0007zv-P7 for gctc-ntg-context-518@m.gmane-mx.org; Thu, 30 Apr 2020 17:52:35 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id E2B7F183926; Thu, 30 Apr 2020 17:52:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MSb3ArApSxg0; Thu, 30 Apr 2020 17:52:00 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id DF67918392F; Thu, 30 Apr 2020 17:52:00 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 5596618392A for ; Thu, 30 Apr 2020 17:52:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id whePieqx20tG for ; Thu, 30 Apr 2020 17:51:59 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.210.182; helo=mail-pf1-f182.google.com; envelope-from=steynjack@gmail.com; receiver= Original-Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 3178F183926 for ; Thu, 30 Apr 2020 17:51:59 +0200 (CEST) Original-Received: by mail-pf1-f182.google.com with SMTP id x15so3067254pfa.1 for ; Thu, 30 Apr 2020 08:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=x2dquMi7O/4fSjuvrpgoV3Fw51ZPZJ+c9IHhsyAhFBc=; b=UY/+M4EIMJLA8uh0mRhdfUHXINS6YxDdU4CY9mGPRFOKIbOMwOJ+C9a0z0WOr1vAko BpKiEM2p6fpQzqtom9HjeiVNLitYgC4AJ9tXxei4dHmFpvD48v3pOEbZiu5otOK/vRkU Q1vlckML7GsIgJ8RZf6XFAbs2o+4fm8Pgw8Gdu6fxALAbR8mP3zcThIuvdd8XSYUZsdx Xhne0cpOFf01ILHzI+v3xhkXPuX5qZDWaQGFnqjXOW11p4Z0en5aMM7u6OseghCyyfCa SAP7yfuuHnzrJxQduqVuTnBgW7q9egA1kJ4q4gnO8qaasXDmDcY6z83laP3qq7Xoxzpb XXBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=x2dquMi7O/4fSjuvrpgoV3Fw51ZPZJ+c9IHhsyAhFBc=; b=tk051e+gZtn7RH5/AX24KkzNcomS/E4eYqOn+qu3zvkbmtMMP/9RhB+U18/MkpJSD6 maCMrDpzrQ/ywNKjjr+IhyVPlg2JBuuvUHMN1fe5TCBXZh86ZeVBjRS9A5beSJBNivY2 iG/1Agy9pbaGd5WTZjNpGKw8YRdwY+rUxOogmNA6hQVDoB1B8MGO0nDfGJuOcoA9xDzT 27XY43Miq815Z/53Fw90WPvKthsW9Tqx8nh2d+R2iabLAj1NZ1HS41oNOyuwq0ccXmuq lsVZw7QLMVkkFSUFummHzgNVJlp6RtgI1A833tzKR0855TZUNQ40N5PGYc7ddqhYJA96 ms9g== X-Gm-Message-State: AGi0PuagxCeJYEdot8hC+NUSp2TErnFL0YK8Yn2WU22a67nS2NSkGKib DR1dw/2cn2A6hGnKgNoF7yE7mpOAlFlARM+pS3kAGQ== X-Google-Smtp-Source: APiQypIxnex2u8bGm6ogjvp7hHvnHv5edqz1eU4sASYiWc1cw0FtuiQZAJgEat+sGlwiLrVGm+lSoyrhVTEQ6y9caIw= X-Received: by 2002:a63:951b:: with SMTP id p27mr3874864pgd.49.1588261917284; Thu, 30 Apr 2020 08:51:57 -0700 (PDT) In-Reply-To: X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107129 Archived-At: --===============3974143481351532805== Content-Type: multipart/alternative; boundary="00000000000063df7505a4840b22" --00000000000063df7505a4840b22 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=3Dmiddle, marking=3Don] \setupinteraction [title=3D{TestDoc}, author=3D{Anon}] \setupbackend [format=3DPDF/X-1a:2003, intent=3D{ISO Coated v2 300\letterpercent\space (ECI)}] \setupinteractionscreen[width=3Dmax,height=3Dmax] \startluacode moduledata.mystuff=3D{} respecify_pdf_boxes =3D function() local pdfverbose =3D lpdf.verbose local factor =3D number.dimenfactors.bp local f_value =3D string.formatters["\letterpercent.6N"] local function boxvalue(n) return pdfverbose(f_value(factor * n)) end local paperwidth =3D tex.dimen.printpaperwidth local paperheight =3D tex.dimen.printpaperheight local pagewidth =3D tex.dimen.paperwidth local pageheight =3D tex.dimen.paperheight local bleedoffset =3D 3 / number.dimenfactors.mm local pdfarray =3D 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 =3D 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 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 =3D string.formatters > > local pdfverbose =3D lpdf.verbose > local pdfarray =3D lpdf.array > > local factor =3D number.dimenfactors.bp > local f_value =3D 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 wrote: > >> Hi, >> >> I am having trouble setting the PDF boxes to my desired dimensions. >> Suppose I have \setuppapersize[*a*][*b*]. I want CropBox =3D MediaBox = =3D *b*. >> So far, so good: I can just use cropoffset=3D0mm in \setuplayout. But I = want >> TrimBox =3D *a*. However, as far as I can see, I can't achieve this usin= g >> trimoffset in \setuplayout unless (width of *b*) =E2=80=93 (width of *a*= ) =3D >> (height of *b*) =E2=80=93 (height of *a*), which does not hold in my cas= e. So it >> looks like I need to find another way to set the TrimBox (and the BleedB= ox, >> which I want to be 3mm wider and taller than the TrimBox). Does anyone k= now >> how to do this? >> >> Best, >> >> Jack >> > --00000000000063df7505a4840b22 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 illu= strate how to set these PDF boxes using Lua. I would much appreciate any fe= edback on how the Lua code can be cleaned up or made more flexible (the ble= ed is hard-coded in because I didn't know how to obtain the user-specif= ied bleedoffset, for example), or made better in any other way.

Jac= k

\setuppapersize[A5][A4]

\setuplayout[location= =3Dmiddle, marking=3Don]

\setupinteraction
=C2=A0 [title=3D{TestD= oc},
=C2=A0 =C2=A0author=3D{Anon}]

\setupbackend
=C2=A0 [forma= t=3DPDF/X-1a:2003,
=C2=A0 =C2=A0intent=3D{ISO Coated v2 300\letterpercen= t\space (ECI)}]

\setupinteractionscreen[width=3Dmax,height=3Dmax]
\startluacode
moduledata.mystuff=3D{}
respecify_pdf_boxes =3D fu= nction()
=C2=A0 =C2=A0 local pdfverbose =3D lpdf.verbose
=C2=A0 =C2= =A0 local factor =3D number.dimenfactors.bp
=C2=A0 =C2=A0 local f_value = =3D string.formatters["\letterpercent.6N"]

=C2=A0 =C2=A0 l= ocal function boxvalue(n)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return pdfverbose(= f_value(factor * n))
=C2=A0 =C2=A0 end

=C2=A0 =C2=A0 local paperw= idth =3D tex.dimen.printpaperwidth
=C2=A0 =C2=A0 local paperheight =3D t= ex.dimen.printpaperheight
=C2=A0 =C2=A0 local pagewidth =3D tex.dimen.pa= perwidth
=C2=A0 =C2=A0 local pageheight =3D tex.dimen.paperheight
=C2= =A0 =C2=A0 local bleedoffset =3D 3 / number.dimenfactors.mm
=C2=A0 =C2=A0 local pdfarray =3D lpdf.arr= ay

=C2=A0 =C2=A0 lpdf.addtopageattributes("MediaBox", pdfa= rray {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue(0),
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 boxvalue(0),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue(paperwidth),=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue(paperheight),})

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

=C2=A0 =C2=A0 lpdf.addtopageattribut= es("TrimBox", pdfarray {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue(= (paperwidth - pagewidth) / 2),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue((pap= erheight - pageheight) / 2),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue((paper= width + pagewidth) / 2),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue((paperheig= ht + pageheight) / 2),})

=C2=A0 =C2=A0 lpdf.addtopageattributes(&quo= t;BleedBox", pdfarray {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue((paper= width - pagewidth) / 2 - bleedoffset),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 boxva= lue((paperheight - pageheight) / 2 - bleedoffset),
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 boxvalue((paperwidth + pagewidth) / 2 + bleedoffset),
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 boxvalue((paperheight + pageheight) / 2 + bleedoffset),})=
end

moduledata.mystuff.respecify_pdf_boxes =3D respecify_pdf_box= es

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

\starttext
tes= t
\stoptext

On Sun, 26 Apr 2020 at 02:42, Jack Steyn <= steynjack@gmail.co= m> wrote:
After much searching, my probably laughable attempt consi= sts of combining the answer to the question at=C2=A0https://tex.stackexchange.com/= questions/433110/setting-page-attributes-of-every-page-in-a-generated-conte= xt-file=C2=A0with what I can see in the source at=C2=A0https://source.contextgarden.net/tex/context/base/mkiv/lpdf-mis.lua<= /a>:

\appendtoks
=C2=A0 \startluacode
=C2=A0 =C2= =A0 =C2=A0 local formatters =3D string.formatters

=C2=A0 =C2=A0 =C2= =A0 local pdfverbose =3D lpdf.verbose
=C2=A0 =C2=A0 =C2=A0 local pdfarra= y =3D lpdf.array

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

=C2=A0 =C2=A0 =C2=A0 local function boxvalu= e(n)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return pdfverbose(f_value(factor= * n))
=C2=A0 =C2=A0 =C2=A0 end

=C2=A0 =C2=A0 =C2=A0 lpdf.addtopa= geattributes("TrimBox", pdfarray {
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 boxvalue(30),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue(30),=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 boxvalue(180),
=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 boxvalue(267),})
=C2=A0 \stopluacode
\to \aftereverypa= ge

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

J= ack

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

I am having trouble setting the PDF boxes to my desired= dimensions. Suppose I have \setuppapersize[a][b].=C2=A0I wan= t CropBox =3D MediaBox =3D=C2=A0b.= So far, so good: I can just use cropoffset=3D0mm in \setuplayout. But I wa= nt TrimBox =3D a. However, as far as I can see, I can't achieve = this using trimoffset in \setuplayout unless (width of b) =E2=80=93 = (width of a) =3D (height of b) =E2=80=93 (height of a)= , which does not hold in my case. So=C2=A0it looks like I need to find anot= her 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
--00000000000063df7505a4840b22-- --===============3974143481351532805== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============3974143481351532805==--