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;
32 import com.lowagie.text.*;
33 import com.lowagie.text.pdf.*;
35 import gnu.regexp.REException;
36 import gnu.regexp.REMatch;
37 import gnu.regexp.REMatchEnumeration;
38 import mir.config.MirPropertiesConfiguration;
39 import mir.entity.EntityBrowser;
40 import mir.log.LoggerWrapper;
41 import mir.misc.StringUtil;
42 import mir.util.DateTimeFunctions;
43 import mircoders.entity.EntityContent;
44 import mircoders.entity.EntityImages;
45 import mircoders.storage.DatabaseImages;
47 import java.io.ByteArrayOutputStream;
48 import java.io.IOException;
49 import java.net.MalformedURLException;
50 import java.util.ArrayList;
51 import java.util.Iterator;
52 import java.util.List;
54 public class PDFGenerator{
56 public Document document;
57 public PdfWriter writer;
58 public PdfContentByte cb;
59 public String localImageDir;
60 public float currentYPosition;
61 public int currentPage;
62 public float pageWidth;
63 public float pageHeight;
64 public float verticalMargin;
65 public float horizontalMargin;
67 public float bottomEdge;
68 public float rightEdge;
69 public float leftEdge;
71 public int maxImageHeight;
72 public int maxImageWidth;
73 protected LoggerWrapper logger;
75 public int indexFontSize;
76 public int indexLineHeight;
77 public int indexFontFamily;
79 public float footerHeight;
80 public String footerText;
81 public int footerFontSize;
82 public int footerFontFamily;
84 public int metaHeight;
85 public int metaFontSize;
86 public int metaFontFamily;
88 public int descriptionLineHeight;
89 public int descriptionFontSize;
90 public int descriptionFontFamily;
92 public int contentLineHeight;
93 public int contentFontSize;
94 public int contentFontFamily;
96 public int sourceLineHeight;
97 public int sourceFontSize;
98 public int sourceFontFamily;
100 public int bigImageCaptionFontSize;
101 public int bigImageCaptionFontFamily;
103 protected MirPropertiesConfiguration configuration;
106 public PDFGenerator(ByteArrayOutputStream out){
107 logger = new LoggerWrapper("PDFGenerator");
108 configuration = MirPropertiesConfiguration.instance();
109 localImageDir=configuration.getString("Producer.Image.Path");
112 indexFontSize = Integer.parseInt(configuration.getString("PDF.Index.FontSize"));
113 indexLineHeight = Integer.parseInt(configuration.getString("PDF.Index.LineHeight"));
114 indexFontFamily = getFontByName(configuration.getString("PDF.Index.FontFamily"));
116 footerText = configuration.getString("PDF.Footer.String");
117 footerFontSize = Integer.parseInt(configuration.getString("PDF.Footer.FontSize"));
118 footerFontFamily = getFontByName(configuration.getString("PDF.Footer.FontFamily"));
119 footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));;
121 metaFontSize = Integer.parseInt(configuration.getString("PDF.Meta.FontSize"));
122 metaFontFamily = getFontByName(configuration.getString("PDF.Meta.FontFamily"));
123 metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));;
125 descriptionFontSize = Integer.parseInt(configuration.getString("PDF.Description.FontSize"));
126 descriptionLineHeight = Integer.parseInt(configuration.getString("PDF.Description.LineHeight"));
127 descriptionFontFamily = getFontByName(configuration.getString("PDF.Description.FontFamily"));
129 contentFontSize = Integer.parseInt(configuration.getString("PDF.Content.FontSize"));
130 contentLineHeight = Integer.parseInt(configuration.getString("PDF.Content.LineHeight"));
131 contentFontFamily = getFontByName(configuration.getString("PDF.Content.FontFamily"));
133 sourceFontSize = Integer.parseInt(configuration.getString("PDF.Source.FontSize"));
134 sourceLineHeight = Integer.parseInt(configuration.getString("PDF.Source.LineHeight"));
135 sourceFontFamily = getFontByName(configuration.getString("PDF.Source.FontFamily"));
137 bigImageCaptionFontSize = Integer.parseInt(configuration.getString("PDF.BigImageCaption.FontSize"));
138 bigImageCaptionFontFamily = getFontByName(configuration.getString("PDF.BigImageCaption.FontFamily"));
141 catch (NumberFormatException e){
145 // step 1: make a document
147 String pageSize = configuration.getString("PDF.Pagesize");
149 if (pageSize.equals("LETTER")){
150 document = new Document(PageSize.LETTER);
155 document = new Document(PageSize.A4);
160 maxImageHeight = 250;
165 horizontalMargin = 20;
169 topEdge=pageHeight-verticalMargin;
170 bottomEdge=verticalMargin;
171 rightEdge=pageWidth-horizontalMargin;
172 leftEdge=horizontalMargin;
174 currentYPosition=topEdge;
177 String headerText = configuration.getString("PDF.Title.String");
180 writer = PdfWriter.getInstance(document, out);
181 cb = writer.getDirectContent();
184 addHeader(headerText);
186 catch(DocumentException de) {
187 logger.error(de.getMessage());
196 public void addHeader(String headerText){
197 int titleFontSize=Integer.parseInt(configuration.getString("PDF.Title.FontSize"));
198 int titleLineHeight=Integer.parseInt(configuration.getString("PDF.Title.LineHeight"));
199 String titleFontFamily=configuration.getString("PDF.Title.FontFamily");
200 String headerImage=configuration.getString("PDF.Header.Image");
201 int headerImageHeight = Integer.parseInt(configuration.getString("PDF.Header.ImageHeight"));
204 if ((! headerImage.equals("")) && headerImageHeight != 0){
205 PdfTemplate template = cb.createTemplate(rightEdge-horizontalMargin,headerImageHeight);
207 float toYPosition=currentYPosition - headerImageHeight;
208 Image theImage = Image.getInstance(headerImage);
209 theImage.setAbsolutePosition(0,0);
210 // theImage.scaleAbsolute(img_width,img_height);
211 template.addImage(theImage);
214 cb.addTemplate(template,leftEdge,toYPosition);
215 currentYPosition = toYPosition;
217 if (! headerText.equals("")){
218 ColumnText ct = new ColumnText(cb);
220 ct.addText(new Phrase(headerText, new Font(getFontByName(titleFontFamily), titleFontSize,Font.BOLD)));
221 float[] rightCol = {rightEdge,currentYPosition,rightEdge,currentYPosition-titleLineHeight};
222 float[] leftCol = {leftEdge,currentYPosition,leftEdge,currentYPosition-titleLineHeight};
223 ct.setColumns(leftCol,rightCol);
224 ct.setYLine(currentYPosition);
225 ct.setAlignment(Element.ALIGN_CENTER);
228 currentYPosition = currentYPosition - titleLineHeight;
231 catch(DocumentException de) {
232 logger.error(de.getMessage());
234 catch(MalformedURLException de) {
235 logger.error(de.getMessage());
237 catch(IOException de) {
238 logger.error(de.getMessage());
241 public void addIndexItem(EntityContent entityContent){
244 ColumnText ict = new ColumnText(cb);
245 String theTitle = entityContent.getFieldValue("title");
246 String theCreator = entityContent.getFieldValue("creator");
247 Phrase titleP=new Phrase(" - " + theTitle,new Font(indexFontFamily,indexFontSize,Font.BOLD));
248 Phrase creatorP=new Phrase( " :: " + theCreator,new Font(indexFontFamily,indexFontSize));
249 float toYPosition = currentYPosition - indexLineHeight;
250 float[] leftIndexCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
251 float[] rightIndexCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
253 ict.addText(creatorP);
254 ict.setColumns(leftIndexCols,rightIndexCols);
255 ict.setYLine(currentYPosition);
256 ict.setAlignment(Element.ALIGN_LEFT);
258 currentYPosition = toYPosition;
260 catch(DocumentException de) {
261 logger.error(de.getMessage());
268 private int addTextLine(ColumnText ct,int lineHeight,int alignment,float left, float right){
269 logger.debug("adding a line of text");
270 if (! enoughY(lineHeight)){
273 float toYPosition = currentYPosition - lineHeight;
274 float[] leftContentCols = {left,currentYPosition,left,toYPosition};
275 float[] rightContentCols = {right,currentYPosition,right,toYPosition};
276 ct.setColumns(leftContentCols,rightContentCols);
277 ct.setYLine(currentYPosition);
278 ct.setAlignment(alignment);
281 currentYPosition = toYPosition;
284 catch(DocumentException de) {
285 logger.error(de.getMessage());
290 public void addLine(){
292 cb.moveTo(rightEdge, currentYPosition-5);
293 cb.lineTo(leftEdge, currentYPosition-5);
295 currentYPosition = currentYPosition - 10;
299 public void addFooter(){
301 ColumnText fct = new ColumnText(cb);
303 cb.moveTo(rightEdge, bottomEdge+footerHeight-5);
304 cb.lineTo(leftEdge, bottomEdge+footerHeight-5);
306 float[] leftFooterCols = {leftEdge,bottomEdge+footerHeight-1,leftEdge,bottomEdge};
307 float[] rightFooterCols = {rightEdge,bottomEdge+footerHeight-1,rightEdge,bottomEdge};
309 Paragraph footerP=new Paragraph(footerText,new Font(footerFontFamily,footerFontSize));
310 fct.addText(footerP);
312 fct.setColumns(leftFooterCols,rightFooterCols);
313 fct.setYLine(bottomEdge+footerHeight-1);
314 fct.setAlignment(Element.ALIGN_JUSTIFIED);
317 Paragraph numberP=new Paragraph((new Integer(currentPage)).toString(),new Font(footerFontFamily,footerFontSize,Font.BOLD));
318 fct.addText(numberP);
319 fct.setAlignment(Element.ALIGN_RIGHT);
323 catch (DocumentException de){
324 logger.error(de.getMessage());
330 public void newPage(){
336 currentYPosition=topEdge;
338 catch(DocumentException de) {
339 logger.error(de.getMessage());
343 public void addArticleSeparator(){
349 cb.moveTo(rightEdge, currentYPosition-5);
350 cb.lineTo(leftEdge, currentYPosition-5);
352 currentYPosition = currentYPosition - 10;
355 public void addArticleMetaInfo(ColumnText ct,String theTitle,String theCreator,String theDate){
356 //see if we have room for the author and title
358 if (! enoughY(metaHeight)){
362 Paragraph titleP=new Paragraph(theTitle+"\n",new Font(metaFontFamily,metaFontSize,Font.BOLD));
363 Paragraph whowhenP=new Paragraph(theCreator + " " + theDate ,new Font(metaFontFamily,metaFontSize));
365 ct.addText(whowhenP);
367 ct.setYLine(currentYPosition);
368 ct.setAlignment(Element.ALIGN_LEFT);
370 float toYPosition = currentYPosition - metaHeight;
371 float[] leftHeadCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
372 float[] rightHeadCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
374 ct.setColumns(leftHeadCols,rightHeadCols);
377 currentYPosition = toYPosition;
379 catch(DocumentException de) {
380 logger.error(de.getMessage());
385 public void addArticleDescription(ColumnText ct,String theDescription){
386 // Now we add the description, one line at a time, the ct should be empty at this point
389 Paragraph descP=new Paragraph(theDescription,new Font(descriptionFontFamily,descriptionFontSize,Font.BOLD));
392 // every article has a description, so we can assume that:
393 int status = ColumnText.NO_MORE_COLUMN;
396 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake >0){
397 //there is still text left in the description.
398 status = addTextLine(ct,descriptionLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
402 logger.error("runaway description...try increasing the line height or decreasing the font size");
405 public void addArticleContent(ColumnText ct,String theContent,Iterator images){
406 //let's go ahead and add in all the body text
407 Paragraph contentP=new Paragraph(theContent,new Font(contentFontFamily,contentFontSize));
408 ct.addText(contentP);
410 int contentLinesBeforeImages=3;
411 //and assume we have at least one line of text in the content
412 int status = ColumnText.NO_MORE_COLUMN;
414 // let's add a little bit of text, like a couple of lines
416 while (((status & ColumnText.NO_MORE_TEXT) == 0) && x<contentLinesBeforeImages){
417 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
421 boolean addImageOnLeft = true; //we will alternate within articles
422 while (images.hasNext()){
424 EntityImages currentImage=(EntityImages) images.next();
425 float img_width=(new Float(currentImage.getFieldValue("img_width"))).floatValue();
426 float img_height=(new Float(currentImage.getFieldValue("img_height"))).floatValue();
427 if (img_height>maxImageHeight){
428 img_width=(new Float((new Float(img_width*(maxImageHeight/img_height))).intValue())).floatValue();
429 img_height=maxImageHeight;
431 if (img_width>maxImageWidth){
432 img_height=(new Float((new Float(img_height*(maxImageWidth/img_width))).intValue())).floatValue();
433 img_width=maxImageWidth;
436 String img_title=currentImage.getFieldValue("title");
437 String img_path=currentImage.getFieldValue("publish_path");
439 if ((status & ColumnText.NO_MORE_TEXT) == 0){
440 // there is still text, so add an image which will have text wrapped around it, then add the text which
441 // will be on the left or the right of the image
443 float templateMinimumHeight = img_height+20;
444 float templateWidth = img_width+10;
445 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
447 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
450 //here we need a page check
451 if (! enoughY((new Float(templateHeight)).intValue())){
452 //ok, well just fill text to the bottom then
453 float toYPosition = bottomEdge+footerHeight;
454 float[] leftBottomCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
455 float[] rightBottomCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
456 ct.setColumns(leftBottomCols,rightBottomCols);
457 ct.setYLine(currentYPosition);
458 ct.setAlignment(Element.ALIGN_JUSTIFIED);
462 catch(DocumentException de) {
463 logger.error(de.getMessage());
468 float toYPosition=currentYPosition - templateHeight;
471 Image theImage = Image.getInstance(localImageDir+img_path);
472 theImage.scaleAbsolute(img_width,img_height);
473 theImage.setAbsolutePosition(5,13);
475 template.addImage(theImage);
476 template.beginText();
477 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
478 template.setFontAndSize(bf, 8);
479 template.setTextMatrix(5, 3);
480 template.showText(img_title);
483 catch(BadElementException de) {
484 logger.error(de.getMessage());
486 catch(DocumentException de) {
487 logger.error(de.getMessage());
489 catch (MalformedURLException de){
490 logger.error(de.getMessage());
492 catch (IOException de){
493 logger.error(de.getMessage());
497 float leftImageTextEdge=leftEdge;
498 float rightImageTextEdge=rightEdge;
502 cb.addTemplate(template,leftEdge,toYPosition);
503 leftImageTextEdge=leftEdge+templateWidth+5;
504 addImageOnLeft = false;
507 cb.addTemplate(template,rightEdge-templateWidth,toYPosition);
508 rightImageTextEdge = rightEdge-templateWidth-5;
509 addImageOnLeft = true;
512 logger.debug("adding template at " + leftEdge + "," + toYPosition);
514 //and fill some text while we are at it
516 float[] leftBottomCols = {leftImageTextEdge,currentYPosition,leftImageTextEdge,toYPosition};
517 float[] rightBottomCols = {rightImageTextEdge,currentYPosition,rightImageTextEdge,toYPosition};
518 ct.setColumns(leftBottomCols,rightBottomCols);
519 ct.setYLine(currentYPosition);
520 ct.setAlignment(Element.ALIGN_JUSTIFIED);
523 currentYPosition=toYPosition;
525 catch(DocumentException de) {
526 logger.error(de.getMessage());
532 //add an image on the left with a big caption to the right
533 currentYPosition = currentYPosition - 10;
534 float templateMinimumHeight = img_height;
535 float templateWidth = img_width;
536 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
537 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
538 if (! enoughY((new Float(templateHeight)).intValue())){
541 float toYPosition=currentYPosition - templateHeight;
543 Image theImage = Image.getInstance(localImageDir+img_path);
544 theImage.setAbsolutePosition(0,13);
545 theImage.scaleAbsolute(img_width,img_height);
546 template.addImage(theImage);
548 catch(BadElementException de) {
549 logger.error(de.getMessage());
551 catch(DocumentException de) {
552 logger.error(de.getMessage());
554 catch(MalformedURLException de) {
555 logger.error(de.getMessage());
557 catch(IOException de) {
558 logger.error(de.getMessage());
561 cb.addTemplate(template,leftEdge,toYPosition);
564 ColumnText cct = new ColumnText(cb);
565 float[] leftCaptionCols = {leftEdge+templateWidth+5,currentYPosition-5,leftEdge+templateWidth+5,toYPosition};
566 float[] rightCaptionCols = {rightEdge,currentYPosition-5,rightEdge,toYPosition};
568 Paragraph captionP=new Paragraph(img_title,new Font(bigImageCaptionFontFamily,bigImageCaptionFontSize,Font.BOLD));
569 cct.addText(captionP);
570 cct.setColumns(leftCaptionCols,rightCaptionCols);
571 cct.setYLine(currentYPosition-5);
572 cct.setAlignment(Element.ALIGN_LEFT);
575 currentYPosition=toYPosition;
577 catch(DocumentException de) {
578 logger.error(de.getMessage());
583 //add the rest of the text which might be left
585 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake > 0){
586 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
590 logger.error("runaway content....try decreasing font size or increasing line height");
593 private void addArticleSource(ColumnText ct,String theSource){
594 Paragraph sourceP = new Paragraph(theSource,new Font(sourceFontFamily,sourceFontSize,Font.BOLD));
596 addTextLine(ct,sourceLineHeight,Element.ALIGN_RIGHT,leftEdge,rightEdge);
600 private boolean enoughY(int heightOfBlockToAdd){
601 if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
608 public void add(EntityContent entityContent){
609 logger.error("adding a content Entity");
619 * --image without text
623 List extraTables = new ArrayList();
624 extraTables.add("content_x_media cxm");
625 Iterator images = new EntityBrowser(
626 DatabaseImages.getInstance(), "i", extraTables,
627 "cxm.content_id="+entityContent.getId()+"and cxm.media_id=i.id",
628 "i.id desc", 30, -1, 0);
630 String isHTML = entityContent.getFieldValue("is_html");
631 String theTitle = entityContent.getFieldValue("title");
632 String theCreator = entityContent.getFieldValue("creator");
633 String theDate = DateTimeFunctions.advancedDateFormat(
634 configuration.getString("RDF.Meta.DateFormat"),
635 StringUtil.convertMirInternalDateToDate(entityContent.getFieldValue("webdb_create")),
636 configuration.getString("Mir.DefaultTimezone"));
639 String theDescriptionRaw = entityContent.getFieldValue("description");
640 String theContentRaw = entityContent.getFieldValue("content_data");
641 String theSource = configuration.getString("Producer.PublicationHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getFieldValue("publish_path") + entityContent.getFieldValue("id") + ".shtml";
645 String theContent = "";
646 String theDescription = "";
648 if (isHTML.equals("1")){
653 RE nobackslashr = new RE("\r");
654 theContent= nobackslashr.substituteAll(theContentRaw,"");
655 theDescription= nobackslashr.substituteAll(theDescriptionRaw,"");
657 RE HxTag = new RE("</?h[1-6][^>]*>",RE.REG_ICASE);
658 theContent = HxTag.substituteAll(theContent,"\n\n");
659 theDescription = HxTag.substituteAll(theDescription,"\n\n");
661 RE ListItemTag = new RE("<li[^>]*>",RE.REG_ICASE);
662 theContent = ListItemTag.substituteAll(theContent,"\n * ");
663 theDescription = ListItemTag.substituteAll(theDescription,"\n * ");
665 RE ListTag = new RE("<(u|o)l[^>]*>",RE.REG_ICASE);
666 theContent = ListTag.substituteAll(theContent,"\n");
667 theDescription = ListTag.substituteAll(theDescription,"\n");
669 RE DivTag = new RE("</?div[^>]*>",RE.REG_ICASE);
670 theContent= DivTag.substituteAll(theContent,"\n");
671 theDescription= DivTag.substituteAll(theDescription,"\n");
673 RE PTag = new RE("<(p|P)([:space:]+[^>]*)?>");
674 theContent= PTag.substituteAll(theContent,"\n ");
675 theDescription= PTag.substituteAll(theDescription,"\n ");
677 RE PTagClose = new RE("</(p|P)([:space:]+[^>]*)?>");
678 theContent= PTagClose.substituteAll(theContent,"\n");
679 theDescription= PTagClose.substituteAll(theDescription,"\n");
681 RE BRTag = new RE("<(br|BR)([:space:]+[^>]*)?>");
682 theContent= BRTag.substituteAll(theContent,"\n");
683 theDescription= BRTag.substituteAll(theDescription,"\n");
685 RE ATagAll = new RE("<a[^>]*href=(?:\"|\')([^#\"\'][^\'\"]+)(?:\"|\')[^>]*>(.*?)</a>",RE.REG_ICASE);
686 REMatchEnumeration atags= ATagAll.getMatchEnumeration(theContent);
687 String theContentCopy=theContent;
688 while (atags.hasMoreMatches()){
689 REMatch atag = atags.nextMatch();
690 String atagString=atag.toString();
691 String atagStringHref=atag.toString(1);
692 String atagStringText=atag.toString(2);
693 int begin=theContentCopy.indexOf(atagString);
694 theContentCopy=theContentCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theContentCopy.substring(begin+atagString.length());
696 theContent=theContentCopy;
698 REMatchEnumeration atags2= ATagAll.getMatchEnumeration(theDescription);
699 String theDescriptionCopy=theDescription;
700 while (atags2.hasMoreMatches()){
701 REMatch atag = atags2.nextMatch();
702 String atagString=atag.toString();
703 String atagStringHref=atag.toString(1);
704 String atagStringText=atag.toString(2);
705 int begin=theDescriptionCopy.indexOf(atagString);
706 theDescriptionCopy=theDescriptionCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theDescriptionCopy.substring(begin+atagString.length());
708 theDescription=theDescriptionCopy;
711 RE noTags = new RE("<[^>]*>");
712 theContent= noTags.substituteAll(theContent," ");
713 theDescription= noTags.substituteAll(theDescription," ");
715 theContent=mir.util.Translate.decode(theContent);
716 theDescription=mir.util.Translate.decode(theDescription);
718 RE re1 = new RE("\r?\n\r?\n");
719 String theDescription1 = re1.substituteAll(theDescription,"BREAKHERE");
721 RE re2 = new RE("\r?\n");
722 String theDescription2 = re2.substituteAll(theDescription1," ");
724 RE re3 = new RE("BREAKHERE");
725 theDescription = re3.substituteAll(theDescription2,"\n ");
729 catch(REException ree){
730 logger.error(ree.getMessage());
735 RE re1 = new RE("\r?\n\r?\n");
736 String theContent1 = re1.substituteAll(theContentRaw,"BREAKHERE");
737 String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
739 RE re2 = new RE("\r?\n");
740 String theContent2 = re2.substituteAll(theContent1," ");
741 String theDescription2 = re2.substituteAll(theDescription1," ");
743 RE re3 = new RE("BREAKHERE");
744 theContent = " " + re3.substituteAll(theContent2,"\n ");
745 theDescription = re3.substituteAll(theDescription2,"\n ");
748 catch(REException ree){
749 logger.error(ree.getMessage());
753 addArticleSeparator();
755 ColumnText ct = new ColumnText(cb);
757 addArticleMetaInfo(ct,theTitle,theCreator,theDate);
758 addArticleDescription(ct,theDescription);
759 addArticleContent(ct,theContent,images);
760 addArticleSource(ct,theSource);
764 public int getFontByName(String fontName) {
766 if (fontName.equalsIgnoreCase("helvetica")){
767 theFont = Font.HELVETICA;
770 if (fontName.equalsIgnoreCase("courier")) {
771 theFont = Font.COURIER;
774 if (fontName.equalsIgnoreCase("times")) {
775 theFont = Font.TIMES_ROMAN;
778 logger.error("using helvetica because I can't get font for name: "+fontName);
779 theFont = Font.HELVETICA;