PDF Generating Tool Support Forum

HOME   Login   Register    Search

Post a reply
Message body:
Enter your message here, it may contain no more than 60000 characters. 

Font size:
Font colour
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are OFF
Disable BBCode
Do not automatically parse URLs
Confirmation of post
To prevent automated posts the board requires you to enter a confirmation code. The code is displayed in the image you should see below. If you are visually impaired or cannot otherwise read this code please contact the Board Administrator.
Confirmation code:
Enter the code exactly as it appears. All letters are case insensitive, there is no zero.

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).
    Post Posted: 05 Oct 2011, 16:19
Post subject:  Re: A definition of custom resource loaders

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.

    Post 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.
    Post Posted: 06 Sep 2011, 12:11
Post subject:  Re: A definition of custom resource loaders

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");

But I don't see CustomFileResourceProvider getting called.

Any help would be really appreciated?

    Post 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.
    Post Posted: 30 Aug 2011, 19:21
Post subject:  Re: A definition of custom resource loaders
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.

    Post 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 {
		} 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);


		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):


or via API call:

HashMap map = new HashMap();
map.put( "pd4ml.extra.resource.loaders", "CustomFileResourceProvider" );

It may also be a coma-separated list of multiple resource loaders.
    Post Posted: 02 Jun 2009, 12:03

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