Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Creating PDF output on demand
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating PDF output on demand



Hi Stefan!

There's an example of iText integration with WO here: http:// hugi.karlmenn.is/page/webobjects .

I was working on a PDF project the other day, and found that I had to write some very complex iText code to achieve what I wanted. I took a look at FO, and that is indeed very fun to work with, but unfortunately, Apache FOP does not support some of the stuff I needed to do.
I ended up using a nice little library called PD4ML which allows you to design your document in HTML and then converts the HTML to PDF for you. It even has limited support for CSS.
If commercial software is an option for you, you can download an evaluation version here: http://pd4ml.zefer.org/ .


Here's some simple example code for generating PDF with it (basically ripped from the PD4ML tutorial, but with an added WO twist):

	import org.zefer.pd4ml.PD4ML;
	import org.zefer.pd4ml.PD4Constants;
	import java.awt.Dimension;
	import java.awt.Insets;
	import java.io.ByteArrayOutputStream;
	import java.io.StringReader;

public static NSData convertHTMLToPDF( String htmlString, boolean isLandscape ) {

Dimension format = PD4Constants.A4;


		// margins in millimeters
		int topValue = 10;
		int leftValue = 10;
		int rightValue = 10;
		int bottomValue = 10;

		// Width of the HTML
		int userSpaceWidth = 780;

		ByteArrayOutputStream bos = new ByteArrayOutputStream();

		try {
			PD4ML pd4ml = new PD4ML();

if( isLandscape ) {
format = pd4ml.changePageOrientation( format );
}

pd4ml.setPageSize( format );
pd4ml.setPageInsetsMM( new Insets(topValue, leftValue, bottomValue, rightValue) );


			pd4ml.setHtmlWidth( userSpaceWidth );
			pd4ml.enableImgSplit( true );
			pd4ml.enableRenderingPatch( true );

			pd4ml.render( new StringReader( htmlString ), bos );
		}
		catch (Exception e) {
			e.printStackTrace();
		}

		return new NSData( bos.toByteArray() );
	}

Cheers,
- Hugi


On 30.11.2005, at 21:20, Stefan Pantke wrote:

I need to compose PDF output based on certain input,

	- partly based on XML
		... and apply styles for PDF output
	- partly based on images and Text
		... and apply 'simple' composition rules for PDF output

I know of FOP, but just found iText

	http://www.lowagie.com/iText/

iText seems to be well documented and feature rich. At least for my
second task, this might be a good solution to further evaluate options.


My PDFs need to be high-resolution to be printed on high-resolution
imaging/printing machine.

But: Do we have a PDF lib, which especially integrates well with WO?


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.