* Django: using ConTeXT mkiv to output PDF
@ 2018-01-24 14:15 kaddour kardio
2018-01-25 10:47 ` Henning Hraban Ramm
0 siblings, 1 reply; 10+ messages in thread
From: kaddour kardio @ 2018-01-24 14:15 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 3280 bytes --]
i have a small Django app <https://bitbucket.org/kaddourkardio/kardiology> to
manage my patients data, and use LaTeX to output reports. It consists un a
*parent* model called Patients and child models Consultation , StressEcho and
so on. With LaTex this works without problems
def courrier_pdf(request, pk2, pk1):
entry = Courrier.objects.get(pk=pk2)
source = Patient.objects.get(pk=pk1)
context = dict({'courrier': entry, 'patient': source})#buffer =
BytesIO()template = get_template('courrier/courrier.tex')
rendered_tpl = template.render(context,
request).encode('utf-8')#Python3 only. For python2 check out the
docs!with tempfile.TemporaryDirectory() as tempdir:
# Create subprocess, supress output with PIPE and
# run latex twice to generate the TOC properly.
# Finally read the generated pdf.
for i in range(2):
process = Popen(
['xelatex', '-output-directory', tempdir],
stdin=PIPE,
stdout=PIPE,
)
process.communicate(rendered_tpl)
with open(os.path.join(tempdir, 'texput.pdf'), 'rb') as f:
pdf = f.read()
r = HttpResponse(content_type='application/pdf')
r.write(pdf)return r
i tried with this view in order to use ConTeXT but without success
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:
process = Popen(['context', '--result', tempdir],
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
My feeling is that the problem is in the workspace since i get logfiles in
the root of my app Here is log file from ConTeXT:
open source > level 1, order 1, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-yes.mkiv'
system >
system > ConTeXt ver: 2018.01.04 17:37 MKIV beta fmt:
2018.1.4 int: english/english
system >
system > 'cont-new.mkiv' loaded
open source > level 2, order 2, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-new.mkiv'
close source > level 2, order 2, name '/home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-new.mkiv'
system > files > jobname 'tmpy82c5j7i', input
'/tmp/tmpy82c5j7i', result 'tmpy82c5j7i'
fonts > latin modern fonts are not preloaded
languages > language 'en' is active
tex error > tex error on line 8 in file /home/kaddour/context/tex/texmf-
context/tex/context/base/mkiv/cont-yes.mkiv: ! I can't find file
`/tmp/tmpy82c5j7i'.
l.8 }
I tried this in my view
os.chdirw(tempdir)
just before process without success.
My guess is that ConTeXT option --result= does not behave exactly like
LaTeX's -output-directoryAny help is welcome i really need ConTeXT for my
work and this problem is driving me mad!
--
Dr YAHYAOUI Mohamed Kaddour, cardiologue -- Clinique KARDIA.
[-- Attachment #1.2: Type: text/html, Size: 133036 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-24 14:15 Django: using ConTeXT mkiv to output PDF kaddour kardio
@ 2018-01-25 10:47 ` Henning Hraban Ramm
2018-01-25 13:58 ` kaddour kardio
0 siblings, 1 reply; 10+ messages in thread
From: Henning Hraban Ramm @ 2018-01-25 10:47 UTC (permalink / raw)
To: mailing list for ConTeXt users
Am 2018-01-24 um 15:15 schrieb kaddour kardio <kaddourkardio@gmail.com>:
> i have a small Django app to manage my patients data, and use LaTeX to output reports. It consists un a parent model called Patients and child models Consultation , StressEcho and so on. With LaTex this works without problems
> My guess is that ConTeXT option --result= does not behave exactly like LaTeX's -output-directoryAny help is welcome i really need ConTeXT for my work and this problem is driving me mad!
Yes, --result doesn’t work with directories, just filenames.
In my own Django app that uses ConTeXt, I just copy/generate all the needes files into one work directory per process.
Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
GPG Key ID 1C9B22FD
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-25 10:47 ` Henning Hraban Ramm
@ 2018-01-25 13:58 ` kaddour kardio
2018-01-25 14:19 ` Hans Hagen
0 siblings, 1 reply; 10+ messages in thread
From: kaddour kardio @ 2018-01-25 13:58 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1601 bytes --]
Can you please give me a snippet on how you manage working in another
directory ?
On Thursday, January 25, 2018, Henning Hraban Ramm <texml@fiee.net> wrote:
> Am 2018-01-24 um 15:15 schrieb kaddour kardio <kaddourkardio@gmail.com>:
>
> > i have a small Django app to manage my patients data, and use LaTeX to
> output reports. It consists un a parent model called Patients and child
> models Consultation , StressEcho and so on. With LaTex this works without
> problems
>
> > My guess is that ConTeXT option --result= does not behave exactly like
> LaTeX's -output-directoryAny help is welcome i really need ConTeXT for my
> work and this problem is driving me mad!
>
> Yes, --result doesn’t work with directories, just filenames.
>
> In my own Django app that uses ConTeXt, I just copy/generate all the
> needes files into one work directory per process.
>
>
> Greetlings, Hraban
> ---
> http://www.fiee.net
> http://wiki.contextgarden.net
> GPG Key ID 1C9B22FD
>
> ____________________________________________________________
> _______________________
> 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
> ____________________________________________________________
> _______________________
--
Dr YAHYAOUI Mohamed Kaddour, cardiologue -- Clinique KARDIA.
[-- Attachment #1.2: Type: text/html, Size: 2442 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-25 13:58 ` kaddour kardio
@ 2018-01-25 14:19 ` Hans Hagen
2018-01-26 18:41 ` kaddour kardio
0 siblings, 1 reply; 10+ messages in thread
From: Hans Hagen @ 2018-01-25 14:19 UTC (permalink / raw)
To: ntg-context
On 1/25/2018 2:58 PM, kaddour kardio wrote:
> Can you please give me a snippet on how you manage working in another
> directory ?
mtxrun --path=/data/foo --script context .....
> On Thursday, January 25, 2018, Henning Hraban Ramm <texml@fiee.net
> <mailto:texml@fiee.net>> wrote:
>
> Am 2018-01-24 um 15:15 schrieb kaddour kardio
> <kaddourkardio@gmail.com <mailto:kaddourkardio@gmail.com>>:
>
> > i have a small Django app to manage my patients data, and use
> LaTeX to output reports. It consists un a parent model called
> Patients and child models Consultation , StressEcho and so on. With
> LaTex this works without problems
>
> > My guess is that ConTeXT option --result= does not behave exactly
> like LaTeX's -output-directoryAny help is welcome i really need
> ConTeXT for my work and this problem is driving me mad!
>
> Yes, --result doesn’t work with directories, just filenames.
>
> In my own Django app that uses ConTeXt, I just copy/generate all the
> needes files into one work directory per process.
>
>
> Greetlings, Hraban
> ---
> http://www.fiee.net
> http://wiki.contextgarden.net
> GPG Key ID 1C9B22FD
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an
> entry to the Wiki!
>
> maillist : ntg-context@ntg.nl <mailto:ntg-context@ntg.nl> /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> <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/
> <https://bitbucket.org/phg/context-mirror/commits/>
> wiki : http://contextgarden.net
> ___________________________________________________________________________________
>
>
>
> --
> Dr YAHYAOUI Mohamed Kaddour, cardiologue -- Clinique KARDIA.
>
>
>
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>
--
-----------------------------------------------------------------
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-25 14:19 ` Hans Hagen
@ 2018-01-26 18:41 ` kaddour kardio
2018-01-27 10:18 ` Hans Hagen
2018-01-28 17:59 ` Pablo Rodriguez
0 siblings, 2 replies; 10+ messages in thread
From: kaddour kardio @ 2018-01-26 18:41 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 1035 bytes --]
>
> 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.
[-- Attachment #1.2: Type: text/html, Size: 2652 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-26 18:41 ` kaddour kardio
@ 2018-01-27 10:18 ` Hans Hagen
2018-01-28 17:59 ` Pablo Rodriguez
1 sibling, 0 replies; 10+ messages in thread
From: Hans Hagen @ 2018-01-27 10:18 UTC (permalink / raw)
To: mailing list for ConTeXt users, kaddour kardio
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-26 18:41 ` kaddour kardio
2018-01-27 10:18 ` Hans Hagen
@ 2018-01-28 17:59 ` Pablo Rodriguez
2018-01-28 23:33 ` kaddour kardio
1 sibling, 1 reply; 10+ messages in thread
From: Pablo Rodriguez @ 2018-01-28 17:59 UTC (permalink / raw)
To: ntg-context
On 01/26/2018 07:41 PM, kaddour kardio wrote:
> [...]
> i tried this without success :(
> the only workaround u've found for now is to render a tex file and
> copile it manually.
I don’t know how to invoke ConTeXt using Django, but to create booklets
with my favourite text editor (Geany, https://geany.org/).
While --result could handle path in it, my command to create booklets was:
contextjit --purgeall --path="%d" --arguments=filename=%e.pdf
--result=/home/ousia/"%e-2UP.pdf" /home/ousia/A5-to-A4_landscape-booklet.tex
"%d" and %e" stand for directory and file name without extension.
After --path was introduced (or it was mandatory to use it, since
--result cannot handle path in it), my command reads:
cd && contextjit --purgeall --path="%d" --arguments=filename=%d/%e.pdf
--result="%e-2UP.pdf" /home/ousia/A5-to-A4_landscape-booklet.tex
I wonder whether my previous comment might help you to improve your
ConTeXt in Django.
Best wishes,
Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-28 17:59 ` Pablo Rodriguez
@ 2018-01-28 23:33 ` kaddour kardio
2018-02-02 12:22 ` kaddour kardio
0 siblings, 1 reply; 10+ messages in thread
From: kaddour kardio @ 2018-01-28 23:33 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 552 bytes --]
i think i am one step closer to my goal.
alla i have is to combine:
1- What Hans taught me about working on file (and not simply stdout) python
has already a module *tempfile.NamedTemporaryFile()* ,
2- Your snippet to run ConTeXT inside the temporary folder *cd &&
contextjit --purgeall --path="%d" --arguments=filename=%d/%e.pdf*
*--result="%e-2UP.pdf" /home/ousia/A5-to-A4_landscape-booklet.tex*
**To be adapted for a working example ( tomorrow i have a night shift so
probably tuesday i will work on again).
Thank you everybody!
[-- Attachment #1.2: Type: text/html, Size: 1794 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Django: using ConTeXT mkiv to output PDF
2018-01-28 23:33 ` kaddour kardio
@ 2018-02-02 12:22 ` kaddour kardio
2018-02-02 12:49 ` Hans Hagen
0 siblings, 1 reply; 10+ messages in thread
From: kaddour kardio @ 2018-02-02 12:22 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1.1: Type: text/plain, Size: 885 bytes --]
Still working on the issue, i have a simple (comehow related) question:
since the PDF generated is a binary, i can pipe it through the stdout ?
On Mon, Jan 29, 2018 at 12:33 AM, kaddour kardio <kaddourkardio@gmail.com>
wrote:
> i think i am one step closer to my goal.
> alla i have is to combine:
> 1- What Hans taught me about working on file (and not simply stdout)
> python has already a module *tempfile.NamedTemporaryFile()* ,
> 2- Your snippet to run ConTeXT inside the temporary folder *cd &&
> contextjit --purgeall --path="%d" --arguments=filename=%d/%e.pdf*
> *--result="%e-2UP.pdf" /home/ousia/A5-to-A4_landscape-booklet.tex*
>
> **To be adapted for a working example ( tomorrow i have a night shift
> so probably tuesday i will work on again).
>
> Thank you everybody!
>
>
--
Dr YAHYAOUI Mohamed Kaddour, cardiologue -- Clinique KARDIA.
[-- Attachment #1.2: Type: text/html, Size: 2703 bytes --]
[-- Attachment #2: Type: text/plain, Size: 492 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-02-02 12:49 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24 14:15 Django: using ConTeXT mkiv to output PDF 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
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
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).