[reportlab-users] inserting image in dynamic .prep file without saving image first

Robin Becker robin at reportlab.com
Fri Aug 29 05:16:35 EDT 2014


On 29/08/2014 01:00, David wrote:
> Dear list,
>
> following this recipe ( http://stackoverflow.com/a/19160507 ), I am
> trying to emulate the "not saving an image on the hard disk" approach
> for z3c and preppy in an dynamic .prep file.
>
> I fail and hope for your wisdom.
>
> Two questions:
>



> a) what object type does z3c.rml expect for images?
I'm not exactly sure what's meant here: rml contains only text so unless z3c.rml 
provides plugin flowables or graphics theres only text available.


> b) How would you suggest do I approach the goal of not saving images on
> my hard drive yet inserting them in a pdf via z3c?
>
in modern rml you can use an inlineData tag inside an image tag. Our tests 
include this

<illustration height="200" width="150">	
	<image file="" x="0" y="0">
		<inlineData filters="ascii85 
gzip">Gaob at B35f%hoFCm>=?Gi.rhAp;,b;f,==7C>I_7M'on0oMCEGjZHTBh:!;#n7qH68DOY<?C0#"@bDN`&TDSYY(['=on[krFIEqTY4eZ:-1s\Q7i!$o?_#G/]#R#]D?n`E!JO#o*(^pV(_\!0-QBi:!M+"%6BJ^W[_-jNM*"IbEj0c;&#m>j?NXh1BeCE+"e'ldtf-c\O"pP9dL5
.............
[U.b0P5FS5q at Ae$iXUOQR?/_]6\uD;_Wi*G.Y<&_n\uUU-5QCdGa-HhT~></inlineData>
	</image>
</illustration>

so in your prep file you can just create the image as bytes and convert to a 
readable form using various compressions and encodings. The dtd says this


<!ELEMENT image (inlineData?)>
<!ATTLIST image
     file CDATA #REQUIRED
     x CDATA #REQUIRED
     y CDATA #REQUIRED
     width CDATA #IMPLIED
     height CDATA #IMPLIED
     inline CDATA #IMPLIED
     transparency_mask CDATA "auto"
     preserveAspectRatio (yes | no | 0 | 1) #IMPLIED
     showBoundary (yes | no | 0 | 1) #IMPLIED
     anchor (n|ne|e|se|s|sw|w|nw|c) #IMPLIED
     pdfBoxType (MediaBox | CropBox| TrimBox | BleedBox | ArtBox) #IMPLIED
     required (yes | no | 0 | 1 | true | false) "true"
	alt_file CDATA #IMPLIED
     type (pdf|bitmap)	#IMPLIED
 >
<!ELEMENT inlineData (#PCDATA)>
<!--inlineData filters is a space separated list of filters which are applied in 
order
	 allowed filters are
	 base64 | ascii85 | bzip2 | gzip
	 -->
<!ATTLIST inlineData
	filters CDATA #REQUIRED
	>
<!ELEMENT setFont EMPTY>
<!ATTLIST setFont
     name CDATA #REQUIRED
     size CDATA #REQUIRED
     leading CDATA #IMPLIED
 >


> Thanks for your guidance and creativity!
>
> David
....

-- 
Robin Becker


More information about the reportlab-users mailing list