From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/109193 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ramkumar KB Newsgroups: gmane.comp.tex.context Subject: Re: Running mtxrun in a continuous batch mode Date: Wed, 4 Nov 2020 11:48:00 +0800 Message-ID: References: <001a4cfc-d1ec-dbc9-0f2a-3d9bf613a035@xs4all.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6178870834320266082==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14923"; mail-complaints-to="usenet@ciao.gmane.io" To: ntg-context@ntg.nl, Hans Hagen Original-X-From: ntg-context-bounces@ntg.nl Wed Nov 04 04:49:26 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 1ka9nZ-0003my-IT for gctc-ntg-context-518@m.gmane-mx.org; Wed, 04 Nov 2020 04:49:25 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 89F701A9B7C; Wed, 4 Nov 2020 04:48:17 +0100 (CET) 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 n2uJjyVoKR2O; Wed, 4 Nov 2020 04:48:15 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D339F1A9D3F; Wed, 4 Nov 2020 04:48:15 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id E97C11A9B7C for ; Wed, 4 Nov 2020 04:48:14 +0100 (CET) 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 PxZ0C_u8O9T9 for ; Wed, 4 Nov 2020 04:48:13 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.208.181; helo=mail-lj1-f181.google.com; envelope-from=ramkumarkb@gmail.com; receiver= Original-Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) (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 1C8941A9B7A for ; Wed, 4 Nov 2020 04:48:12 +0100 (CET) Original-Received: by mail-lj1-f181.google.com with SMTP id 2so21401566ljj.13 for ; Tue, 03 Nov 2020 19:48:12 -0800 (PST) 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=5jcFt26UV5F3fBlbos1lwbJKSTngysHyAiTT1ikW2IM=; b=mJ/LEc3c0NHNkgvOwL1r7gmMtah5x38fcYnT26I51iQ9Q1f/XXpqcyvZ+Bw83tdWJ/ ILfL/ccGBgP7XRGKr3smyQ9wSw3aJHkllHxhVt13QjqHLz/mxAEU2Me68AaPp8g2BGW3 RbCaitAtrIcOL55KIs7ROEtB+pfwZn1KsEeemorCZGIRjWXwC02MQu7FCZqxytW3lg4J i+d/0bB6kqkhphXvGobqrMP0RnrV8aSJhC9fT+Cq3wTzznKEhHOxVnywOAS+oYsdL6/Y tmXKviiGDpTtFRZcRNFQsXzIReKza8p16pflp9EC1RdCIn2rhFhAm6HwQxicfSua5ElH zw/A== 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=5jcFt26UV5F3fBlbos1lwbJKSTngysHyAiTT1ikW2IM=; b=pyXJN65qkeIuRRQCcsL2u74Vi/AWCBnAGRhwSRM9bvrUhs08PMknYjTXNqDEFuGYtR 7AB54nbvIbf0FULVVIuyz56EKNGk8DSaEIAb9oQvcBDMOQ4oRVLS8r9RmwZQCRyDxfkG 13ZRN9x0YHZz48mr/FUg0ElwAhNdp6chwmLvzTTMtEedQgAbnOPlhYRPGizR3kab7R5R b7Lpf4HN5IJCD/k0xnl5MOUaQA7+VJYzRLFo0lQYjF5c5uRuRgoCkknBdNnFHOVaUDme dIJeuD66AzKIB/ipV13GBGXsssoUbQ+hj9EtABBq2GGbL3EKTqA+dESFWr6Qg/0YV+if fjKg== X-Gm-Message-State: AOAM531D+4CTWjVP1KyLdUHWn4FQZ+8QkzCuAhB7qwH9E21e7QQema/3 704Dnz6s9+bg9uqtFE1jv7Shq+jt4dhfYX72cw7zO4ttucA= X-Google-Smtp-Source: ABdhPJw7fufZYrlC3vhXOQaHrvjga745mbHq81zRcCWq87vNJsWw+oRG7VTQF2mA7n2PZnTZGd8BixSjsf0u56yrREo= X-Received: by 2002:a2e:87c6:: with SMTP id v6mr10327054ljj.233.1604461692133; Tue, 03 Nov 2020 19:48:12 -0800 (PST) In-Reply-To: <001a4cfc-d1ec-dbc9-0f2a-3d9bf613a035@xs4all.nl> 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:109193 Archived-At: --===============6178870834320266082== Content-Type: multipart/alternative; boundary="00000000000037241f05b33fd94b" --00000000000037241f05b33fd94b Content-Type: text/plain; charset="UTF-8" Hans, Thank you so much for the kind response. Apologies that I was not very clear in my initial query. I have - 1. MyStatement.tex, with all the necessary fonts, static text, images, header, footer etc 2. MyStatement.tex reads from a JSON file for certain sections of the document for the dynamic content 3. context MyStatement.tex produces MyStatement.pdf How do I do the above steps 1 to 3 in a continuous fashion such that - - Output is MyStatement_1.pdf (reads from data_1.json), MyStatement_2.pdf (reads from data_2.json) and so on - The tex processing is fast as fonts etc are loaded once (as the Tex template is same for all the MyStatement_n.pdf) >From the sample code that you gave, I get a hint that this can be possibly done using ConTeXt Lua Document approach. Is this correct? Thank you once again, Best, Ramkumar On Tue, Nov 3, 2020 at 7:02 PM Hans Hagen wrote: > On 11/3/2020 1:55 AM, Ramkumar KB wrote: > > Hello, > > > > I am trying to run mtxrun in a batch process and read the available > > documentation here - > > https://wiki.contextgarden.net/Running_ConTeXt_without_a_shell > > > > My usecase is being able to create PDF docs based on the input data that > > comes in a JSON format (in a continuous batch process). In ConTeXt, > > thanks to the Lua engine, I am able to inject a JSON read from a file - > > and use the JSON in the tex file (here variable `tab` holds the JSON). > > > > How do I make this as a continuous webservice - in comes JSON and out > > comes the PDF ? > > > > \startluacode > > require("test-json") > > \stopluacode > > > > The name of the document is \ctxlua{tex.print(tab['documentName'])} > > > > Any tips or pointers would be much appreciated. > foo.cld : > > require("util-jsn") > > -- local str = io.loaddata("somefile.json") > > local str = [[ { > "title": "Some JSON", > "text" : "Just an example.", > "data" : [ > { "a" : "first 1", "b" : "last 1" }, > { "b" : "last 2", "a" : "first 2" } > ] > } ]] > > local tmp = utilities.json.tolua(str) > > context.starttext() > > context.starttitle { title = tmp.title } > > context(tmp.text) context.par() > > context.starttabulate { "|c|c|" } > for i=1,#tmp.data do > local d = tmp.data[i] > context.NC() > context(d.a) context.NC() > context(d.b) context.NC() > context.NR() > end > context.stoptabulate() > > context.stoptitle() > > context.stoptext() > > and then > > context foo.cld > > > ----------------------------------------------------------------- > Hans Hagen | PRAGMA ADE > Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > ----------------------------------------------------------------- > --00000000000037241f05b33fd94b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hans,

