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");
122 configuration = MirPropertiesConfiguration.instance();
124 catch (MirPropertiesConfiguration.PropertiesConfigExc e) {
125 throw new RuntimeException("Can't get configuration: " + e.getMessage());
127 localImageDir=configuration.getString("Producer.Image.Path");
130 indexFontSize = Integer.parseInt(configuration.getString("PDF.Index.FontSize"));
131 indexLineHeight = Integer.parseInt(configuration.getString("PDF.Index.LineHeight"));
132 indexFontFamily = getFontByName(configuration.getString("PDF.Index.FontFamily"));
134 footerText = configuration.getString("PDF.Footer.String");
135 footerFontSize = Integer.parseInt(configuration.getString("PDF.Footer.FontSize"));
136 footerFontFamily = getFontByName(configuration.getString("PDF.Footer.FontFamily"));
137 footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));;
139 metaFontSize = Integer.parseInt(configuration.getString("PDF.Meta.FontSize"));
140 metaFontFamily = getFontByName(configuration.getString("PDF.Meta.FontFamily"));
141 metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));;
143 descriptionFontSize = Integer.parseInt(configuration.getString("PDF.Description.FontSize"));
144 descriptionLineHeight = Integer.parseInt(configuration.getString("PDF.Description.LineHeight"));
145 descriptionFontFamily = getFontByName(configuration.getString("PDF.Description.FontFamily"));
147 contentFontSize = Integer.parseInt(configuration.getString("PDF.Content.FontSize"));
148 contentLineHeight = Integer.parseInt(configuration.getString("PDF.Content.LineHeight"));
149 contentFontFamily = getFontByName(configuration.getString("PDF.Content.FontFamily"));
151 sourceFontSize = Integer.parseInt(configuration.getString("PDF.Source.FontSize"));
152 sourceLineHeight = Integer.parseInt(configuration.getString("PDF.Source.LineHeight"));
153 sourceFontFamily = getFontByName(configuration.getString("PDF.Source.FontFamily"));
155 bigImageCaptionFontSize = Integer.parseInt(configuration.getString("PDF.BigImageCaption.FontSize"));
156 bigImageCaptionFontFamily = getFontByName(configuration.getString("PDF.BigImageCaption.FontFamily"));
159 catch (NumberFormatException e){
163 // step 1: make a document
165 String pageSize = configuration.getString("PDF.Pagesize");
167 if (pageSize.equals("LETTER")){
168 document = new Document(PageSize.LETTER);
173 document = new Document(PageSize.A4);
178 maxImageHeight = 250;
183 horizontalMargin = 20;
187 topEdge=pageHeight-verticalMargin;
188 bottomEdge=verticalMargin;
189 rightEdge=pageWidth-horizontalMargin;
190 leftEdge=horizontalMargin;
192 currentYPosition=topEdge;
195 String headerText = configuration.getString("PDF.Title.String");
198 writer = PdfWriter.getInstance(document, out);
199 cb = writer.getDirectContent();
202 addHeader(headerText);
204 catch(DocumentException de) {
205 logger.error(de.getMessage());
214 public void addHeader(String headerText){
215 int titleFontSize=Integer.parseInt(configuration.getString("PDF.Title.FontSize"));
216 int titleLineHeight=Integer.parseInt(configuration.getString("PDF.Title.LineHeight"));
217 String titleFontFamily=configuration.getString("PDF.Title.FontFamily");
218 String headerImage=configuration.getString("PDF.Header.Image");
219 int headerImageHeight = Integer.parseInt(configuration.getString("PDF.Header.ImageHeight"));
222 if ((! headerImage.equals("")) && headerImageHeight != 0){
223 PdfTemplate template = cb.createTemplate(rightEdge-horizontalMargin,headerImageHeight);
225 float toYPosition=currentYPosition - headerImageHeight;
226 Image theImage = Image.getInstance(headerImage);
227 theImage.setAbsolutePosition(0,0);
228 // theImage.scaleAbsolute(img_width,img_height);
229 template.addImage(theImage);
232 cb.addTemplate(template,leftEdge,toYPosition);
233 currentYPosition = toYPosition;
235 if (! headerText.equals("")){
236 ColumnText ct = new ColumnText(cb);
238 ct.addText(new Phrase(headerText, new Font(getFontByName(titleFontFamily), titleFontSize,Font.BOLD)));
239 float[] rightCol = {rightEdge,currentYPosition,rightEdge,currentYPosition-titleLineHeight};
240 float[] leftCol = {leftEdge,currentYPosition,leftEdge,currentYPosition-titleLineHeight};
241 ct.setColumns(leftCol,rightCol);
242 ct.setYLine(currentYPosition);
243 ct.setAlignment(Element.ALIGN_CENTER);
246 currentYPosition = currentYPosition - titleLineHeight;
249 catch(DocumentException de) {
250 logger.error(de.getMessage());
252 catch(MalformedURLException de) {
253 logger.error(de.getMessage());
255 catch(IOException de) {
256 logger.error(de.getMessage());
259 public void addIndexItem(EntityContent entityContent){
262 ColumnText ict = new ColumnText(cb);
263 String theTitle = entityContent.getValue("title");
264 String theCreator = entityContent.getValue("creator");
265 Phrase titleP=new Phrase(" - " + theTitle,new Font(indexFontFamily,indexFontSize,Font.BOLD));
266 Phrase creatorP=new Phrase( " :: " + theCreator,new Font(indexFontFamily,indexFontSize));
267 float toYPosition = currentYPosition - indexLineHeight;
268 float[] leftIndexCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
269 float[] rightIndexCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
271 ict.addText(creatorP);
272 ict.setColumns(leftIndexCols,rightIndexCols);
273 ict.setYLine(currentYPosition);
274 ict.setAlignment(Element.ALIGN_LEFT);
276 currentYPosition = toYPosition;
278 catch(DocumentException de) {
279 logger.error(de.getMessage());
286 private int addTextLine(ColumnText ct,int lineHeight,int alignment,float left, float right){
287 logger.debug("adding a line of text");
288 if (! enoughY(lineHeight)){
291 float toYPosition = currentYPosition - lineHeight;
292 float[] leftContentCols = {left,currentYPosition,left,toYPosition};
293 float[] rightContentCols = {right,currentYPosition,right,toYPosition};
294 ct.setColumns(leftContentCols,rightContentCols);
295 ct.setYLine(currentYPosition);
296 ct.setAlignment(alignment);
299 currentYPosition = toYPosition;
302 catch(DocumentException de) {
303 logger.error(de.getMessage());
308 public void addLine(){
310 cb.moveTo(rightEdge, currentYPosition-5);
311 cb.lineTo(leftEdge, currentYPosition-5);
313 currentYPosition = currentYPosition - 10;
317 public void addFooter(){
319 ColumnText fct = new ColumnText(cb);
321 cb.moveTo(rightEdge, bottomEdge+footerHeight-5);
322 cb.lineTo(leftEdge, bottomEdge+footerHeight-5);
324 float[] leftFooterCols = {leftEdge,bottomEdge+footerHeight-1,leftEdge,bottomEdge};
325 float[] rightFooterCols = {rightEdge,bottomEdge+footerHeight-1,rightEdge,bottomEdge};
327 Paragraph footerP=new Paragraph(footerText,new Font(footerFontFamily,footerFontSize));
328 fct.addText(footerP);
330 fct.setColumns(leftFooterCols,rightFooterCols);
331 fct.setYLine(bottomEdge+footerHeight-1);
332 fct.setAlignment(Element.ALIGN_JUSTIFIED);
335 Paragraph numberP=new Paragraph((new Integer(currentPage)).toString(),new Font(footerFontFamily,footerFontSize,Font.BOLD));
336 fct.addText(numberP);
337 fct.setAlignment(Element.ALIGN_RIGHT);
341 catch (DocumentException de){
342 logger.error(de.getMessage());
348 public void newPage(){
354 currentYPosition=topEdge;
356 catch(DocumentException de) {
357 logger.error(de.getMessage());
361 public void addArticleSeparator(){
367 cb.moveTo(rightEdge, currentYPosition-5);
368 cb.lineTo(leftEdge, currentYPosition-5);
370 currentYPosition = currentYPosition - 10;
373 public void addArticleMetaInfo(ColumnText ct,String theTitle,String theCreator,String theDate){
374 //see if we have room for the author and title
376 if (! enoughY(metaHeight)){
380 Paragraph titleP=new Paragraph(theTitle+"\n",new Font(metaFontFamily,metaFontSize,Font.BOLD));
381 Paragraph whowhenP=new Paragraph(theCreator + " " + theDate ,new Font(metaFontFamily,metaFontSize));
383 ct.addText(whowhenP);
385 ct.setYLine(currentYPosition);
386 ct.setAlignment(Element.ALIGN_LEFT);
388 float toYPosition = currentYPosition - metaHeight;
389 float[] leftHeadCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
390 float[] rightHeadCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
392 ct.setColumns(leftHeadCols,rightHeadCols);
395 currentYPosition = toYPosition;
397 catch(DocumentException de) {
398 logger.error(de.getMessage());
403 public void addArticleDescription(ColumnText ct,String theDescription){
404 // Now we add the description, one line at a time, the ct should be empty at this point
407 Paragraph descP=new Paragraph(theDescription,new Font(descriptionFontFamily,descriptionFontSize,Font.BOLD));
410 // every article has a description, so we can assume that:
411 int status = ColumnText.NO_MORE_COLUMN;
414 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake >0){
415 //there is still text left in the description.
416 status = addTextLine(ct,descriptionLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
420 logger.error("runaway description...try increasing the line height or decreasing the font size");
423 public void addArticleContent(ColumnText ct,String theContent,Iterator images){
424 //let's go ahead and add in all the body text
425 Paragraph contentP=new Paragraph(theContent,new Font(contentFontFamily,contentFontSize));
426 ct.addText(contentP);
428 int contentLinesBeforeImages=3;
429 //and assume we have at least one line of text in the content
430 int status = ColumnText.NO_MORE_COLUMN;
432 // let's add a little bit of text, like a couple of lines
434 while (((status & ColumnText.NO_MORE_TEXT) == 0) && x<contentLinesBeforeImages){
435 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
439 boolean addImageOnLeft = true; //we will alternate within articles
440 while (images.hasNext()){
442 EntityImages currentImage=(EntityImages) images.next();
443 float img_width=(new Float(currentImage.getValue("img_width"))).floatValue();
444 float img_height=(new Float(currentImage.getValue("img_height"))).floatValue();
445 if (img_height>maxImageHeight){
446 img_width=(new Float((new Float(img_width*(maxImageHeight/img_height))).intValue())).floatValue();
447 img_height=maxImageHeight;
449 if (img_width>maxImageWidth){
450 img_height=(new Float((new Float(img_height*(maxImageWidth/img_width))).intValue())).floatValue();
451 img_width=maxImageWidth;
454 String img_title=currentImage.getValue("title");
455 String img_path=currentImage.getValue("publish_path");
457 if ((status & ColumnText.NO_MORE_TEXT) == 0){
458 // there is still text, so add an image which will have text wrapped around it, then add the text which
459 // will be on the left or the right of the image
461 float templateMinimumHeight = img_height+20;
462 float templateWidth = img_width+10;
463 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
465 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
468 //here we need a page check
469 if (! enoughY((new Float(templateHeight)).intValue())){
470 //ok, well just fill text to the bottom then
471 float toYPosition = bottomEdge+footerHeight;
472 float[] leftBottomCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
473 float[] rightBottomCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
474 ct.setColumns(leftBottomCols,rightBottomCols);
475 ct.setYLine(currentYPosition);
476 ct.setAlignment(Element.ALIGN_JUSTIFIED);
480 catch(DocumentException de) {
481 logger.error(de.getMessage());
486 float toYPosition=currentYPosition - templateHeight;
489 Image theImage = Image.getInstance(localImageDir+img_path);
490 theImage.scaleAbsolute(img_width,img_height);
491 theImage.setAbsolutePosition(5,13);
493 template.addImage(theImage);
494 template.beginText();
495 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
496 template.setFontAndSize(bf, 8);
497 template.setTextMatrix(5, 3);
498 template.showText(img_title);
501 catch(BadElementException de) {
502 logger.error(de.getMessage());
504 catch(DocumentException de) {
505 logger.error(de.getMessage());
507 catch (MalformedURLException de){
508 logger.error(de.getMessage());
510 catch (IOException de){
511 logger.error(de.getMessage());
515 float leftImageTextEdge=leftEdge;
516 float rightImageTextEdge=rightEdge;
520 cb.addTemplate(template,leftEdge,toYPosition);
521 leftImageTextEdge=leftEdge+templateWidth+5;
522 addImageOnLeft = false;
525 cb.addTemplate(template,rightEdge-templateWidth,toYPosition);
526 rightImageTextEdge = rightEdge-templateWidth-5;
527 addImageOnLeft = true;
530 logger.debug("adding template at " + leftEdge + "," + toYPosition);
532 //and fill some text while we are at it
534 float[] leftBottomCols = {leftImageTextEdge,currentYPosition,leftImageTextEdge,toYPosition};
535 float[] rightBottomCols = {rightImageTextEdge,currentYPosition,rightImageTextEdge,toYPosition};
536 ct.setColumns(leftBottomCols,rightBottomCols);
537 ct.setYLine(currentYPosition);
538 ct.setAlignment(Element.ALIGN_JUSTIFIED);
541 currentYPosition=toYPosition;
543 catch(DocumentException de) {
544 logger.error(de.getMessage());
550 //add an image on the left with a big caption to the right
551 currentYPosition = currentYPosition - 10;
552 float templateMinimumHeight = img_height;
553 float templateWidth = img_width;
554 float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
555 PdfTemplate template = cb.createTemplate(templateWidth,templateHeight);
556 if (! enoughY((new Float(templateHeight)).intValue())){
559 float toYPosition=currentYPosition - templateHeight;
561 Image theImage = Image.getInstance(localImageDir+img_path);
562 theImage.setAbsolutePosition(0,13);
563 theImage.scaleAbsolute(img_width,img_height);
564 template.addImage(theImage);
566 catch(BadElementException de) {
567 logger.error(de.getMessage());
569 catch(DocumentException de) {
570 logger.error(de.getMessage());
572 catch(MalformedURLException de) {
573 logger.error(de.getMessage());
575 catch(IOException de) {
576 logger.error(de.getMessage());
579 cb.addTemplate(template,leftEdge,toYPosition);
582 ColumnText cct = new ColumnText(cb);
583 float[] leftCaptionCols = {leftEdge+templateWidth+5,currentYPosition-5,leftEdge+templateWidth+5,toYPosition};
584 float[] rightCaptionCols = {rightEdge,currentYPosition-5,rightEdge,toYPosition};
586 Paragraph captionP=new Paragraph(img_title,new Font(bigImageCaptionFontFamily,bigImageCaptionFontSize,Font.BOLD));
587 cct.addText(captionP);
588 cct.setColumns(leftCaptionCols,rightCaptionCols);
589 cct.setYLine(currentYPosition-5);
590 cct.setAlignment(Element.ALIGN_LEFT);
593 currentYPosition=toYPosition;
595 catch(DocumentException de) {
596 logger.error(de.getMessage());
601 //add the rest of the text which might be left
603 while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake > 0){
604 status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
608 logger.error("runaway content....try decreasing font size or increasing line height");
611 private void addArticleSource(ColumnText ct,String theSource){
612 Paragraph sourceP = new Paragraph(theSource,new Font(sourceFontFamily,sourceFontSize,Font.BOLD));
614 addTextLine(ct,sourceLineHeight,Element.ALIGN_RIGHT,leftEdge,rightEdge);
618 private boolean enoughY(int heightOfBlockToAdd){
619 if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
626 public void add(EntityContent entityContent){
627 logger.error("adding a content Entity");
637 * --image without text
641 Vector extraTables = new Vector();
642 extraTables.add("content_x_media cxm");
643 Iterator images = new EntityBrowser(
644 DatabaseImages.getInstance(), "i", extraTables,
645 "cxm.content_id="+entityContent.getId()+"and cxm.media_id=i.id",
646 "i.id desc", 30, -1, 0);
648 String isHTML = entityContent.getValue("is_html");
649 String theTitle = entityContent.getValue("title");
650 String theCreator = entityContent.getValue("creator");
651 String theDate = DateTimeFunctions.advancedDateFormat(
652 configuration.getString("RDF.Meta.DateFormat"),
653 StringUtil.convertMirInternalDateToDate(entityContent.getValue("webdb_create")),
654 configuration.getString("Mir.DefaultTimezone"));
657 String theDescriptionRaw = entityContent.getValue("description");
658 String theContentRaw = entityContent.getValue("content_data");
659 String theSource = configuration.getString("Producer.ProductionHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getValue("publish_path") + entityContent.getValue("id") + ".shtml";
663 String theContent = "";
664 String theDescription = "";
666 if (isHTML.equals("1")){
671 RE nobackslashr = new RE("\r");
672 theContent= nobackslashr.substituteAll(theContentRaw,"");
674 RE HxTag = new RE("</?h[1-6][^>]*>",RE.REG_ICASE);
675 theContent = HxTag.substituteAll(theContent,"\n\n");
677 RE ListItemTag = new RE("<li[^>]*>",RE.REG_ICASE);
678 theContent = ListItemTag.substituteAll(theContent,"\n * ");
680 RE ListTag = new RE("<(u|o)l[^>]*>",RE.REG_ICASE);
681 theContent = ListTag.substituteAll(theContent,"\n");
683 RE DivTag = new RE("</?div[^>]*>",RE.REG_ICASE);
684 theContent= DivTag.substituteAll(theContent,"\n");
686 RE PTag = new RE("<(p|P)([:space:]+[^>]*)?>");
687 theContent= PTag.substituteAll(theContent,"\n ");
689 RE PTagClose = new RE("</(p|P)([:space:]+[^>]*)?>");
690 theContent= PTagClose.substituteAll(theContent,"\n");
692 RE BRTag = new RE("<(br|BR)([:space:]+[^>]*)?>");
693 theContent= BRTag.substituteAll(theContent,"\n");
695 RE ATagAll = new RE("<a[^>]*href=(?:\"|\')([^#\"\'][^\'\"]+)(?:\"|\')[^>]*>(.*?)</a>",RE.REG_ICASE);
696 REMatchEnumeration atags= ATagAll.getMatchEnumeration(theContent);
697 String theContentCopy=theContent;
698 while (atags.hasMoreMatches()){
699 REMatch atag = atags.nextMatch();
700 String atagString=atag.toString();
701 String atagStringHref=atag.toString(1);
702 String atagStringText=atag.toString(2);
703 int begin=theContentCopy.indexOf(atagString);
704 theContentCopy=theContentCopy.substring(0,begin) + atagStringText + " ["+ atagStringHref + "] " + theContentCopy.substring(begin+atagString.length());
706 theContent=theContentCopy;
708 RE noTags = new RE("<[^>]*>");
709 theContent= noTags.substituteAll(theContent," ");
711 theContent=mir.util.Translate.decode(theContent);
713 RE re1 = new RE("\r?\n\r?\n");
714 String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
716 RE re2 = new RE("\r?\n");
717 String theDescription2 = re2.substituteAll(theDescription1," ");
719 RE re3 = new RE("BREAKHERE");
720 theDescription = re3.substituteAll(theDescription2,"\n ");
724 catch(REException ree){
725 logger.error(ree.getMessage());
730 RE re1 = new RE("\r?\n\r?\n");
731 String theContent1 = re1.substituteAll(theContentRaw,"BREAKHERE");
732 String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
734 RE re2 = new RE("\r?\n");
735 String theContent2 = re2.substituteAll(theContent1," ");
736 String theDescription2 = re2.substituteAll(theDescription1," ");
738 RE re3 = new RE("BREAKHERE");
739 theContent = " " + re3.substituteAll(theContent2,"\n ");
740 theDescription = re3.substituteAll(theDescription2,"\n ");
743 catch(REException ree){
744 logger.error(ree.getMessage());
748 addArticleSeparator();
750 ColumnText ct = new ColumnText(cb);
752 addArticleMetaInfo(ct,theTitle,theCreator,theDate);
753 addArticleDescription(ct,theDescription);
754 addArticleContent(ct,theContent,images);
755 addArticleSource(ct,theSource);
759 public int getFontByName(String fontName) {
761 if (fontName.equalsIgnoreCase("helvetica")){
762 theFont = Font.HELVETICA;
765 if (fontName.equalsIgnoreCase("courier")) {
766 theFont = Font.COURIER;
769 if (fontName.equalsIgnoreCase("times")) {
770 theFont = Font.TIMES_ROMAN;
773 logger.error("using helvetica because I can't get font for name: "+fontName);
774 theFont = Font.HELVETICA;