ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Ramkumar KB <ramkumarkb@gmail.com>
To: ntg-context@ntg.nl, Hans Hagen <j.hagen@xs4all.nl>
Subject: Re: Running mtxrun in a continuous batch mode
Date: Wed, 4 Nov 2020 11:48:00 +0800	[thread overview]
Message-ID: <CAMD5SRMpLNUYoCjfvb2rrMy6V4RMyxF_gqsUhWk-P4yd2k=_6w@mail.gmail.com> (raw)
In-Reply-To: <001a4cfc-d1ec-dbc9-0f2a-3d9bf613a035@xs4all.nl>


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

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 <j.hagen@xs4all.nl> 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
> -----------------------------------------------------------------
>

[-- Attachment #1.2: Type: text/html, Size: 4476 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
___________________________________________________________________________________

  reply	other threads:[~2020-11-04  3:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03  0:55 Ramkumar KB
2020-11-03 11:02 ` Hans Hagen
2020-11-04  3:48   ` Ramkumar KB [this message]
2020-11-04 11:24     ` Hans Hagen
2020-11-06  8:38       ` Ramkumar KB
2020-11-06  8:47         ` thierry horsin
2020-11-06 14:51           ` Aditya Mahajan
2020-11-07  1:29             ` Ramkumar KB

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMD5SRMpLNUYoCjfvb2rrMy6V4RMyxF_gqsUhWk-P4yd2k=_6w@mail.gmail.com' \
    --to=ramkumarkb@gmail.com \
    --cc=j.hagen@xs4all.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).