 |
 |
 |
 |
 |
PDF Generating Tool Support Forum |
 |
|
Topic review - A definition of custom resource loaders |
Post subject: Re: A definition of custom resource loaders |
In general you cannot place images to particular places of document layout via PD4ML API or with resource loaders.
You define your document layout using HTML and the images positions are defined by a locations of <img> tags.
If you plan to load images from a database, you may define your own image loading protocol. For example:
<img src="database:table=images;key=4711">
Your custom resource loader should parse the string "database:table=images;key=4711" and perform a corresponding request to the database (using the key value to locate a proper image) via JDBC (or similar).
In general you cannot place images to particular places of document layout via PD4ML API or with resource loaders.
You define your document layout using HTML and the images positions are defined by a locations of [b]<img>[/b] tags.
If you plan to load images from a database, you may define your own image loading protocol. For example:
[b]<img src="database:table=images;key=4711">[/b]
Your custom resource loader should parse the string "database:table=images;key=4711" and perform a corresponding request to the database (using the key value to locate a proper image) via JDBC (or similar).
|
|
|
PD4ML
 |
Posted: 05 Oct 2011, 16:19 |
|
|
|
 |
Post subject: Re: A definition of custom resource loaders |
Hi,
Do you have an example JSP and ResoruceProvider Class for reading multiple images from the database? I am looking for a way to place the images at a particular place on the PDF using the ResourceProvide method.
Thanks
Hi,
Do you have an example JSP and ResoruceProvider Class for reading multiple images from the database? I am looking for a way to place the images at a particular place on the PDF using the ResourceProvide method.
Thanks
|
|
|
Guest
 |
Posted: 23 Sep 2011, 00:58 |
|
|
|
 |
Post subject: Re: A definition of custom resource loaders |
Is CustomFileResourceProvider.class in the classpath?
If so, try to enable debug (pd4ml.enableDebugInfo()) and inspect server's log.
Is [b]CustomFileResourceProvider.class[/b] in the classpath?
If so, try to enable debug ([b]pd4ml.enableDebugInfo()[/b]) and inspect server's log.
|
|
|
PD4ML
 |
Posted: 06 Sep 2011, 12:11 |
|
|
|
 |
Post subject: Re: A definition of custom resource loaders |
Hi,
Do you have any example code for using the Custom Resource loader using Java/JSP.
I have this code in my Filter : map.put( "pd4ml.extra.resource.loaders", "CustomFileResourceProvider"); pd4ml.setDynamicParams(map);
But I don't see CustomFileResourceProvider getting called.
Any help would be really appreciated?
Thanks
Hi,
Do you have any example code for using the Custom Resource loader using Java/JSP.
I have this code in my Filter : map.put( "pd4ml.extra.resource.loaders", "CustomFileResourceProvider"); pd4ml.setDynamicParams(map);
But I don't see CustomFileResourceProvider getting called.
Any help would be really appreciated?
Thanks
|
|
|
Guest
 |
Posted: 05 Sep 2011, 21:15 |
|
|
|
 |
Post subject: Re: A definition of custom resource loaders |
> Is there a way I can pass the InputStream of the image as an arguement to the ResourceProvider.
You need to reference somehow the image in the database from an HTML source. It is up to you: you may even implement a repository of InputStreams (which would be a quite strange architectural decision) and refer to them by a unique input stream ID:
<img src="file:inputstream#4711">
In the resource loader you'll receive "file:inputstream#4711" image URI to be parsed, to select the corresponding input stream and to read the referred image.
But of course a better approach is to specify in the image URI some unique key, sufficient to lookup and to read database image with your custom resource loader.
> Is there a way I can pass the InputStream of the image as an arguement to the ResourceProvider.
You need to reference somehow the image in the database from an HTML source. It is up to you: you may even implement a repository of InputStreams (which would be a quite strange architectural decision) and refer to them by a unique input stream ID:
<img src="file:inputstream#4711">
In the resource loader you'll receive "file:inputstream#4711" image URI to be parsed, to select the corresponding input stream and to read the referred image.
But of course a better approach is to specify in the image URI some unique key, sufficient to lookup and to read database image with your custom resource loader.
|
|
|
PD4ML
 |
Posted: 30 Aug 2011, 19:21 |
|
|
|
 |
