ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	kaddour kardio <kaddourkardio@gmail.com>
Subject: Re: Django: using ConTeXT mkiv to output PDF
Date: Sat, 27 Jan 2018 11:18:57 +0100	[thread overview]
Message-ID: <0be7ef25-3c38-1ea4-59e1-783a420fdaa5@wxs.nl> (raw)
In-Reply-To: <CAL7_PC7nT0zXsZpkntnvmrtxQSDbQmePGWOb8PGm7xXsfZDF4A@mail.gmail.com>

On 1/26/2018 7:41 PM, kaddour kardio wrote:
>     def courrier_mkiv(request, pk2, pk1):
>          entry = Courrier.objects.get(pk=pk2)
>          cource = Patient.objects.get(pk=pk1)
>          context = dict({'courrier': entry, 'patient': cource})
>          # buffer = BytesIO()
>          template = get_template('courrier/courrier.mkiv')
>          rendered_tpl = template.render(context, request).encode('utf-8')
>          with tempfile.TemporaryDirectory() as tempdir:
>          # mtxrun --path=/data/foo --script context
>              process = Popen(['mtxrun', '--path', tempdir,
>                              '--script=context'
>                              '--result'],
>                              stdin=PIPE,
>                              stdout=PIPE,
>                              )
>              process.communicate(rendered_tpl)
>          with open(os.path.join(tempdir, 'textput.pdf'), 'rb') as f:
>              pdf = f.read()
>          r = HttpResponse(content_type='application/pdf')
>          r.write(pdf)
>          return r
> 
> 
> i tried this without success :(
> the only workaround u've found for now is to render a tex file and 
> copile it manually.
I have no clue what you do, but just running context should nto be that 
hard. And yes, you need a file (no piping of stdin) as there are 
normally multiple runs needes. Also, mkiv assumes that there is a file 
(tex, xml, ...) as it's actually an indirect process: if you run 
"context foo.tex" on the console you will see what gets actually called 
and the file loaded is "cont-yes.mkiv" which in turn will load whatever 
is needed as source.

Hans


-----------------------------------------------------------------
                                           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
___________________________________________________________________________________

  reply	other threads:[~2018-01-27 10:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 14:15 kaddour kardio
2018-01-25 10:47 ` Henning Hraban Ramm
2018-01-25 13:58   ` kaddour kardio
2018-01-25 14:19     ` Hans Hagen
2018-01-26 18:41       ` kaddour kardio
2018-01-27 10:18         ` Hans Hagen [this message]
2018-01-28 17:59         ` Pablo Rodriguez
2018-01-28 23:33           ` kaddour kardio
2018-02-02 12:22             ` kaddour kardio
2018-02-02 12:49               ` Hans Hagen

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=0be7ef25-3c38-1ea4-59e1-783a420fdaa5@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=kaddourkardio@gmail.com \
    --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).