Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] implementing iText in Magnolia

Sandor Rozsa

2005-09-27

Replies:

Hello iTexters,

first of all, let me thank you for developing this software.

I try to implement currently iText in Magnolia. Magnolia is a Java based
Open Source CMS system built on JCR. For more info: www.magnolia.info

My goal is to develop a dynamic print-page function based on the PDF file
format for the Open Source version of Magnolia.

What I envisioned was:

- in magnolia I can adjust the general page parameters like margins, used
fonts, header an footer image etc. on a per-page basis (so the editor can
actually choose how the particular page would look if it will be printed).

- I made a few test and put together a servlet based on your very
comprehensive tutorials. I am using the HTTP Servlet (from your tutorials)
to get the interesting parts of the particular page. For the prototype I'm
using a form with different textareas containing the particular data (like
margins, fonts etc.) and I'm submitting this to the servlet.

- Most of the things I would like to accomplish are working good or I see
clearly how a I can code them later.

But now I'm stucked on a few points. Maybe somebody of the more experienced
developers could give me some hints. I also have to say that I'm realy a
java/jsp nooby, so some snippets would be very usefull (sorry for my
ignorance, but I realy just started with programming - I'm actually only a
designer....)

Here are some of my problems/challenges:

Characters:
--------------------
I have problems with foreign characters like ü ö ä ß. How can I tell the
servlet to use foreign characters?

Header Image:
--------------------
I had some success in running your Image sample servlet. My problem is that
I have to deal with dynamically changing images. I have tried to do this by:

Declaring a string
   String headerImage = request.getParameter("headerImage");

(for "headerImage" I can get anything I would like from the CMS) ...

And after
 Document document = new Document();
...
 if (headerImage != null)
 {
   document.newPage();
 document.add(new Paragraph("This should be my Image"));
 Image jpg = Image.getInstance(headerImage);
 document.add(jpg);

 }

I do not getting any error, but no image will be put inside of my pdf.
Do you have any advise how I should handle this?

Content:

I decided to take over the content as a html-snippet (stream?). I'm not sure
if this is the best way, but the pages can contain anything from tables to
images to links. So I thought that this would be the simplest way. I know
that XML would be also an option, but for that I have to generate XML, store
it somewhere, transmit this to the servlet and afterwards delete the XML
file - sounds complicated for me - or did I missed something?

A typical html-snippet would look like this:

<h2>First paragraph wit a Link</h2>This is just to show how a link looks <a
target="_blank" href="http://localhost:8080/comform/createpdf">PDF<br />
</a> <div class="productBoxDownloadTitle"><br /> Magnolia Content
Management Suite is the leading open-source Enterprise Content Management
built on the revolutionary Java Content Repository Standard JSR-170</div>
Magnolia 2.1 speaks 15 major languages, including English, Chinese,
Japanese, Russian, French, German, Spanish and Portuguese. It contains
numerous new features: native search, XML-based import/export, a new
cross-browser rich-text editor and drop-in single container deployment
amongst others.<img alt="" class="left"
src="/comform/features/PDF-Test/mainColumnParagraphs/00/image/2.jpg"/><h2>Se
cond Paragraph with text and Image</h2><div
class="productBoxDownloadTitle">Magnolia Content Management Suite is the
leading open-source Enterprise Content Management built on the revolutionary
Java Content Repository Standard JSR-170</div> Magnolia 2.1 speaks 15 major
languages, including English, Chinese, Japanese, Russian, French, German,
Spanish and Portuguese. It contains numerous new features: native search,
XML-based import/export, a new cross-browser rich-text editor and drop-in
single container deployment amongst others.

Now her is the problem: I had even problems to get the "old" tutorial for
parsing HTML/XHTML documents up and running. Now I don't have a clue how I
would have to parse only some PARTS of a html page :-)

I've tried already with:

...
   String parserTest = request.getParameter("parserTest");
...

     if (parserTest != null)
     {
          PdfWriter.getInstance(document, response.getOutputStream());
         
         // step 3: we create a parser and set the document
handler
         SAXParser parser =
SAXParserFactory.newInstance().newSAXParser();
         
         // step 4: we parse the document
         parser.parse(parserTest, new
SAXmyHtmlHandler(document));
     }
....

But I seem to miss something... :-) Please remember: a nooby is trying to
code something :-)!

Is that actually possible? Or am I on the completely wrong way?

Any help is greatly appreciated. Thanks again and sorry for the ultral-long
posting...

Greetings from Cologne Germany,

Sandor Rozsa



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
©2008 junlu.com - Jax Systems, LLC, U.S.A.