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 via email to