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.ArrayList;
41 import java.util.Iterator;
42 import java.util.List;
44 import mir.config.MirPropertiesConfiguration;
45 import mir.entity.EntityBrowser;
46 import mir.log.LoggerWrapper;
47 import mir.misc.StringUtil;
48 import mir.util.DateTimeRoutines;
49 import mir.util.HTMLRoutines;
50 import mircoders.entity.EntityContent;
51 import mircoders.entity.EntityImages;
52 import mircoders.storage.DatabaseImages;
54 import com.lowagie.text.BadElementException;
55 import com.lowagie.text.Document;
56 import com.lowagie.text.DocumentException;
57 import com.lowagie.text.Element;
58 import com.lowagie.text.Font;
59 import com.lowagie.text.Image;
60 import com.lowagie.text.PageSize;
61 import com.lowagie.text.Paragraph;
62 import com.lowagie.text.Phrase;
63 import com.lowagie.text.pdf.BaseFont;
64 import com.lowagie.text.pdf.ColumnText;
65 import com.lowagie.text.pdf.PdfContentByte;
66 import com.lowagie.text.pdf.PdfTemplate;
67 import com.lowagie.text.pdf.PdfWriter;
69 public class PDFGenerator{
71 public Document document;
72 public PdfWriter writer;
73 public PdfContentByte cb;
74 public String localImageDir;
75 public float currentYPosition;
76 public int currentPage;
77 public float pageWidth;
78 public float pageHeight;
79 public float verticalMargin;
80 public float horizontalMargin;
82 public float bottomEdge;
83 public float rightEdge;
84 public float leftEdge;
86 public int maxImageHeight;
87 public int maxImageWidth;
88 protected LoggerWrapper logger;
90 public int indexFontSize;
91 public int indexLineHeight;
92 public int indexFontFamily;
94 public float footerHeight;
95 public String footerText;
96 public int footerFontSize;
97 public int footerFontFamily;
99 public int metaHeight;
100 public int metaFontSize;
101 public int metaFontFamily;
103 public int descriptionLineHeight;
104 public int descriptionFontSize;
105 public int descriptionFontFamily;
107 public int contentLineHeight;
108 public int contentFontSize;
109 public int contentFontFamily;
111 public int sourceLineHeight;
112 public int sourceFontSize;
113 public int sourceFontFamily;
115 public int bigImageCaptionFontSize;
116 public int bigImageCaptionFontFamily;
118 protected MirPropertiesConfiguration configuration;
121 public PDFGenerator(ByteArrayOutputStream out){
122 logger = new LoggerWrapper("PDFGenerator");
123 configuration = MirPropertiesConfiguration.instance();
124 localImageDir=configuration.getString("Producer.Image.Path");
127 indexFontSize = Integer.parseInt(configuration.getString("PDF.Index.FontSize"));
128 indexLineHeight = Integer.parseInt(configuration.getString("PDF.Index.LineHeight"));
129 indexFontFamily = getFontByName(configuration.getString("PDF.Index.FontFamily"));
131 footerText = configuration.getString("PDF.Footer.String");
132 footerFontSize = Integer.parseInt(configuration.getString("PDF.Footer.FontSize"));
133 footerFontFamily = getFontByName(configuration.getString("PDF.Footer.FontFamily"));
134 footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));
136 metaFontSize = Integer.parseInt(configuration.getString("PDF.Meta.FontSize"));
137 metaFontFamily = getFontByName(configuration.getString("PDF.Meta.FontFamily"));
138 metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));
140 descriptionFontSize = Integer.parseInt(configuration.getString("PDF.Description.FontSize"));
141 descriptionLineHeight = Integer.parseInt(configuration.getString("PDF.Description.LineHeight"));
142 descriptionFontFamily = getFontByName(configuration.getString("PDF.Description.FontFamily"));
144 contentFontSize = Integer.parseInt(configuration.getString("PDF.Content.FontSize"));
145 contentLineHeight = Integer.parseInt(configuration.getString("PDF.Content.LineHeight"));
146 contentFontFamily = getFontByName(configuration.getString("PDF.Content.FontFamily"));
148 sourceFontSize = Integer.parseInt(configuration.getString("PDF.Source.FontSize"));
149 sourceLineHeight = Integer.parseInt(configuration.getString("PDF.Source.LineHeight"));
150 sourceFontFamily = getFontByName(configuration.getString("PDF.Source.FontFamily"));
152 bigImageCaptionFontSize = Integer.parseInt(configuration.getString("PDF.BigImageCaption.FontSize"));
153 bigImageCaptionFontFamily = getFontByName(configuration.getString("PDF.BigImageCaption.FontFamily"));
156 catch (NumberFormatException e){
160 // step 1: make a document
162 String pageSize = configuration.getString("PDF.Pagesize");
164 if (pageSize.equals("LETTER")){
165 document = new Document(PageSize.LETTER);
170 document = new Document(PageSize.A4);
175 maxImageHeight = 250;
180 horizontalMargin = 20;
184 topEdge=pageHeight-verticalMargin;
185 bottomEdge=verticalMargin;
186 rightEdge=pageWidth-horizontalMargin;
187 leftEdge=horizontalMargin;
189 currentYPosition=topEdge;
192 String headerText = configuration.getString("PDF.Title.String");
195 writer = PdfWriter.getInstance(document, out);
196 cb = writer.getDirectContent();
199 addHeader(headerText);
201 catch(DocumentException de) {
202 logger.error(de.getMessage());
211 public void addHeader(String headerText){
212 int titleFontSize=Integer.parseInt(configuration.getString("PDF.Title.FontSize"));
213 int titleLineHeight=Integer.parseInt(configuration.getString("PDF.Title.LineHeight"));
214 String titleFontFamily=configuration.getString("PDF.Title.FontFamily");
215 String headerImage=configuration.getString("PDF.Header.Image");
216 int headerImageHeight = Integer.parseInt(configuration.getString("PDF.Header.ImageHeight"));
219 if ((! headerImage.equals("")) && headerImageHeight != 0){
220 PdfTemplate template = cb.createTemplate(rightEdge-horizontalMargin,headerImageHeight);
222 float toYPosition=currentYPosition - headerImageHeight;
223 Image theImage = Image.getInstance(headerImage);
224 theImage.setAbsolutePosition(0,0);
225 // theImage.scaleAbsolute(img_width,img_height);
226 template.addImage(theImage);
229 cb.addTemplate(template,leftEdge,toYPosition);
230 currentYPosition = toYPosition;
232 if (! headerText.equals("")){
233 ColumnText ct = new ColumnText(cb);
235 ct.addText(new Phrase(headerText, new Font(getFontByName(titleFontFamily), titleFontSize,Font.BOLD)));
236 float[] rightCol = {rightEdge,currentYPosition,rightEdge,currentYPosition-titleLineHeight};
237 float[] leftCol = {leftEdge,currentYPosition,leftEdge,currentYPosition-titleLineHeight};
238 ct.setColumns(leftCol,rightCol);
239 ct.setYLine(currentYPosition);
240 ct.setAlignment(Element.ALIGN_CENTER);
243 currentYPosition = currentYPosition - titleLineHeight;
246 catch(DocumentException de) {
247 logger.error(de.getMessage());
249 catch(MalformedURLException de) {
250 logger.error(de.getMessage());
252 catch(IOException de) {
253 logger.error(de.getMessage());
256 public void addIndexItem(EntityContent entityContent){
259 ColumnText ict = new ColumnText(cb);
260 String theTitle = entityContent.getFieldValue("title");
261 String theCreator = entityContent.getFieldValue("creator");
262 Phrase titleP=new Phrase(" - " + theTitle,new Font(indexFontFamily,indexFontSize,Font.BOLD));
263 Phrase creatorP=new Phrase( " :: " + theCreator,new Font(indexFontFamily,indexFontSize));
264 float toYPosition = currentYPosition - indexLineHeight;
265 float[] leftIndexCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
266 float[] rightIndexCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
268 ict.addText(creatorP);
269 ict.setColumns(leftIndexCols,rightIndexCols);
270 ict.setYLine(currentYPosition);
271 ict.setAlignment(Element.ALIGN_LEFT);
273 currentYPosition = toYPosition;
275 catch(DocumentException de) {
276 logger.error(de.getMessage());
283 private int addTextLine(ColumnText ct,int lineHeight,int alignment,float left, float right){
284 logger.debug("adding a line of text");
285 if (! enoughY(lineHeight)){
288 float toYPosition = currentYPosition - lineHeight;
289 float[] leftContentCols = {left,currentYPosition,left,toYPosition};
290 float[] rightContentCols = {right,currentYPosition,right,toYPosition};
291 ct.setColumns(leftContentCols,rightContentCols);
292 ct.setYLine(currentYPosition);
293 ct.setAlignment(alignment);
296 currentYPosition = toYPosition;
299 catch(DocumentException de) {
300 logger.error(de.getMessage());
305 public void addLine(){
307 cb.moveTo(rightEdge, currentYPosition-5);
308 cb.lineTo(leftEdge, currentYPosition-5);
310 currentYPosition = currentYPosition - 10;
314 public void addFooter(){
316 ColumnText fct = new ColumnText(cb);
318 cb.moveTo(rightEdge, bottomEdge+footerHeight-5);
319 cb.lineTo(leftEdge, bottomEdge+footerHeight-5);
321 float[] leftFooterCols = {leftEdge,bottomEdge+footerHeight-1,leftEdge,bottomEdge};
322 float[] rightFooterCols = {rightEdge,bottomEdge+footerHeight-1,rightEdge,bottomEdge};
324 Paragraph footerP=new Paragraph(footerText,new Font(footerFontFamily,footerFontSize));
325 fct.addText(footerP);
327 fct.setColumns(leftFooterCols,rightFooterCols);
328 fct.setYLine(bottomEdge+footerHeight-1);
329 fct.setAlignment(Element.ALIGN_JUSTIFIED);
332 Paragraph numberP=new Paragraph((new Integer(currentPage)).toString(),new Font(footerFontFamily,footerFontSize,Font.BOLD));
333 fct.addText(numberP);
334 fct.setAlignment(Element.ALIGN_RIGHT);
338 catch (DocumentException de){
339 logger.error(de.getMessage());
345 public void newPage(){
351 currentYPosition=topEdge;
353 catch(DocumentException de) {
354 logger.error(de.getMessage());
358 public void addArticleSeparator(){
364 cb.moveTo(rightEdge, currentYPosition-5);
365 cb.lineTo(leftEdge, currentYPosition-5);
367 currentYPosition = currentYPosition - 10;
370 public void addArticleMetaInfo(ColumnText ct,String theTitle,String theCreator,String theDate){
371 //see if we have room for the author and title
373 if (! enoughY(metaHeight)){
377 Paragraph titleP=new Paragraph(theTitle+"\n",new Font(metaFontFamily,metaFontSize,Font.BOLD));
378 Paragraph whowhenP=new Paragraph(theCreator + " " + theDate ,new Font(metaFontFamily,metaFontSize));
380 ct.addText(whowhenP);
382 ct.setYLine(currentYPosition);
383 ct.setAlignment(Element.ALIGN_LEFT);
385 float toYPosition = currentYPosition - metaHeight;
386 float[] leftHeadCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
387 float[] rightHeadCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
389 ct.setColumns(leftHeadCols,rightHeadCols);
392 currentYPosition = toYPosition;
394 catch(DocumentException de) {
395 logger.error(de.getMessage());
400 public void addArticleDescription(ColumnText ct,String theDescription){
401 // Now we add the description, one line at a time, the ct should be empty at this point
404 Paragraph descP=new Paragraph(theDescription,new Font(descriptionFontFamily,descriptionFontSize,Font.BOLD));
407 // every article has a description, so we can assume that:
408 int status = ColumnText.NO_MORE_COLUMN;
411 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake >0){
412 //there is still text left in the description.
413 status = addTextLine(ct,descriptionLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
417 logger.error("runaway description...try increasing the line height or decreasing the font size");
420 public void addArticleContent(ColumnText ct,String theContent,Iterator images){
421 //let's go ahead and add in all the body text
422 Paragraph contentP=new Paragraph(theContent,new Font(contentFontFamily,contentFontSize));
423 ct.addText(contentP);
425 int contentLinesBeforeImages=3;
426 //and assume we have at least one line of text in the content
427 int status = ColumnText.NO_MORE_COLUMN;
429 // let's add a little bit of text, like a couple of lines
431 while (((status & ColumnText.NO_MORE_TEXT) == 0) && x<contentLinesBeforeImages){
432 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
436 boolean addImageOnLeft = true; //we will alternate within articles
437 while (images.hasNext()){
439 EntityImages currentImage=(EntityImages) images.next();
440 float img_width=(new Float(currentImage.getFieldValue("img_width"))).floatValue();
441 float img_height=(new Float(currentImage.getFieldValue("img_height"))).floatValue();
442 if (img_height>maxImageHeight){
443 img_width=(new Float((new Float(img_width*(maxImageHeight/img_height))).intValue())).floatValue();
444 img_height=maxImageHeight;
446 if (img_width>maxImageWidth){
447 img_height=(new Float((new Float(img_height*(maxImageWidth/img_width))).intValue())).floatValue();
448 img_width=maxImageWidth;
451 String img_title=currentImage.getFieldValue("title");
452 String img_path=currentImage.getFieldValue("publish_path");
454 if ((status & ColumnText.NO_MORE_TEXT) == 0){
455 // there is still text, so add an image which will have text wrapped around it, then add the text which
456 // will be on the left or the right of the image
458 float templateMinimumHeight = img_height+20;
459 float templateWidth = img_width+10;
460 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
462 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
465 //here we need a page check
466 if (! enoughY((new Float(templateHeight)).intValue())){
467 //ok, well just fill text to the bottom then
468 float toYPosition = bottomEdge+footerHeight;
469 float[] leftBottomCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
470 float[] rightBottomCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
471 ct.setColumns(leftBottomCols,rightBottomCols);
472 ct.setYLine(currentYPosition);
473 ct.setAlignment(Element.ALIGN_JUSTIFIED);
477 catch(DocumentException de) {
478 logger.error(de.getMessage());
483 float toYPosition=currentYPosition - templateHeight;
486 Image theImage = Image.getInstance(localImageDir+img_path);
487 theImage.scaleAbsolute(img_width,img_height);
488 theImage.setAbsolutePosition(5,13);
490 template.addImage(theImage);
491 template.beginText();
492 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
493 template.setFontAndSize(bf, 8);
494 template.setTextMatrix(5, 3);
495 template.showText(img_title);
498 catch(BadElementException de) {
499 logger.error(de.getMessage());
501 catch(DocumentException de) {
502 logger.error(de.getMessage());
504 catch (MalformedURLException de){
505 logger.error(de.getMessage());
507 catch (IOException de){
508 logger.error(de.getMessage());
512 float leftImageTextEdge=leftEdge;
513 float rightImageTextEdge=rightEdge;
517 cb.addTemplate(template,leftEdge,toYPosition);
518 leftImageTextEdge=leftEdge+templateWidth+5;
519 addImageOnLeft = false;
522 cb.addTemplate(template,rightEdge-templateWidth,toYPosition);
523 rightImageTextEdge = rightEdge-templateWidth-5;
524 addImageOnLeft = true;
527 logger.debug("adding template at " + leftEdge + "," + toYPosition);
529 //and fill some text while we are at it
531 float[] leftBottomCols = {leftImageTextEdge,currentYPosition,leftImageTextEdge,toYPosition};
532 float[] rightBottomCols = {rightImageTextEdge,currentYPosition,rightImageTextEdge,toYPosition};
533 ct.setColumns(leftBottomCols,rightBottomCols);
534 ct.setYLine(currentYPosition);
535 ct.setAlignment(Element.ALIGN_JUSTIFIED);
538 currentYPosition=toYPosition;
540 catch(DocumentException de) {
541 logger.error(de.getMessage());
547 //add an image on the left with a big caption to the right
548 currentYPosition = currentYPosition - 10;
549 float templateMinimumHeight = img_height;
550 float templateWidth = img_width;
551 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
552 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
553 if (! enoughY((new Float(templateHeight)).intValue())){
556 float toYPosition=currentYPosition - templateHeight;
558 Image theImage = Image.getInstance(localImageDir+img_path);
559 theImage.setAbsolutePosition(0,13);
560 theImage.scaleAbsolute(img_width,img_height);
561 template.addImage(theImage);
563 catch(BadElementException de) {
564 logger.error(de.getMessage());
566 catch(DocumentException de) {
567 logger.error(de.getMessage());
569 catch(MalformedURLException de) {
570 logger.error(de.getMessage());
572 catch(IOException de) {
573 logger.error(de.getMessage());
576 cb.addTemplate(template,leftEdge,toYPosition);
579 ColumnText cct = new ColumnText(cb);
580 float[] leftCaptionCols = {leftEdge+templateWidth+5,currentYPosition-5,leftEdge+templateWidth+5,toYPosition};
581 float[] rightCaptionCols = {rightEdge,currentYPosition-5,rightEdge,toYPosition};
583 Paragraph captionP=new Paragraph(img_title,new Font(bigImageCaptionFontFamily,bigImageCaptionFontSize,Font.BOLD));
584 cct.addText(captionP);
585 cct.setColumns(leftCaptionCols,rightCaptionCols);
586 cct.setYLine(currentYPosition-5);
587 cct.setAlignment(Element.ALIGN_LEFT);
590 currentYPosition=toYPosition;
592 catch(DocumentException de) {
593 logger.error(de.getMessage());
598 //add the rest of the text which might be left
600 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake > 0){
601 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
605 logger.error("runaway content....try decreasing font size or increasing line height");
608 private void addArticleSource(ColumnText ct,String theSource){
609 Paragraph sourceP = new Paragraph(theSource,new Font(sourceFontFamily,sourceFontSize,Font.BOLD));
611 addTextLine(ct,sourceLineHeight,Element.ALIGN_RIGHT,leftEdge,rightEdge);
615 private boolean enoughY(int heightOfBlockToAdd){
616 if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
622 public void add(EntityContent entityContent){
623 logger.error("adding a content Entity");
633 * --image without text
637 List extraTables = new ArrayList();
638 extraTables.add("content_x_media cxm");
639 Iterator images = new EntityBrowser(
640 DatabaseImages.getInstance(), "i", extraTables,
641 "cxm.content_id="+entityContent.getId()+"and cxm.media_id=i.id",
642 "i.id desc", 30, -1, 0);
644 String isHTML = entityContent.getFieldValue("is_html");
645 String theTitle = entityContent.getFieldValue("title");
646 String theCreator = entityContent.getFieldValue("creator");
647 String theDate = DateTimeRoutines.advancedDateFormat(
648 configuration.getString("RDF.Meta.DateFormat"),
649 StringUtil.convertMirInternalDateToDate(entityContent.getFieldValue("webdb_create")),
650 configuration.getString("Mir.DefaultTimezone"));
653 String theDescriptionRaw = entityContent.getFieldValue("description");
654 String theContentRaw = entityContent.getFieldValue("content_data");
655 String theSource = configuration.getString("Producer.PublicationHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getFieldValue("publish_path") + entityContent.getFieldValue("id") + ".shtml";
659 String theContent = "";
660 String theDescription = "";
662 if (isHTML.equals("1")){
667 RE nobackslashr = new RE("\r");
668 theContent= nobackslashr.substituteAll(theContentRaw,"");
669 theDescription= nobackslashr.substituteAll(theDescriptionRaw,"");
671 RE HxTag = new RE("</?h[1-6][^>]*>",RE.REG_ICASE);
672 theContent = HxTag.substituteAll(theContent,"\n\n");
673 theDescription = HxTag.substituteAll(theDescription,"\n\n");
675 RE ListItemTag = new RE("<li[^>]*>",RE.REG_ICASE);
676 theContent = ListItemTag.substituteAll(theContent,"\n * ");
677 theDescription = ListItemTag.substituteAll(theDescription,"\n * ");
679 RE ListTag = new RE("<(u|o)l[^>]*>",RE.REG_ICASE);
680 theContent = ListTag.substituteAll(theContent,"\n");
681 theDescription = ListTag.substituteAll(theDescription,"\n");
683 RE DivTag = new RE("</?div[^>]*>",RE.REG_ICASE);
684 theContent= DivTag.substituteAll(theContent,"\n");
685 theDescription= DivTag.substituteAll(theDescription,"\n");
687 RE PTag = new RE("<(p|P)([:space:]+[^>]*)?>");
688 theContent= PTag.substituteAll(theContent,"\n ");
689 theDescription= PTag.substituteAll(theDescription,"\n ");
691 RE PTagClose = new RE("</(p|P)([:space:]+[^>]*)?>");
692 theContent= PTagClose.substituteAll(theContent,"\n");
693 theDescription= PTagClose.substituteAll(theDescription,"\n");
695 RE BRTag = new RE("<(br|BR)([:space:]+[^>]*)?>");
696 theContent= BRTag.substituteAll(theContent,"\n");
697 theDescription= BRTag.substituteAll(theDescription,"\n");
699 RE ATagAll = new RE("<a[^>]*href=(?:\"|\')([^#\"\'][^\'\"]+)(?:\"|\')[^>]*>(.*?)</a>",RE.REG_ICASE);
700 REMatchEnumeration atags= ATagAll.getMatchEnumeration(theContent);
701 String theContentCopy=theContent;
702 while (atags.hasMoreMatches()){
703 REMatch atag = atags.nextMatch();
704 String atagString=atag.toString();
705 String atagStringHref=atag.toString(1);
706 String atagStringText=atag.toString(2);
707 int begin=theContentCopy.indexOf(atagString);
708 theContentCopy=theContentCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theContentCopy.substring(begin+atagString.length());
710 theContent=theContentCopy;
712 REMatchEnumeration atags2= ATagAll.getMatchEnumeration(theDescription);
713 String theDescriptionCopy=theDescription;
714 while (atags2.hasMoreMatches()){
715 REMatch atag = atags2.nextMatch();
716 String atagString=atag.toString();
717 String atagStringHref=atag.toString(1);
718 String atagStringText=atag.toString(2);
719 int begin=theDescriptionCopy.indexOf(atagString);
720 theDescriptionCopy=theDescriptionCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theDescriptionCopy.substring(begin+atagString.length());
722 theDescription=theDescriptionCopy;
725 RE noTags = new RE("<[^>]*>");
726 theContent= noTags.substituteAll(theContent," ");
727 theDescription= noTags.substituteAll(theDescription," ");
729 theContent = HTMLRoutines.resolveHTMLEntites(theContent);
730 theDescription = HTMLRoutines.resolveHTMLEntites(theDescription);
732 RE re1 = new RE("\r?\n\r?\n");
733 String theDescription1 = re1.substituteAll(theDescription,"BREAKHERE");
735 RE re2 = new RE("\r?\n");
736 String theDescription2 = re2.substituteAll(theDescription1," ");
738 RE re3 = new RE("BREAKHERE");
739 theDescription = re3.substituteAll(theDescription2,"\n ");
743 catch(REException ree){
744 logger.error(ree.getMessage());
749 RE re1 = new RE("\r?\n\r?\n");
750 String theContent1 = re1.substituteAll(theContentRaw,"BREAKHERE");
751 String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
753 RE re2 = new RE("\r?\n");
754 String theContent2 = re2.substituteAll(theContent1," ");
755 String theDescription2 = re2.substituteAll(theDescription1," ");
757 RE re3 = new RE("BREAKHERE");
758 theContent = " " + re3.substituteAll(theContent2,"\n ");
759 theDescription = re3.substituteAll(theDescription2,"\n ");
762 catch(REException ree){
763 logger.error(ree.getMessage());
767 addArticleSeparator();
769 ColumnText ct = new ColumnText(cb);
771 addArticleMetaInfo(ct,theTitle,theCreator,theDate);
772 addArticleDescription(ct,theDescription);
773 addArticleContent(ct,theContent,images);
774 addArticleSource(ct,theSource);
778 public int getFontByName(String fontName) {
780 if (fontName.equalsIgnoreCase("helvetica")){
781 theFont = Font.HELVETICA;
784 if (fontName.equalsIgnoreCase("courier")) {
785 theFont = Font.COURIER;
788 if (fontName.equalsIgnoreCase("times")) {
789 theFont = Font.TIMES_ROMAN;
792 logger.error("using helvetica because I can't get font for name: "+fontName);
793 theFont = Font.HELVETICA;