Thank you so much for the kind re= sponse.=C2=A0

Apologies=C2=A0that I was not very c= lear in my initial=C2=A0query. I have -=C2=A0
  1. MyStatement= .tex, with all the necessary fonts, static text, images, header, footer etc=
  2. MyStatement.tex reads from a JSON file for certain sections of the= document for the dynamic content
  3. context = MyStatement.tex produces MyStatement.pdf=C2=A0
How do I do the above steps 1 to 3 in a cont= inuous fashion such that -=C2=A0
  • Output is MyStatement_1.pdf (reads from data_1.json), MyStatement_2.pdf (reads from data_2.json) and so on
  • The tex processing is fast as fonts etc are loaded once (as the Tex te= mplate is same for all the MyStatement_n.pdf)
From the sample code that you gave, I get a hint that this= can be possibly done using ConTeXt Lua Document approach. Is this correct?=

Thank you once again,

<= div>Best,
Ramkumar

On Tue, Nov 3, 2020 at 7:02 PM Hans Hagen= <j.hagen@xs4all.= nl> wrote:
https://wiki.contextgarden.net/Ru= nning_ConTeXt_without_a_shell
>
> My usecase=C2=A0is being=C2=A0able to create PDF docs based on the inp= ut data that
> comes in a JSON=C2=A0format (in a continuous batch process). In ConTeX= t,
> thanks to the Lua engine, I am able to inject a JSON read from a file = -
> and use the JSON in the tex file (here variable `tab` holds the JSON).=
>
> How do I make this as a continuous webservice - in comes JSON and out =
> comes the PDF ?
>
> \startluacode
> require("test-json")
> \stopluacode
>
> The=C2=A0name=C2=A0of=C2=A0the=C2=A0document=C2=A0is=C2=A0\ctxlua{tex.= print(tab['documentName'])}
>
> Any tips or pointers would be much appreciated.
foo.cld :

require("util-jsn")

-- local str =3D io.loaddata("somefile.json")

local str =3D [[ {
=C2=A0 =C2=A0 =C2=A0"title": "Some JSON",
=C2=A0 =C2=A0 =C2=A0"text" : "Just an example.",
=C2=A0 =C2=A0 =C2=A0"data" : [
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ "a" : "first 1", &q= uot;b" : "last 1" },
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ "b" : "last 2", &qu= ot;a" : "first 2" }
=C2=A0 =C2=A0 =C2=A0]
} ]]

local tmp =3D utilities.json.tolua(str)

context.starttext()

=C2=A0 =C2=A0 =C2=A0context.starttitle { title =3D tmp.title }

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0context(tmp.text) context.par()

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0context.starttabulate { "|c|c|"= }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for i=3D1,#tmp.data do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0local d =3D t= mp.data[i]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0context.NC()<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0context(d.a) context.NC()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0context(d.b) context.NC()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0context.NR()<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0context.stoptabulate()

=C2=A0 =C2=A0 =C2=A0context.stoptitle()

context.stoptext()

and then

context foo.cld


-----------------------------------------------------------------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Hans Hagen | PRAGMA ADE
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ridderstraat 27 | 80= 61 GH Hasselt | The Netherlands
=C2=A0 =C2=A0 =C2=A0 =C2=A0 tel: 038 477 53 69 | www.pragma-ade.nl | www.= pragma-pod.nl
-----------------------------------------------------------------
--00000000000037241f05b33fd94b-- --===============6178870834320266082== 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== --===============6178870834320266082==--