Post subject: Re: A definition of custom resource loaders |
Hi, I need to extract multiple images from database and put them on the PDF. Is there a way I can pass the InputStream of the image as an arguement to the ResourceProvider.
Thanks
Hi, I need to extract multiple images from database and put them on the PDF. Is there a way I can pass the InputStream of the image as an arguement to the ResourceProvider.
Thanks
|
|
|
Guest
 |
Posted: 29 Aug 2011, 23:04 |
|
|
|
 |
Post subject: A definition of custom resource loaders |
In most of the situations PD4ML is able to resolve relative or absolute resource references (to images, to CSS etc) and load them. However there are special cases, when the default mechanisms are not sufficient. For example: - The resources are stored in an unusual place, i.e. in a database.
- The resources are referenced by an "exotic" or non-standard protocol. For instance, Weblogic and WebSphere SSL implementations are not derived from the standard JDK SSL classes PD4ML relies on, so it causes ClassCastException.
As a workaround PD4ML allows you to create your own resource loader, which takes an URL as a parameter, and should return the loaded resource as an array of bytes. import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.zefer.cache.ResourceProvider;
public class CustomFileResourceProvider extends ResourceProvider {
public byte[] getResourceAsBytes(String resource, boolean debugOn) throws IOException {
ByteArrayOutputStream fos = new ByteArrayOutputStream();
byte buffer[] = new byte[2048];
InputStream is = null;
resource = "http://pd4ml.com/i/" + resource;
URL src = new URL(resource);
URLConnection urlConnect = src.openConnection();
try {
urlConnect.connect();
} catch (Throwable e) {
return new byte[0];
}
is = urlConnect.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
int read;
do {
read = is.read(buffer, 0, buffer.length);
if (read > 0) { // something to put down
fos.write(buffer, 0, read);
}
} while (read > -1);
fos.close();
bis.close();
is.close();
return fos.toByteArray();
}
} In order to enable the loader, you may either pass to PD4ML the class name with an environment variable (add the following to JVM command line): -Dpd4ml.extra.resource.loaders=CustomFileResourceProvideror via API call: HashMap map = new HashMap();
map.put( "pd4ml.extra.resource.loaders", "CustomFileResourceProvider" );
pd4ml.setDynamicParams(map); It may also be a coma-separated list of multiple resource loaders.
In most of the situations PD4ML is able to resolve relative or absolute resource references (to images, to CSS etc) and load them. However there are special cases, when the default mechanisms are not sufficient.
For example:
[list] [*] The resources are stored in an unusual place, i.e. in a database. [*] The resources are referenced by an "exotic" or non-standard protocol. For instance, Weblogic and WebSphere SSL implementations are not derived from the standard JDK SSL classes PD4ML relies on, so it causes ClassCastException.[/list]
As a workaround PD4ML allows you to create your own resource loader, which takes an URL as a parameter, and should return the loaded resource as an array of bytes.
[language=java]import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection;
import org.zefer.cache.ResourceProvider;
public class CustomFileResourceProvider extends ResourceProvider {
public byte[] getResourceAsBytes(String resource, boolean debugOn) throws IOException { ByteArrayOutputStream fos = new ByteArrayOutputStream(); byte buffer[] = new byte[2048];
InputStream is = null; resource = "http://pd4ml.com/i/" + resource; URL src = new URL(resource); URLConnection urlConnect = src.openConnection(); try { urlConnect.connect(); } catch (Throwable e) { return new byte[0]; } is = urlConnect.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is);
int read; do { read = is.read(buffer, 0, buffer.length); if (read > 0) { // something to put down fos.write(buffer, 0, read); } } while (read > -1);
fos.close(); bis.close(); is.close();
return fos.toByteArray(); } }[/language]
In order to enable the loader, you may either pass to PD4ML the class name with an environment variable (add the following to JVM command line):
[b]-Dpd4ml.extra.resource.loaders=CustomFileResourceProvider[/b]
or via API call:
[language=java]HashMap map = new HashMap(); map.put( "pd4ml.extra.resource.loaders", "CustomFileResourceProvider" ); pd4ml.setDynamicParams(map);[/language]
It may also be a coma-separated list of multiple resource loaders.
|
|
|
PD4ML
 |
Posted: 02 Jun 2009, 12:03 |
|
|
|
 |
|

|
 |
 |
|
 |
Copyright ©2004-10 zefer|org. All rights reserved. |
|
|
 |
|
 |