2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with any library licensed under the Apache Software License,
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23 * (or with modified versions of the above that use the same license as the above),
24 * and distribute linked combinations including the two. You must obey the
25 * GNU General Public License in all respects for all of the code used other than
26 * the above mentioned libraries. If you modify this file, you may extend this
27 * exception to your version of the file, but you are not obligated to do so.
28 * If you do not wish to do so, delete this exception statement from your version.
30 package mircoders.pdf;
33 import gnu.regexp.REException;
34 import gnu.regexp.REMatch;
35 import gnu.regexp.REMatchEnumeration;
37 import java.io.ByteArrayOutputStream;
38 import java.io.IOException;
39 import java.net.MalformedURLException;
40 import java.util.Iterator;
41 import java.util.Vector;
43 import mir.config.MirPropertiesConfiguration;
44 import mir.entity.EntityBrowser;
45 import mir.log.LoggerWrapper;
46 import mir.misc.StringUtil;
47 import mir.util.DateTimeFunctions;
48 import mircoders.entity.EntityContent;
49 import mircoders.entity.EntityImages;
50 import mircoders.storage.DatabaseImages;
52 import com.lowagie.text.BadElementException;
53 import com.lowagie.text.Document;
54 import com.lowagie.text.DocumentException;
55 import com.lowagie.text.Element;
56 import com.lowagie.text.Font;
57 import com.lowagie.text.Image;
58 import com.lowagie.text.PageSize;
59 import com.lowagie.text.Paragraph;
60 import com.lowagie.text.Phrase;
61 import com.lowagie.text.pdf.BaseFont;
62 import com.lowagie.text.pdf.ColumnText;
63 import com.lowagie.text.pdf.PdfContentByte;
64 import com.lowagie.text.pdf.PdfTemplate;
65 import com.lowagie.text.pdf.PdfWriter;
67 public class PDFGenerator{
69 public Document document;
70 public PdfWriter writer;
71 public PdfContentByte cb;
72 public String localImageDir;
73 public float currentYPosition;
74 public int currentPage;
75 public float pageWidth;
76 public float pageHeight;
77 public float verticalMargin;
78 public float horizontalMargin;
80 public float bottomEdge;
81 public float rightEdge;
82 public float leftEdge;
84 public int maxImageHeight;
85 public int maxImageWidth;
86 protected LoggerWrapper logger;
88 public int indexFontSize;
89 public int indexLineHeight;
90 public int indexFontFamily;
92 public float footerHeight;
93 public String footerText;
94 public int footerFontSize;
95 public int footerFontFamily;
97 public int metaHeight;
98 public int metaFontSize;
99 public int metaFontFamily;
101 public int descriptionLineHeight;
102 public int descriptionFontSize;
103 public int descriptionFontFamily;
105 public int contentLineHeight;
106 public int contentFontSize;
107 public int contentFontFamily;
109 public int sourceLineHeight;
110 public int sourceFontSize;
111 public int sourceFontFamily;
113 public int bigImageCaptionFontSize;
114 public int bigImageCaptionFontFamily;
116 protected MirPropertiesConfiguration configuration;
119 public PDFGenerator(ByteArrayOutputStream out){
120 logger = new LoggerWrapper("PDFGenerator");
121 configuration = MirPropertiesConfiguration.instance();
122 localImageDir=configuration.getString("Producer.Image.Path");
125 indexFontSize = Integer.parseInt(configuration.getString("PDF.Index.FontSize"));
126 indexLineHeight = Integer.parseInt(configuration.getString("PDF.Index.LineHeight"));
127 indexFontFamily = getFontByName(configuration.getString("PDF.Index.FontFamily"));
129 footerText = configuration.getString("PDF.Footer.String");
130 footerFontSize = Integer.parseInt(configuration.getString("PDF.Footer.FontSize"));
131 footerFontFamily = getFontByName(configuration.getString("PDF.Footer.FontFamily"));
132 footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));;
134 metaFontSize = Integer.parseInt(configuration.getString("PDF.Meta.FontSize"));
135 metaFontFamily = getFontByName(configuration.getString("PDF.Meta.FontFamily"));
136 metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));;
138 descriptionFontSize = Integer.parseInt(configuration.getString("PDF.Description.FontSize"));
139 descriptionLineHeight = Integer.parseInt(configuration.getString("PDF.Description.LineHeight"));
140 descriptionFontFamily = getFontByName(configuration.getString("PDF.Description.FontFamily"));
142 contentFontSize = Integer.parseInt(configuration.getString("PDF.Content.FontSize"));
143 contentLineHeight = Integer.parseInt(configuration.getString("PDF.Content.LineHeight"));
144 contentFontFamily = getFontByName(configuration.getString("PDF.Content.FontFamily"));
146 sourceFontSize = Integer.parseInt(configuration.getString("PDF.Source.FontSize"));
147 sourceLineHeight = Integer.parseInt(configuration.getString("PDF.Source.LineHeight"));
148 sourceFontFamily = getFontByName(configuration.getString("PDF.Source.FontFamily"));
150 bigImageCaptionFontSize = Integer.parseInt(configuration.getString("PDF.BigImageCaption.FontSize"));
151 bigImageCaptionFontFamily = getFontByName(configuration.getString("PDF.BigImageCaption.FontFamily"));
154 catch (NumberFormatException e){
158 // step 1: make a document
160 String pageSize = configuration.getString("PDF.Pagesize");
162 if (pageSize.equals("LETTER")){
163 document = new Document(PageSize.LETTER);
168 document = new Document(PageSize.A4);
173 maxImageHeight = 250;
178 horizontalMargin = 20;
182 topEdge=pageHeight-verticalMargin;
183 bottomEdge=verticalMargin;
184 rightEdge=pageWidth-horizontalMargin;
185 leftEdge=horizontalMargin;
187 currentYPosition=topEdge;
190 String headerText = configuration.getString("PDF.Title.String");
193 writer = PdfWriter.getInstance(document, out);
194 cb = writer.getDirectContent();
197 addHeader(headerText);
199 catch(DocumentException de) {
200 logger.error(de.getMessage());
209 public void addHeader(String headerText){
210 int titleFontSize=Integer.parseInt(configuration.getString("PDF.Title.FontSize"));
211 int titleLineHeight=Integer.parseInt(configuration.getString("PDF.Title.LineHeight"));
212 String titleFontFamily=configuration.getString("PDF.Title.FontFamily");
213 String headerImage=configuration.getString("PDF.Header.Image");
214 int headerImageHeight = Integer.parseInt(configuration.getString("PDF.Header.ImageHeight"));
217 if ((! headerImage.equals("")) && headerImageHeight != 0){
218 PdfTemplate template = cb.createTemplate(rightEdge-horizontalMargin,headerImageHeight);
220 float toYPosition=currentYPosition - headerImageHeight;
221 Image theImage = Image.getInstance(headerImage);
222 theImage.setAbsolutePosition(0,0);
223 // theImage.scaleAbsolute(img_width,img_height);
224 template.addImage(theImage);
227 cb.addTemplate(template,leftEdge,toYPosition);
228 currentYPosition = toYPosition;
230 if (! headerText.equals("")){
231 ColumnText ct = new ColumnText(cb);
233 ct.addText(new Phrase(headerText, new Font(getFontByName(titleFontFamily), titleFontSize,Font.BOLD)));
234 float[] rightCol = {rightEdge,currentYPosition,rightEdge,currentYPosition-titleLineHeight};
235 float[] leftCol = {leftEdge,currentYPosition,leftEdge,currentYPosition-titleLineHeight};
236 ct.setColumns(leftCol,rightCol);
237 ct.setYLine(currentYPosition);
238 ct.setAlignment(Element.ALIGN_CENTER);
241 currentYPosition = currentYPosition - titleLineHeight;
244 catch(DocumentException de) {
245 logger.error(de.getMessage());
247 catch(MalformedURLException de) {
248 logger.error(de.getMessage());
250 catch(IOException de) {
251 logger.error(de.getMessage());
254 public void addIndexItem(EntityContent entityContent){
257 ColumnText ict = new ColumnText(cb);
258 String theTitle = entityContent.getFieldValue("title");
259 String theCreator = entityContent.getFieldValue("creator");
260 Phrase titleP=new Phrase(" - " + theTitle,new Font(indexFontFamily,indexFontSize,Font.BOLD));
261 Phrase creatorP=new Phrase( " :: " + theCreator,new Font(indexFontFamily,indexFontSize));
262 float toYPosition = currentYPosition - indexLineHeight;
263 float[] leftIndexCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
264 float[] rightIndexCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
266 ict.addText(creatorP);
267 ict.setColumns(leftIndexCols,rightIndexCols);
268 ict.setYLine(currentYPosition);
269 ict.setAlignment(Element.ALIGN_LEFT);
271 currentYPosition = toYPosition;
273 catch(DocumentException de) {
274 logger.error(de.getMessage());
281 private int addTextLine(ColumnText ct,int lineHeight,int alignment,float left, float right){
282 logger.debug("adding a line of text");
283 if (! enoughY(lineHeight)){
286 float toYPosition = currentYPosition - lineHeight;
287 float[] leftContentCols = {left,currentYPosition,left,toYPosition};
288 float[] rightContentCols = {right,currentYPosition,right,toYPosition};
289 ct.setColumns(leftContentCols,rightContentCols);
290 ct.setYLine(currentYPosition);
291 ct.setAlignment(alignment);
294 currentYPosition = toYPosition;
297 catch(DocumentException de) {
298 logger.error(de.getMessage());
303 public void addLine(){
305 cb.moveTo(rightEdge, currentYPosition-5);
306 cb.lineTo(leftEdge, currentYPosition-5);
308 currentYPosition = currentYPosition - 10;
312 public void addFooter(){
314 ColumnText fct = new ColumnText(cb);
316 cb.moveTo(rightEdge, bottomEdge+footerHeight-5);
317 cb.lineTo(leftEdge, bottomEdge+footerHeight-5);
319 float[] leftFooterCols = {leftEdge,bottomEdge+footerHeight-1,leftEdge,bottomEdge};
320 float[] rightFooterCols = {rightEdge,bottomEdge+footerHeight-1,rightEdge,bottomEdge};
322 Paragraph footerP=new Paragraph(footerText,new Font(footerFontFamily,footerFontSize));
323 fct.addText(footerP);
325 fct.setColumns(leftFooterCols,rightFooterCols);
326 fct.setYLine(bottomEdge+footerHeight-1);
327 fct.setAlignment(Element.ALIGN_JUSTIFIED);
330 Paragraph numberP=new Paragraph((new Integer(currentPage)).toString(),new Font(footerFontFamily,footerFontSize,Font.BOLD));
331 fct.addText(numberP);
332 fct.setAlignment(Element.ALIGN_RIGHT);
336 catch (DocumentException de){
337 logger.error(de.getMessage());
343 public void newPage(){
349 currentYPosition=topEdge;
351 catch(DocumentException de) {
352 logger.error(de.getMessage());
356 public void addArticleSeparator(){
362 cb.moveTo(rightEdge, currentYPosition-5);
363 cb.lineTo(leftEdge, currentYPosition-5);
365 currentYPosition = currentYPosition - 10;
368 public void addArticleMetaInfo(ColumnText ct,String theTitle,String theCreator,String theDate){
369 //see if we have room for the author and title
371 if (! enoughY(metaHeight)){
375 Paragraph titleP=new Paragraph(theTitle+"\n",new Font(metaFontFamily,metaFontSize,Font.BOLD));
376 Paragraph whowhenP=new Paragraph(theCreator + " " + theDate ,new Font(metaFontFamily,metaFontSize));
378 ct.addText(whowhenP);
380 ct.setYLine(currentYPosition);
381 ct.setAlignment(Element.ALIGN_LEFT);
383 float toYPosition = currentYPosition - metaHeight;
384 float[] leftHeadCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
385 float[] rightHeadCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
387 ct.setColumns(leftHeadCols,rightHeadCols);
390 currentYPosition = toYPosition;
392 catch(DocumentException de) {
393 logger.error(de.getMessage());
398 public void addArticleDescription(ColumnText ct,String theDescription){
399 // Now we add the description, one line at a time, the ct should be empty at this point
402 Paragraph descP=new Paragraph(theDescription,new Font(descriptionFontFamily,descriptionFontSize,Font.BOLD));
405 // every article has a description, so we can assume that:
406 int status = ColumnText.NO_MORE_COLUMN;
409 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake >0){
410 //there is still text left in the description.
411 status = addTextLine(ct,descriptionLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
415 logger.error("runaway description...try increasing the line height or decreasing the font size");
418 public void addArticleContent(ColumnText ct,String theContent,Iterator images){
419 //let's go ahead and add in all the body text
420 Paragraph contentP=new Paragraph(theContent,new Font(contentFontFamily,contentFontSize));
421 ct.addText(contentP);
423 int contentLinesBeforeImages=3;
424 //and assume we have at least one line of text in the content
425 int status = ColumnText.NO_MORE_COLUMN;
427 // let's add a little bit of text, like a couple of lines
429 while (((status & ColumnText.NO_MORE_TEXT) == 0) && x<contentLinesBeforeImages){
430 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
434 boolean addImageOnLeft = true; //we will alternate within articles
435 while (images.hasNext()){
437 EntityImages currentImage=(EntityImages) images.next();
438 float img_width=(new Float(currentImage.getFieldValue("img_width"))).floatValue();
439 float img_height=(new Float(currentImage.getFieldValue("img_height"))).floatValue();
440 if (img_height>maxImageHeight){
441 img_width=(new Float((new Float(img_width*(maxImageHeight/img_height))).intValue())).floatValue();
442 img_height=maxImageHeight;
444 if (img_width>maxImageWidth){
445 img_height=(new Float((new Float(img_height*(maxImageWidth/img_width))).intValue())).floatValue();
446 img_width=maxImageWidth;
449 String img_title=currentImage.getFieldValue("title");
450 String img_path=currentImage.getFieldValue("publish_path");
452 if ((status & ColumnText.NO_MORE_TEXT) == 0){
453 // there is still text, so add an image which will have text wrapped around it, then add the text which
454 // will be on the left or the right of the image
456 float templateMinimumHeight = img_height+20;
457 float templateWidth = img_width+10;
458 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
460 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
463 //here we need a page check
464 if (! enoughY((new Float(templateHeight)).intValue())){
465 //ok, well just fill text to the bottom then
466 float toYPosition = bottomEdge+footerHeight;
467 float[] leftBottomCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
468 float[] rightBottomCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
469 ct.setColumns(leftBottomCols,rightBottomCols);
470 ct.setYLine(currentYPosition);
471 ct.setAlignment(Element.ALIGN_JUSTIFIED);
475 catch(DocumentException de) {
476 logger.error(de.getMessage());
481 float toYPosition=currentYPosition - templateHeight;
484 Image theImage = Image.getInstance(localImageDir+img_path);
485 theImage.scaleAbsolute(img_width,img_height);
486 theImage.setAbsolutePosition(5,13);
488 template.addImage(theImage);
489 template.beginText();
490 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
491 template.setFontAndSize(bf, 8);
492 template.setTextMatrix(5, 3);
493 template.showText(img_title);
496 catch(BadElementException de) {
497 logger.error(de.getMessage());
499 catch(DocumentException de) {
500 logger.error(de.getMessage());
502 catch (MalformedURLException de){
503 logger.error(de.getMessage());
505 catch (IOException de){
506 logger.error(de.getMessage());
510 float leftImageTextEdge=leftEdge;
511 float rightImageTextEdge=rightEdge;
515 cb.addTemplate(template,leftEdge,toYPosition);
516 leftImageTextEdge=leftEdge+templateWidth+5;
517 addImageOnLeft = false;
520 cb.addTemplate(template,rightEdge-templateWidth,toYPosition);
521 rightImageTextEdge = rightEdge-templateWidth-5;
522 addImageOnLeft = true;
525 logger.debug("adding template at " + leftEdge + "," + toYPosition);
527 //and fill some text while we are at it
529 float[] leftBottomCols = {leftImageTextEdge,currentYPosition,leftImageTextEdge,toYPosition};
530 float[] rightBottomCols = {rightImageTextEdge,currentYPosition,rightImageTextEdge,toYPosition};
531 ct.setColumns(leftBottomCols,rightBottomCols);
532 ct.setYLine(currentYPosition);
533 ct.setAlignment(Element.ALIGN_JUSTIFIED);
536 currentYPosition=toYPosition;
538 catch(DocumentException de) {
539 logger.error(de.getMessage());
545 //add an image on the left with a big caption to the right
546 currentYPosition = currentYPosition - 10;
547 float templateMinimumHeight = img_height;
548 float templateWidth = img_width;
549 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
550 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
551 if (! enoughY((new Float(templateHeight)).intValue())){
554 float toYPosition=currentYPosition - templateHeight;
556 Image theImage = Image.getInstance(localImageDir+img_path);
557 theImage.setAbsolutePosition(0,13);
558 theImage.scaleAbsolute(img_width,img_height);
559 template.addImage(theImage);
561 catch(BadElementException de) {
562 logger.error(de.getMessage());
564 catch(DocumentException de) {
565 logger.error(de.getMessage());
567 catch(MalformedURLException de) {
568 logger.error(de.getMessage());
570 catch(IOException de) {
571 logger.error(de.getMessage());
574 cb.addTemplate(template,leftEdge,toYPosition);
577 ColumnText cct = new ColumnText(cb);
578 float[] leftCaptionCols = {leftEdge+templateWidth+5,currentYPosition-5,leftEdge+templateWidth+5,toYPosition};
579 float[] rightCaptionCols = {rightEdge,currentYPosition-5,rightEdge,toYPosition};
581 Paragraph captionP=new Paragraph(img_title,new Font(bigImageCaptionFontFamily,bigImageCaptionFontSize,Font.BOLD));
582 cct.addText(captionP);
583 cct.setColumns(leftCaptionCols,rightCaptionCols);
584 cct.setYLine(currentYPosition-5);
585 cct.setAlignment(Element.ALIGN_LEFT);
588 currentYPosition=toYPosition;
590 catch(DocumentException de) {
591 logger.error(de.getMessage());
596 //add the rest of the text which might be left
598 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake > 0){
599 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
603 logger.error("runaway content....try decreasing font size or increasing line height");
606 private void addArticleSource(ColumnText ct,String theSource){
607 Paragraph sourceP = new Paragraph(theSource,new Font(sourceFontFamily,sourceFontSize,Font.BOLD));
609 addTextLine(ct,sourceLineHeight,Element.ALIGN_RIGHT,leftEdge,rightEdge);
613 private boolean enoughY(int heightOfBlockToAdd){
614 if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
621 public void add(EntityContent entityContent){
622 logger.error("adding a content Entity");
632 * --image without text
636 Vector extraTables = new Vector();
637 extraTables.add("content_x_media cxm");
638 Iterator images = new EntityBrowser(
639 DatabaseImages.getInstance(), "i", extraTables,
640 "cxm.content_id="+entityContent.getId()+"and cxm.media_id=i.id",
641 "i.id desc", 30, -1, 0);
643 String isHTML = entityContent.getFieldValue("is_html");
644 String theTitle = entityContent.getFieldValue("title");
645 String theCreator = entityContent.getFieldValue("creator");
646 String theDate = DateTimeFunctions.advancedDateFormat(
647 configuration.getString("RDF.Meta.DateFormat"),
648 StringUtil.convertMirInternalDateToDate(entityContent.getFieldValue("webdb_create")),
649 configuration.getString("Mir.DefaultTimezone"));
652 String theDescriptionRaw = entityContent.getFieldValue("description");
653 String theContentRaw = entityContent.getFieldValue("content_data");
654 String theSource = configuration.getString("Producer.PublicationHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getFieldValue("publish_path") + entityContent.getFieldValue("id") + ".shtml";
658 String theContent = "";
659 String theDescription = "";
661 if (isHTML.equals("1")){
666 RE nobackslashr = new RE("\r");
667 theContent= nobackslashr.substituteAll(theContentRaw,"");
668 theDescription= nobackslashr.substituteAll(theDescriptionRaw,"");
670 RE HxTag = new RE("</?h[1-6][^>]*>",RE.REG_ICASE);
671 theContent = HxTag.substituteAll(theContent,"\n\n");
672 theDescription = HxTag.substituteAll(theDescription,"\n\n");
674 RE ListItemTag = new RE("<li[^>]*>",RE.REG_ICASE);
675 theContent = ListItemTag.substituteAll(theContent,"\n * ");
676 theDescription = ListItemTag.substituteAll(theDescription,"\n * ");
678 RE ListTag = new RE("<(u|o)l[^>]*>",RE.REG_ICASE);
679 theContent = ListTag.substituteAll(theContent,"\n");
680 theDescription = ListTag.substituteAll(theDescription,"\n");
682 RE DivTag = new RE("</?div[^>]*>",RE.REG_ICASE);
683 theContent= DivTag.substituteAll(theContent,"\n");
684 theDescription= DivTag.substituteAll(theDescription,"\n");
686 RE PTag = new RE("<(p|P)([:space:]+[^>]*)?>");
687 theContent= PTag.substituteAll(theContent,"\n ");
688 theDescription= PTag.substituteAll(theDescription,"\n ");
690 RE PTagClose = new RE("</(p|P)([:space:]+[^>]*)?>");
691 theContent= PTagClose.substituteAll(theContent,"\n");
692 theDescription= PTagClose.substituteAll(theDescription,"\n");
694 RE BRTag = new RE("<(br|BR)([:space:]+[^>]*)?>");
695 theContent= BRTag.substituteAll(theContent,"\n");
696 theDescription= BRTag.substituteAll(theDescription,"\n");
698 RE ATagAll = new RE("<a[^>]*href=(?:\"|\')([^#\"\'][^\'\"]+)(?:\"|\')[^>]*>(.*?)</a>",RE.REG_ICASE);
699 REMatchEnumeration atags= ATagAll.getMatchEnumeration(theContent);
700 String theContentCopy=theContent;
701 while (atags.hasMoreMatches()){
702 REMatch atag = atags.nextMatch();
703 String atagString=atag.toString();
704 String atagStringHref=atag.toString(1);
705 String atagStringText=atag.toString(2);
706 int begin=theContentCopy.indexOf(atagString);
707 theContentCopy=theContentCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theContentCopy.substring(begin+atagString.length());
709 theContent=theContentCopy;
711 REMatchEnumeration atags2= ATagAll.getMatchEnumeration(theDescription);
712 String theDescriptionCopy=theDescription;
713 while (atags2.hasMoreMatches()){
714 REMatch atag = atags2.nextMatch();
715 String atagString=atag.toString();
716 String atagStringHref=atag.toString(1);
717 String atagStringText=atag.toString(2);
718 int begin=theDescriptionCopy.indexOf(atagString);
719 theDescriptionCopy=theDescriptionCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theDescriptionCopy.substring(begin+atagString.length());
721 theDescription=theDescriptionCopy;
724 RE noTags = new RE("<[^>]*>");
725 theContent= noTags.substituteAll(theContent," ");
726 theDescription= noTags.substituteAll(theDescription," ");
728 theContent=mir.util.Translate.decode(theContent);
729 theDescription=mir.util.Translate.decode(theDescription);
731 RE re1 = new RE("\r?\n\r?\n");
732 String theDescription1 = re1.substituteAll(theDescription,"BREAKHERE");
734 RE re2 = new RE("\r?\n");
735 String theDescription2 = re2.substituteAll(theDescription1," ");
737 RE re3 = new RE("BREAKHERE");
738 theDescription = re3.substituteAll(theDescription2,"\n ");
742 catch(REException ree){
743 logger.error(ree.getMessage());
748 RE re1 = new RE("\r?\n\r?\n");
749 String theContent1 = re1.substituteAll(theContentRaw,"BREAKHERE");
750 String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
752 RE re2 = new RE("\r?\n");
753 String theContent2 = re2.substituteAll(theContent1," ");
754 String theDescription2 = re2.substituteAll(theDescription1," ");
756 RE re3 = new RE("BREAKHERE");
757 theContent = " " + re3.substituteAll(theContent2,"\n ");
758 theDescription = re3.substituteAll(theDescription2,"\n ");
761 catch(REException ree){
762 logger.error(ree.getMessage());
766 addArticleSeparator();
768 ColumnText ct = new ColumnText(cb);
770 addArticleMetaInfo(ct,theTitle,theCreator,theDate);
771 addArticleDescription(ct,theDescription);
772 addArticleContent(ct,theContent,images);
773 addArticleSource(ct,theSource);
777 public int getFontByName(String fontName) {
779 if (fontName.equalsIgnoreCase("helvetica")){
780 theFont = Font.HELVETICA;
783 if (fontName.equalsIgnoreCase("courier")) {
784 theFont = Font.COURIER;
787 if (fontName.equalsIgnoreCase("times")) {
788 theFont = Font.TIMES_ROMAN;
791 logger.error("using helvetica because I can't get font for name: "+fontName);
792 theFont = Font.HELVETICA;