You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by pedro <pe...@libero.it> on 2010/04/13 14:06:32 UTC

java.awt.image

Hi all
    i use 
    <fo:external-graphic scaling="non-uniform
                  <xsl:attribute name="src">
                         <xsl:value-of select="heading/logo"/>					  
            	</xsl:attribute>								</fo:external-graphic>

to diplay an image in my xsl.
Is possible to pass a java.awt.image object instead a image file?
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28229153.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by Venkat Reddy <va...@googlemail.com>.
Nope, the 'src' attribute should a valid URL to the file.

Venkat.

pedro wrote:
> Hi all
>     i use 
>     <fo:external-graphic scaling="non-uniform
>                   <xsl:attribute name="src">
>                          <xsl:value-of select="heading/logo"/>					  
>             	</xsl:attribute>								</fo:external-graphic>
>
> to diplay an image in my xsl.
> Is possible to pass a java.awt.image object instead a image file?
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: java.awt.image

Posted by Eric Douglas <ed...@blockhouse.com>.
Why is the image in a temp dir?  Why is it getting cleaned up?  That
sounds pretty odd.. How does it get there in the first place?  What
happens if it cleans it up before it reads it into memory?  Why not just
put the images in the same place as the xsl?
I explained in the previous message what the command does that you're
trying to use, so it really doesn't matter what you want.
You can want your computer to make your coffee but unless you physically
combine it with a coffee machine or connect it to an external machine,
it's not going to do it.
Java awt images work fine if you're using the xsl with an awt renderer
to make the PreviewPanel object, then building your own window and
placing the image.
If you want external-graphic to show your image you have to be able to
create a uri reference to it.
If you can't do that and you want to pull the image in another way,
you'll have to use another method (you'll most likely have to write your
own).

The simplest way as I said to reference an image and not have to worry
if the end user can find an image file is to write the image into the
xsl as svg draw commands.  How complicated is the image?  I was trying
to figure out the same thing, not worrying if the image would be
deleted, but trying to figure out how FOP would reference it if I need
relative or absolute paths and if they're processed server or client
side..


-----Original Message-----
From: pedro [mailto:pedro.riky@libero.it] 
Sent: Tuesday, April 13, 2010 11:21 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: java.awt.image


I want the object in memory because  the application run on Thin Client
in an
enviroment(network,workstations) that are no under my control and
sometimes i have a problem because the image that i wrote in my temp dir
is clean up by i don't know what,so i won't to understand why because i
have no access on the enviroment and i want to workaround the problem
with a image in memory.
--
View this message in context:
http://old.nabble.com/java.awt.image-tp28229153p28231773.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Sorry, but I have trouble understanding your question.

What I can say is that encoding an image as a Data URL, it does make it
bigger since the data has to be encoded in base64. If you have to save
the image in a database, you could investigate to actually save the
original image file and then build a servlet or URIResolver to access
the image data. The mailing list archive of this list contain ideas on
how to do that.

On 16.04.2010 11:10:41 pedro wrote:
> 
> Hi all !
> It works!Thanks for our helps!
> 
> But i have another question:
> when i create the url of the image i get a very long string, if i save it on
> a file i get a 187k of dimension, so if i have to save it on the db for all
> delivery notes that i save it can be a problem for space, my question is if
> the string that rappresent the url is always the same as the pc the os ecc
> is different or is the same and i can save it at once?
> 
> -- 
> View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28264701.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by pedro <pe...@libero.it>.
Hi all !
It works!Thanks for our helps!

But i have another question:
when i create the url of the image i get a very long string, if i save it on
a file i get a 187k of dimension, so if i have to save it on the db for all
delivery notes that i save it can be a problem for space, my question is if
the string that rappresent the url is always the same as the pc the os ecc
is different or is the same and i can save it at once?

-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28264701.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Apparently, the InputStream is empty for some reason. That's why there's
no data in the data URL. And the String parameter to createDataURL needs
to be null or a valid MIME type (ex. "image/png").

See also:
http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/util/uri/DataURLUtil.java?revision=695225&view=markup

HTH

