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 meghnas <me...@gmail.com> on 2008/03/26 03:35:16 UTC

Relative URL for embedding graphics in FOP

HI All,

I have been generating a PDF file using FOP, I want to put a gif onto the
PDF. I can do this but only when the .gif file is on the C:/ drive of the
machine. I want to use relative path, so that it works for all users.
When I put the logo.gif in my c:/ drive and have the code as below it works:

<fo:table-row>
  <fo:table-cell number-columns-spanned="5">
    <fo:block text-align="left">
	<fo:external-graphic content-width="2.08in" content-height="0.72in"
src='url("/logo.gif")' />
    </fo:block>
  </fo:table-cell>
</fo:table-row>

I am looking for the syntax to use for src='url("/logo.gif")'
Notice the single outer quotes and the double inner quotes - it only works
this way for me. My <xsl:stylesheet version="1.0"> and also xml version is
1.0. The .gif file is actually in my Eclipse project workspace under
WebContent, I am just not sure how I can refer to it using relative path. I
have tried various different syntax combinations, but have been
unsuccessful.

Would really appreciate it, if someone could give me an example of using
relative path, particularly specifying where they put the actual .gif file.
I am interested specifically in where the .xsl file is located and where the
.gif is located, and the syntax of the src  property.

Any help, will be much much appreciated!

Thanks.
-- 
View this message in context: http://www.nabble.com/Relative-URL-for-embedding-graphics-in-FOP-tp16294358p16294358.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: Relative URL for embedding graphics in FOP

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
There's no need to send your question twice. It takes a short while
until a post shows up in Nabble.

If you use "./" as base URL, you're selecting the current directory of
your application as base URL and not the location of the stylesheet. If
you want to do this relative to the stylesheet, it's you who has to
provide the info where that stylesheet is. There are various
possibilities how this could be done in your code (obviously we don't
know your code, so we can only guess).

If it looks like this:
File xsltFile = new File("C:/Temp/mystylesheet.xsl");
Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));

then you can use:
userAgent.setBaseURL(xsltFile.getParentFile().toURL().toExternalForm());

It really depends how you set up your stylesheet.


