Re: ReportLab and Django Examples
Mike Hostetler <[email protected]>
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <CAE1_9RVqxC5WLckgnHct4WY0iUyOBvciHkh4LNJS-BqdF2fDeg@mail.gmail.com> |
Just to help you out - page 7 of the User Guide also needs to be updated: - outputFileNamewhen specified overrides any output file name specified in the xml input text. You may also pass in a file-like object (e.g. a *StringIO*, file object or web request buffer), in which case noth- ing is written to disk. On Tue, Nov 27, 2018 at 2:27 PM Mike Hostetler <[email protected]> wrote: > Duh. I should have thought of the BytesIO... but I have verified that your > method works! > > Thanks! > > On Tue, Nov 27, 2018 at 12:35 PM Andy Robinson <[email protected]> wrote: > >> Hi Mike, >> >> Under Python 3, you need to use the BytesIO class, since PDF is a >> binary format. Since we're writing file-like data, StringIO is no >> longer appropriate. This works.... >> >> import io >> buf = io.BytesIO() >> rml2pdf.go(rml, outputFileName=buf) >> >> # to retrieve the data... >> buf.seek(0) >> rawdata = buf.read() . # gives you back the bytes >> >> I'll try to create a full minimal Django example in the next day or so >> and update the manual... >> On Mon, 26 Nov 2018 at 20:56, Mike Hostetler <[email protected]> >> wrote: >> > >> > I got something that works... >> > >> > fp,fname = tempfile.mkstemp() >> > rml2pdf.go(rml,outputFileName=fname) >> > buf = open(fname,encoding = "ISO-8859-1") >> > >> > But I don't like creating the tempfile. I think rml2pdf.go should take >> a StringIO >> > >> > On Mon, Nov 26, 2018 at 2:13 PM Andy Robinson <[email protected]> >> wrote: >> >> >> >> On Mon, 26 Nov 2018 at 19:43, Mike Hostetler < >> [email protected]> wrote: >> >> > >> >> > I knew it waa old but that was all you had... >> >> > I'm using Python 3.6.6 and Django 2.1.3. >> >> >> >> Sorry, we'd never spotted it before, as all of our customer projects >> >> are on 2.7. I'll try to get a corrected snippet out tomorrow.. >> >> _______________________________________________ >> >> reportlab-users mailing list >> >> [email protected] >> >> https://pairlist2.pair.net/mailman/listinfo/reportlab-users >> > >> > >> > >> > -- >> > Mike Hostetler >> > SquarePeg Systems >> > http://www.squarepegsystems.com >> > _______________________________________________ >> > reportlab-users mailing list >> > [email protected] >> > https://pairlist2.pair.net/mailman/listinfo/reportlab-users >> >> >> >> -- >> Andy Robinson >> Managing Director, ReportLab >> Wimbletech Zone 2 >> 35 Wimbledon Hill Road >> London SW19 7NB, UK >> Tel +44-20-8191-7277 >> _______________________________________________ >> reportlab-users mailing list >> [email protected] >> https://pairlist2.pair.net/mailman/listinfo/reportlab-users >> > > > -- > Mike Hostetler > SquarePeg Systems > http://www.squarepegsystems.com > -- Mike Hostetler SquarePeg Systems http://www.squarepegsystems.com