On 14.04.2010 10:19:56 pedro wrote:
> 
> Hi Jeremias
>    thanks for your answer.
>    i try 
>         String ur = dataURLUtil.createDataURL(bufferFile.getIn(),"RFC
> 2397");
>         and ur is     "data:RFC 2397;base64,"
> 
> then in my xsl i do that 
> 
> <fo:external-graphic scaling="uniform">									<xsl:attribute name="src">
> 	             	<xsl:value-of
> select="concat('url(',concat(heading/logo,')'))"/>
> 		</xsl:attribute>
> </fo:external-graphic>
> 
> but not works it say me I/O error while loading image: null
> 
> where i'm in fault?
> -- 
> View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28239719.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 
> 


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by pedro <pe...@libero.it>.
Hi Jeremias
   thanks for your answer.
   i try 
        String ur = dataURLUtil.createDataURL(bufferFile.getIn(),"RFC
2397");
        and ur is     "data:RFC 2397;base64,"

then in my xsl i do that 

<fo:external-graphic scaling="uniform">									<xsl:attribute name="src">
	             	<xsl:value-of
select="concat('url(',concat(heading/logo,')'))"/>
		</xsl:attribute>
</fo:external-graphic>

but not works it say me I/O error while loading image: null

where i'm in fault?
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28239719.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
There are several possibilities:

1. Serialize the image as an RFC 2397 data URL so you don't have to
write it out as a file. You can use
org.apache.xmlgraphics.util.uri.DataURLUtil.createDataURL(InputStream, String)
for that
(or org.apache.fop.util.DataURLUtil.createDataURL(InputStream, String)
if you have an older FOP).

2. Register a URIResolver with FOP where you can intercept a private URI
scheme and provide an InputStream. But that also requires serializing
the image to a (virtual) file.
http://xmlgraphics.apache.org/fop/latest/embedding.html#fop-factory
http://markmail.org/message/mxv4lx562lyhexza

3. Theoretically, it is possible to register a special Preloader with
the image loading framework which could work off a special Source
subclass where you can pass over a RenderedImage instance. But that's
advanced stuff and I've never tried it and I can't guarantee that it'll
work.
http://xmlgraphics.apache.org/commons/image-loader.html

HTH

On 13.04.2010 17:20:44 pedro wrote:
> 
> I want the object in memory because  the application run on Thin Client in an
> enviroment(network,workstations) that are no under my control and sometimes
> i have a problem because the image that i wrote in my temp dir is clean up
> by i don't know what,so i won't to understand why because i have no access
> on the enviroment and i want to workaround the problem with a image in
> memory.
> -- 
> View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28231773.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by pedro <pe...@libero.it>.
I want the object in memory because  the application run on Thin Client in an
enviroment(network,workstations) that are no under my control and sometimes
i have a problem because the image that i wrote in my temp dir is clean up
by i don't know what,so i won't to understand why because i have no access
on the enviroment and i want to workaround the problem with a image in
memory.
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28231773.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: java.awt.image

Posted by "Hu, Zemin" <Ze...@adp.com>.
Pedro,

Use tools like xstream to generate XML data file from you java data object which should not be hard to do and I would guess 90% of people here use this tool to generate xml data file. If you did this, then the encoded image data should be in your xml data already. You can directly reference your image data field without variable.

Hope it helps.

Zemin
-----Original Message-----
From: pedro [mailto:pedro.riky@libero.it] 
Sent: Wednesday, April 14, 2010 10:53 AM
To: fop-users@xmlgraphics.apache.org
Subject: RE: java.awt.image


Hi Hu
   excuse me but i'm going crazy.
   I create a encode64 bytearrayinputstream that is the image,then i pass my
xml data to xsl but i'm not able to pass the image ($embededLogo ) .I try to
create a xsl-variable but i don't understand how i can pass it to the fop
engine from the java code.
Thanks!
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28243722.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org

----------------------------------------------------------------------
This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, notify the sender immediately by return email and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: java.awt.image

Posted by pedro <pe...@libero.it>.
Hi Hu
   excuse me but i'm going crazy.
   I create a encode64 bytearrayinputstream that is the image,then i pass my
xml data to xsl but i'm not able to pass the image ($embededLogo ) .I try to
create a xsl-variable but i don't understand how i can pass it to the fop
engine from the java code.
Thanks!
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28243722.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: java.awt.image

Posted by "Hu, Zemin" <Ze...@adp.com>.
Pedro,

There is no direct solution. But you can use encoded binary image loading feature in couple of not complicated steps:
Step 1. Make your image to binary ready stream, then encode it by using base64, I used commons-codec-1.3.jar, then make it ready for your FOP-XSL to reference;
Step 2. Use following to embed the image to PDF:
<fo:external-graphic src="{concat('url(', &quot;'&quot;, 'data:image/auto;base64,', $embededLogo, &quot;'&quot;, ')')}"
	content-height="{$height}" content-width="{$width}"/>
$embededLogo is the local variable for the encoded image binary, then you are ready to go!

Zemin

-----Original Message-----
From: pedro [mailto:pedro.riky@libero.it] 
Sent: Tuesday, April 13, 2010 10:54 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: java.awt.image


I know, but i don't want to use a physical file but only one object that i
have in memory.
So i want to say if is possible to pass a java.awt.image or similar to the
xsl .

Thanks!
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28231355.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org

----------------------------------------------------------------------
This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, notify the sender immediately by return email and delete the message and any attachments from your system.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: java.awt.image

Posted by Eric Douglas <ed...@blockhouse.com>.
Src=uri (http://www.w3.org/TR/xsl/#src)
If you can point a uri to it, you can use it.
An image in memory might be useful for putting on a screen with the AWT
renderer.
I can think of any way you would reference a java object from an xsl
file.
If anything you'd have to code it in a custom function yourself and
point the xsl file to that using a namespace.
I'm fairly certain the external-graphic
(http://www.w3.org/TR/xsl/#fo_external-graphic) won't do it.

I couldn't figure out what sort of path to use to point the xsl to my
picture file, so I found a program to convert the file to a series of
svg:path fill statements and put the image right in the xsl.  It made
the output files a bit larger but it removes any headaches over making
sure it can find the graphic file.
 

-----Original Message-----
From: pedro [mailto:pedro.riky@libero.it] 
Sent: Tuesday, April 13, 2010 10:54 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: java.awt.image


I know, but i don't want to use a physical file but only one object that
i have in memory.
So i want to say if is possible to pass a java.awt.image or similar to
the xsl .

Thanks!
--
View this message in context:
http://old.nabble.com/java.awt.image-tp28229153p28231355.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: java.awt.image

Posted by pedro <pe...@libero.it>.
I know, but i don't want to use a physical file but only one object that i
have in memory.
So i want to say if is possible to pass a java.awt.image or similar to the
xsl .

Thanks!
-- 
View this message in context: http://old.nabble.com/java.awt.image-tp28229153p28231355.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org