On 26.03.2008 16:23:49 meghnas wrote:
> 
> Hi Jeremias ,
> 
> I found your response very useful. I have rewritten my code to use UserAgent
> we were using some old methods of FOP which are now deprecated. I am now
> back to getting the PDF generated correctly, after code restructuring. I am
> setting the base URL as follows:
> 
> FOUserAgent userAgent = fopFactory.newFOUserAgent();
> userAgent.setBaseURL("./");
> 
> I want the base URL to be where the .xsl file is currently located in the
> Eclipse project,  not a hardcoded absolute path like the one in the example
> in the links provided below, which suggest:
>  userAgent.setBaseURL("file:///C:/Temp/");
> 
> If I did this only the machine running the application with this folder
> structure will be able to set the base URL all other machines will not. so I
> set the base URL as userAgent.setBaseURL("./");
> However  when trying to generate PDF I get in the console:
> 
> [ INFO] 03/26/08 10:10:31 >: 
>     FOP base url is ./
> 
> [ERROR] 03/26/08 10:10:32 >: 
>     Error with base URL "./"): no protocol: ./
> 
> 
> I have placed the logo.gif in the same directory in Eclipse as the .xsl
> file, but it doesnt seem to like the base URL. Anybody know how to set
> baseURL to current location of .xsl.
> 
> I really appreciate any help.
> 
> Regards.
> 
> Jeremias Maerki-2 wrote:
> > 
> > What you're using is not a relative URL! It's actually an absolute
> > filename which FOP internally converts to an absolute file URL. The
> > leading slash makes it an absolute filename/URL.
> > 
> > A relative URL is this, for example:
> > 
> > <fo:external-graphic src="images/myimage.png"/>
> > 
> > Any relative URI/URL for images is then resolved against the base
> > URI/URL specified in the configuration. See "base" in:
> > http://xmlgraphics.apache.org/fop/stable/configuration.html#general-elements
> > 
> > Or "FOUserAgent.setBaseURL(String)":
> > http://xmlgraphics.apache.org/fop/stable/embedding.html#user-agent
> > 
> > On 26.03.2008 03:35:16 meghnas wrote:
> >> 
> >> HI All,
> >> 
> >> I have been generating a PDF file using FOP, I want to put a gif onto the
> >> PDF. I can do this but only when the .gif file is on the C:/ drive of the
> >> machine. I want to use relative path, so that it works for all users.
> >> When I put the logo.gif in my c:/ drive and have the code as below it
> >> works:
> >> 
> >> <fo:table-row>
> >>   <fo:table-cell number-columns-spanned="5">
> >>     <fo:block text-align="left">
> >> 	<fo:external-graphic content-width="2.08in" content-height="0.72in"
> >> src='url("/logo.gif")' />
> >>     </fo:block>
> >>   </fo:table-cell>
> >> </fo:table-row>
> >> 
> >> I am looking for the syntax to use for src='url("/logo.gif")'
> >> Notice the single outer quotes and the double inner quotes - it only
> >> works
> >> this way for me. My <xsl:stylesheet version="1.0"> and also xml version
> >> is
> >> 1.0. The .gif file is actually in my Eclipse project workspace under
> >> WebContent, I am just not sure how I can refer to it using relative path.
> >> I
> >> have tried various different syntax combinations, but have been
> >> unsuccessful.
> >> 
> >> Would really appreciate it, if someone could give me an example of using
> >> relative path, particularly specifying where they put the actual .gif
> >> file.
> >> I am interested specifically in where the .xsl file is located and where
> >> the
> >> .gif is located, and the syntax of the src  property.
> >> 
> >> Any help, will be much much appreciated!
> >> 
> >> Thanks.
> >> -- 
> >> View this message in context:
> >> http://www.nabble.com/Relative-URL-for-embedding-graphics-in-FOP-tp16294358p16294358.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
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/Relative-URL-for-embedding-graphics-in-FOP-tp16294358p16302994.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: Relative URL for embedding graphics in FOP

Posted by meghnas <me...@gmail.com>.
Hi Jeremias ,

I found your response very useful. I have rewritten my code to use UserAgent
we were using some old methods of FOP which are now deprecated. I am now
back to getting the PDF generated correctly, after code restructuring. I am
setting the base URL as follows:

FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setBaseURL("./");

I want the base URL to be where the .xsl file is currently located in the
Eclipse project,  not a hardcoded absolute path like the one in the example
in the links provided below, which suggest:
 userAgent.setBaseURL("file:///C:/Temp/");

If I did this only the machine running the application with this folder
structure will be able to set the base URL all other machines will not. so I
set the base URL as userAgent.setBaseURL("./");
However  when trying to generate PDF I get in the console:

[ INFO] 03/26/08 10:10:31 >: 
    FOP base url is ./

[ERROR] 03/26/08 10:10:32 >: 
    Error with base URL "./"): no protocol: ./


I have placed the logo.gif in the same directory in Eclipse as the .xsl
file, but it doesnt seem to like the base URL. Anybody know how to set
baseURL to current location of .xsl.

I really appreciate any help.

Regards.

Jeremias Maerki-2 wrote:
> 
> What you're using is not a relative URL! It's actually an absolute
> filename which FOP internally converts to an absolute file URL. The
> leading slash makes it an absolute filename/URL.
> 
> A relative URL is this, for example:
> 
> <fo:external-graphic src="images/myimage.png"/>
> 
> Any relative URI/URL for images is then resolved against the base
> URI/URL specified in the configuration. See "base" in:
> http://xmlgraphics.apache.org/fop/stable/configuration.html#general-elements
> 
> Or "FOUserAgent.setBaseURL(String)":
> http://xmlgraphics.apache.org/fop/stable/embedding.html#user-agent
> 
> On 26.03.2008 03:35:16 meghnas wrote:
>> 
>> HI All,
>> 
>> I have been generating a PDF file using FOP, I want to put a gif onto the
>> PDF. I can do this but only when the .gif file is on the C:/ drive of the
>> machine. I want to use relative path, so that it works for all users.
>> When I put the logo.gif in my c:/ drive and have the code as below it
>> works:
>> 
>> <fo:table-row>
>>   <fo:table-cell number-columns-spanned="5">
>>     <fo:block text-align="left">
>> 	<fo:external-graphic content-width="2.08in" content-height="0.72in"
>> src='url("/logo.gif")' />
>>     </fo:block>
>>   </fo:table-cell>
>> </fo:table-row>
>> 
>> I am looking for the syntax to use for src='url("/logo.gif")'
>> Notice the single outer quotes and the double inner quotes - it only
>> works
>> this way for me. My <xsl:stylesheet version="1.0"> and also xml version
>> is
>> 1.0. The .gif file is actually in my Eclipse project workspace under
>> WebContent, I am just not sure how I can refer to it using relative path.
>> I
>> have tried various different syntax combinations, but have been
>> unsuccessful.
>> 
>> Would really appreciate it, if someone could give me an example of using
>> relative path, particularly specifying where they put the actual .gif
>> file.
>> I am interested specifically in where the .xsl file is located and where
>> the
>> .gif is located, and the syntax of the src  property.
>> 
>> Any help, will be much much appreciated!
>> 
>> Thanks.
>> -- 
>> View this message in context:
>> http://www.nabble.com/Relative-URL-for-embedding-graphics-in-FOP-tp16294358p16294358.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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Relative-URL-for-embedding-graphics-in-FOP-tp16294358p16302994.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: Relative URL for embedding graphics in FOP

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
What you're using is not a relative URL! It's actually an absolute
filename which FOP internally converts to an absolute file URL. The
leading slash makes it an absolute filename/URL.

A relative URL is this, for example:

<fo:external-graphic src="images/myimage.png"/>

Any relative URI/URL for images is then resolved against the base
URI/URL specified in the configuration. See "base" in:
http://xmlgraphics.apache.org/fop/stable/configuration.html#general-elements

Or "FOUserAgent.setBaseURL(String)":
http://xmlgraphics.apache.org/fop/stable/embedding.html#user-agent

On 26.03.2008 03:35:16 meghnas wrote:
> 
> HI All,
> 
> I have been generating a PDF file using FOP, I want to put a gif onto the
> PDF. I can do this but only when the .gif file is on the C:/ drive of the
> machine. I want to use relative path, so that it works for all users.
> When I put the logo.gif in my c:/ drive and have the code as below it works:
> 
> <fo:table-row>
>   <fo:table-cell number-columns-spanned="5">
>     <fo:block text-align="left">
> 	<fo:external-graphic content-width="2.08in" content-height="0.72in"
> src='url("/logo.gif")' />
>     </fo:block>
>   </fo:table-cell>
> </fo:table-row>
> 
> I am looking for the syntax to use for src='url("/logo.gif")'
> Notice the single outer quotes and the double inner quotes - it only works
> this way for me. My <xsl:stylesheet version="1.0"> and also xml version is
> 1.0. The .gif file is actually in my Eclipse project workspace under
> WebContent, I am just not sure how I can refer to it using relative path. I
> have tried various different syntax combinations, but have been
> unsuccessful.
> 
> Would really appreciate it, if someone could give me an example of using
> relative path, particularly specifying where they put the actual .gif file.
> I am interested specifically in where the .xsl file is located and where the
> .gif is located, and the syntax of the src  property.
> 
> Any help, will be much much appreciated!
> 
> Thanks.
> -- 
> View this message in context: http://www.nabble.com/Relative-URL-for-embedding-graphics-in-FOP-tp16294358p16294358.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