a couple of changes:
authorjohn <john>
Sun, 20 Apr 2003 15:28:23 +0000 (15:28 +0000)
committerjohn <john>
Sun, 20 Apr 2003 15:28:23 +0000 (15:28 +0000)
-pdf font and font size is configurable via config.properties

-PDFGenerator is a lot cleaner(refactored into functional methods, rather than one big add article method)
 this will make it easier to have it be localized, i hope

-added some "brakes" to stop iText from looping for ever if it was trying to put text in a line at a time, but the lineHeight was
 set too small, so it doesn't put any text, so it still has text left over, so it tries to put text in a line at a time.....you
 get the idea

source/default.properties
source/mircoders/pdf/PDFGenerator.java

index 480ce82..2785101 100755 (executable)
@@ -150,10 +150,6 @@ ServletModule.FileEdit.FileDirectory=/pub/Dokumente/Indymedia/de-tech/Mir/produc
 ServletModule.FileEdit.ExtFilter=.*\.inc$
 ServletModule.FileEdit.Recursive=0
 
-# Settings allowing the admin interface to show what the public urls are:
-Article.PublicUrl=/en/${date.formatted.yyyy}/${date.formatted.MM}/${id}.shtml
-Comment.PublicUrl=/en/${to_content.date.formatted.yyyy}/${to_content.date.formatted.MM}/${to_content.id}.shtml
-
 #
 #
 # DYNAMIC SITE CONFIG
@@ -238,21 +234,71 @@ Producer.Icon.BigText=text_big.gif
 Producer.HTML2FOStyleSheet=/some/dir/mir/etc/producer/html2fo.xsl
 
 # the following lines are used to construct PDFs on the fly from one or more articles
-# for the moment, if you want to change anything else about your pdfs, you
+# for the moment, if you want to change anything else about your pdfs, you 
 # will have to learn some java!
 #
-# keep in mind that there may not be enough room for all the text you enter as the
-# value of one these options, if text doesn't appear, the only easy thing to do is
+# keep in mind that there may not be enough room for all the text you enter as the 
+# value of one these options, if text doesn't appear, the only easy thing to do is 
 # use less text!
 #
+# also, be sure to adjust the corresponding line height if you change a font size...
+# this may require some trial and error to get right
+#
+# Available font families are helvetica, courier, and times
+#
+
 
 # a single line of big text which will appear at the top of the first page of all generated pdfs
 
-PDF.Title=INDYMEDIA SOMEWHERE
+PDF.Title.String=INDYMEDIA SOMEWHERE
+PDF.Title.FontSize=24
+PDF.Title.LineHeight=28
+PDF.Title.FontFamily=courier
+
+# footer is about two lines of small text which will appear at the bottom of every page 
+
+PDF.Footer.String=Indymedia does blah.  Content is good, and free to use for non-commercial purposes under the Open Content license. if you have questions, email someone.
+PDF.Footer.Height=54
+PDF.Footer.FontSize=12
+PDF.Footer.FontFamily=helvetica 
+
+# how to format the index, i.e. the newsletter table of contents
+
+PDF.Index.FontSize=12
+PDF.Index.LineHeight=16
+PDF.Index.FontFamily=helvetica
+
+# how to format the meta-data, i.e. title, author, date
+
+PDF.Meta.Height=36
+PDF.Meta.FontSize=14
+PDF.Meta.FontFamily=helvetica 
+
+# how to format the article description
+
+PDF.Description.FontSize=12
+PDF.Description.LineHeight=16
+PDF.Description.FontFamily=helvetica
+
+# how to format the article content
+
+PDF.Content.FontSize=10
+PDF.Content.LineHeight=16
+PDF.Content.FontFamily=helvetica
+
+# the formatting for images in gallery mode
+
+PDF.BigImageCaption.FontSize=16
+PDF.BigImageCaption.FontFamily=helvetica
+
+# the formatting for the article source
+
+PDF.Source.FontSize=12
+PDF.Source.LineHeight=16
+PDF.Source.FontFamily=courier
+
 
-# about two lines of small text which will appear at the bottom of every page
 
-PDF.Footer=Indymedia does blah.  Content is good, and free to use for non-commercial purposes under the Open Content license. if you have questions, email someone.
 
 #
 # the size paper your target audience will likely have in their printers.  pick one of A4 or LETTER
index 1944aa7..4347b3a 100755 (executable)
@@ -71,11 +71,38 @@ public class PDFGenerator{
   public float bottomEdge;
   public float rightEdge;
   public float leftEdge;
+
+  public int    maxImageHeight;   
+  public int    maxImageWidth;    
+  protected LoggerWrapper logger;
+
+  public int indexFontSize; 
+  public int indexLineHeight; 
+  public int indexFontFamily; 
+
   public float footerHeight;
   public String footerText;
+  public int footerFontSize; 
+  public int footerFontFamily; 
 
-  protected LoggerWrapper logger;
+  public int metaHeight;
+  public int metaFontSize;
+  public int metaFontFamily;
+
+  public int descriptionLineHeight;
+  public int descriptionFontSize;
+  public int descriptionFontFamily;
 
+  public int contentLineHeight;
+  public int contentFontSize;
+  public int contentFontFamily;
+
+  public int sourceLineHeight;
+  public int sourceFontSize;
+  public int sourceFontFamily;
+
+  public int bigImageCaptionFontSize;
+  public int bigImageCaptionFontFamily;
 
   protected MirPropertiesConfiguration configuration;
 
@@ -89,7 +116,41 @@ public class PDFGenerator{
       throw new RuntimeException("Can't get configuration: " + e.getMessage());
     }
     localImageDir=configuration.getString("Producer.Image.Path");
+
+    try {
+      indexFontSize   = Integer.parseInt(configuration.getString("PDF.Index.FontSize"));
+      indexLineHeight = Integer.parseInt(configuration.getString("PDF.Index.LineHeight"));
+      indexFontFamily = getFontByName(configuration.getString("PDF.Index.FontFamily"));
+      
+      footerText = configuration.getString("PDF.Footer.String");
+      footerFontSize   = Integer.parseInt(configuration.getString("PDF.Footer.FontSize"));
+      footerFontFamily = getFontByName(configuration.getString("PDF.Footer.FontFamily"));
+      footerHeight = Integer.parseInt(configuration.getString("PDF.Footer.Height"));;
+      
+      metaFontSize   = Integer.parseInt(configuration.getString("PDF.Meta.FontSize"));
+      metaFontFamily = getFontByName(configuration.getString("PDF.Meta.FontFamily"));
+      metaHeight = Integer.parseInt(configuration.getString("PDF.Meta.Height"));;
+      
+      descriptionFontSize   = Integer.parseInt(configuration.getString("PDF.Description.FontSize"));
+      descriptionLineHeight = Integer.parseInt(configuration.getString("PDF.Description.LineHeight"));
+      descriptionFontFamily = getFontByName(configuration.getString("PDF.Description.FontFamily"));
+      
+      contentFontSize   = Integer.parseInt(configuration.getString("PDF.Content.FontSize"));
+      contentLineHeight = Integer.parseInt(configuration.getString("PDF.Content.LineHeight"));
+      contentFontFamily = getFontByName(configuration.getString("PDF.Content.FontFamily"));
+      
+      sourceFontSize   = Integer.parseInt(configuration.getString("PDF.Source.FontSize"));
+      sourceLineHeight = Integer.parseInt(configuration.getString("PDF.Source.LineHeight"));
+      sourceFontFamily = getFontByName(configuration.getString("PDF.Source.FontFamily"));
+      
+      bigImageCaptionFontSize   = Integer.parseInt(configuration.getString("PDF.BigImageCaption.FontSize"));
+      bigImageCaptionFontFamily = getFontByName(configuration.getString("PDF.BigImageCaption.FontFamily"));
     
+    }
+    catch (NumberFormatException e){
+      e.printStackTrace();
+    }
+
     // step 1: make a document
     
     String pageSize = configuration.getString("PDF.Pagesize");
@@ -105,75 +166,85 @@ public class PDFGenerator{
        pageHeight=842;
     }
 
-    try {
-      
-      verticalMargin = 20;
-      horizontalMargin = 20;
-      
-      footerHeight = 54;
-
-      topEdge=pageHeight-verticalMargin;
-      bottomEdge=verticalMargin;
-      rightEdge=pageWidth-horizontalMargin;
-      leftEdge=horizontalMargin;
-      
-      currentYPosition=topEdge;
-      currentPage = 1;
-      
-      String headerText = configuration.getString("PDF.Title");
-      footerText = configuration.getString("PDF.Footer");
+    maxImageHeight    = 250;
+    maxImageWidth     = 250;
+        
+   
+    verticalMargin = 20;
+    horizontalMargin = 20;
+    
 
+    
+    topEdge=pageHeight-verticalMargin;
+    bottomEdge=verticalMargin;
+    rightEdge=pageWidth-horizontalMargin;
+    leftEdge=horizontalMargin;
+    
+    currentYPosition=topEdge;
+    currentPage = 1;
+    
+    String headerText = configuration.getString("PDF.Title.String");
+    
+    try{
       writer = PdfWriter.getInstance(document, out);
       cb = writer.getDirectContent();
-
-      document.open();      
-
       
+      document.open();      
+      addHeader(headerText);
+    }
+    catch(DocumentException de) {
+      logger.error(de.getMessage());
+    }
+  }
+  
+  public void stop(){
+    addFooter();
+    document.close();
+  }
 
+  public void addHeader(String headerText){
+    int titleFontSize=Integer.parseInt(configuration.getString("PDF.Title.FontSize"));
+    int titleLineHeight=Integer.parseInt(configuration.getString("PDF.Title.LineHeight"));
+    String titleFontFamily=configuration.getString("PDF.Title.FontFamily");
+    
+    try {
+           
       ColumnText ct = new ColumnText(cb);   
       //add a basic header
-      ct.addText(new Phrase(headerText, FontFactory.getFont(FontFactory.COURIER, 24,Font.BOLD)));
-      
-      float[] rightCol = {rightEdge,topEdge,rightEdge,topEdge-28};
-      float[] leftCol = {leftEdge,topEdge,leftEdge,topEdge-28};
-      //      int status = ct.go();
+      ct.addText(new Phrase(headerText, new Font(getFontByName(titleFontFamily), titleFontSize,Font.BOLD)));
+      float[] rightCol = {rightEdge,topEdge,rightEdge,topEdge-titleLineHeight};
+      float[] leftCol = {leftEdge,topEdge,leftEdge,topEdge-titleLineHeight};
       ct.setColumns(leftCol,rightCol);
-      //      int status=ct.go();
       ct.setYLine(topEdge);
       ct.setAlignment(Element.ALIGN_CENTER);
       ct.go();
       
-      currentYPosition = currentYPosition - 28;
+      currentYPosition = currentYPosition - titleLineHeight;
       
     }
     catch(DocumentException de) {
       logger.error(de.getMessage());
     }
   }
-  
-  public void stop(){
-    addFooter();
-    document.close();
-  }
 
   public void addIndexItem(EntityContent entityContent){
     try {
-    float indexLineHeight = 16;
-    ColumnText ict = new ColumnText(cb);
-    String theTitle = entityContent.getValue("title");
-    String theCreator = entityContent.getValue("creator");
-    Phrase titleP=new Phrase(" - " +  theTitle,new Font(Font.HELVETICA,12,Font.BOLD));
-    Phrase creatorP=new Phrase( " :: " + theCreator,new Font(Font.HELVETICA,12));
-    float toYPosition = currentYPosition - indexLineHeight;
-    float[] leftIndexCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-    float[] rightIndexCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-    ict.addText(titleP);
-    ict.addText(creatorP);
-    ict.setColumns(leftIndexCols,rightIndexCols);
-    ict.setYLine(currentYPosition);
-    ict.setAlignment(Element.ALIGN_LEFT);
-    int status=ict.go();
-    currentYPosition = toYPosition;
+
+      ColumnText ict = new ColumnText(cb);
+      String theTitle = entityContent.getValue("title");
+      String theCreator = entityContent.getValue("creator");
+      Phrase titleP=new Phrase(" - " +  theTitle,new Font(indexFontFamily,indexFontSize,Font.BOLD));
+      Phrase creatorP=new Phrase( " :: " + theCreator,new Font(indexFontFamily,indexFontSize));
+      float toYPosition = currentYPosition - indexLineHeight;
+      float[] leftIndexCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
+      float[] rightIndexCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
+      ict.addText(titleP);
+      ict.addText(creatorP);
+      ict.setColumns(leftIndexCols,rightIndexCols);
+      ict.setYLine(currentYPosition);
+      ict.setAlignment(Element.ALIGN_LEFT);
+      int status=ict.go();
+      currentYPosition = toYPosition;
     }
     catch(DocumentException de) {
       logger.error(de.getMessage());
@@ -183,6 +254,27 @@ public class PDFGenerator{
 
   }
 
+  private int addTextLine(ColumnText ct,int lineHeight,int alignment,float left, float right){
+    logger.debug("adding a line of text");
+    if (! enoughY(lineHeight)){
+      newPage();
+    }
+    float toYPosition = currentYPosition - lineHeight;
+    float[] leftContentCols = {left,currentYPosition,left,toYPosition};
+    float[] rightContentCols = {right,currentYPosition,right,toYPosition};
+    ct.setColumns(leftContentCols,rightContentCols);
+    ct.setYLine(currentYPosition);
+    ct.setAlignment(alignment);
+    try{
+      int status=ct.go();
+      currentYPosition = toYPosition;
+      return status;
+    }
+    catch(DocumentException de) {
+      logger.error(de.getMessage());
+    }
+    return 0;
+  }
 
   public void addLine(){
     cb.setLineWidth(1f);
@@ -203,7 +295,7 @@ public class PDFGenerator{
     float[] leftFooterCols = {leftEdge,bottomEdge+footerHeight-1,leftEdge,bottomEdge};
     float[] rightFooterCols = {rightEdge,bottomEdge+footerHeight-1,rightEdge,bottomEdge};
     
-    Paragraph footerP=new Paragraph(footerText,new Font(Font.HELVETICA,12));
+    Paragraph footerP=new Paragraph(footerText,new Font(footerFontFamily,footerFontSize));
     fct.addText(footerP);
     
     fct.setColumns(leftFooterCols,rightFooterCols);
@@ -211,7 +303,7 @@ public class PDFGenerator{
     fct.setAlignment(Element.ALIGN_JUSTIFIED);
     int status=fct.go();
 
-    Paragraph numberP=new Paragraph((new Integer(currentPage)).toString(),new Font(Font.HELVETICA,12,Font.BOLD));
+    Paragraph numberP=new Paragraph((new Integer(currentPage)).toString(),new Font(footerFontFamily,footerFontSize,Font.BOLD));
     fct.addText(numberP);
     fct.setAlignment(Element.ALIGN_RIGHT);
     status=fct.go();
@@ -237,205 +329,138 @@ public class PDFGenerator{
     }
   }
   
-  public boolean enoughY(int heightOfBlockToAdd){
-    if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
-      return false;
-    else 
-      return true;
+  public void addArticleSeparator(){
+    // make a line 
+    if (! enoughY(10)){
+      newPage();
+    }
+    cb.setLineWidth(1f);
+    cb.moveTo(rightEdge, currentYPosition-5);
+    cb.lineTo(leftEdge, currentYPosition-5);
+    cb.stroke();
+    currentYPosition = currentYPosition - 10;
   }
-  
-  
-  public void add(EntityContent entityContent){
-    logger.error("adding a content Entity");
-    EntityList images=DatabaseContentToMedia.getInstance().getImages(entityContent);
-    String theTitle = entityContent.getValue("title");
-    String theCreator = entityContent.getValue("creator");
-    String theDate = entityContent.getValue("webdb_create_formatted");
-    String theDescriptionRaw = entityContent.getValue("description");
-    String theContentRaw = entityContent.getValue("content_data");
-    String theSource =  configuration.getString("Producer.ProductionHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getValue("publish_path") + entityContent.getValue("id") + ".shtml";
 
-    boolean addImageOnLeft = true;
+  public void addArticleMetaInfo(ColumnText ct,String theTitle,String theCreator,String theDate){
+      //see if we have room for the author and title
     
-    String theContent = "";
-    String theDescription = "";
+    if (! enoughY(metaHeight)){
+       newPage();
+      }
+    
+    Paragraph titleP=new Paragraph(theTitle+"\n",new Font(metaFontFamily,metaFontSize,Font.BOLD));
+    Paragraph whowhenP=new Paragraph(theCreator + "  " + theDate ,new Font(metaFontFamily,metaFontSize));
+    ct.addText(titleP);
+    ct.addText(whowhenP);
+    
+    ct.setYLine(currentYPosition);
+    ct.setAlignment(Element.ALIGN_LEFT);
     
+    float toYPosition = currentYPosition - metaHeight;
+    float[] leftHeadCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
+    float[] rightHeadCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
+    
+    ct.setColumns(leftHeadCols,rightHeadCols);
     try { 
-      RE re1 = new RE("\r?\n\r?\n");
-      String theContent1 = re1.substituteAll(theContentRaw,"BREAKHERE");
-      String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
-      
-      RE re2 = new RE("\r?\n");
-      String theContent2 = re2.substituteAll(theContent1," ");
-      String theDescription2 = re2.substituteAll(theDescription1," ");
-      
-      RE re3 = new RE("BREAKHERE");
-      theContent = "    " + re3.substituteAll(theContent2,"\n    ");
-      theDescription = re3.substituteAll(theDescription2,"\n    ");
-
+      ct.go();
+      currentYPosition = toYPosition;
     }
-    catch(REException ree){
-      logger.error(ree.getMessage());
+    catch(DocumentException de) {
+      logger.error(de.getMessage());
     }
+    
+  }
 
-
-    try { 
-      
-      // make a line (don't worry about the bottomEdge, we should actually write in that area(it's a thin line!)
-      cb.setLineWidth(1f);
-      cb.moveTo(rightEdge, currentYPosition-5);
-      cb.lineTo(leftEdge, currentYPosition-5);
-      cb.stroke();
-      
-      currentYPosition = currentYPosition - 10;
-      
-
-      //see if we have room for the author and title
-      if (! enoughY(36)){
-       newPage();
-      }
-
-      ColumnText ct = new ColumnText(cb);
-
-      Paragraph titleP=new Paragraph(theTitle+"\n",new Font(Font.HELVETICA,14,Font.BOLD));
-      Paragraph whowhenP=new Paragraph(theCreator + "  " + theDate ,new Font(Font.HELVETICA,14));
-      ct.addText(titleP);
-      ct.addText(whowhenP);
-      
-      ct.setYLine(currentYPosition);
-      ct.setAlignment(Element.ALIGN_LEFT);
-      
-      float toYPosition = currentYPosition - 36;
-      float[] leftHeadCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-      float[] rightHeadCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-
-      ct.setColumns(leftHeadCols,rightHeadCols);
-      ct.go();
-      currentYPosition = toYPosition;
+  public void addArticleDescription(ColumnText ct,String theDescription){
+    // Now we add the description, one line at a time, the ct should be empty at this point
     
-      
-      // Now add the description, one line at a time, the ct should be empty at this point
-            
-      Paragraph descP=new Paragraph(theDescription,new Font(Font.HELVETICA,12,Font.BOLD));
+    
+    Paragraph descP=new Paragraph(theDescription,new Font(descriptionFontFamily,descriptionFontSize,Font.BOLD));
+    ct.addText(descP);
+    
+    // every article has a description, so we can assume that:
+    int status = ColumnText.NO_MORE_COLUMN;
+    
+    int brake=1000; 
+    while ((status & ColumnText.NO_MORE_TEXT) == 0 && brake >0){
+      //there is still text left in the description.
+      status = addTextLine(ct,descriptionLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
+      brake--;
+    }
+    if (brake == 0)
+      logger.error("runaway description...try increasing the line height or decreasing the font size");
+  }
+  public void addArticleContent(ColumnText ct,String theContent,EntityList images){
+    //let's go ahead and add in all the body text
+    Paragraph contentP=new Paragraph(theContent,new Font(contentFontFamily,contentFontSize));
+    ct.addText(contentP);
+    
+    int contentLinesBeforeImages=3;
+    //and assume we have at least one line of text in the content
+    int status = ColumnText.NO_MORE_COLUMN;
+    
+    // let's add a little bit of text, like a couple of lines
+    int x = 0;
+    while (((status & ColumnText.NO_MORE_TEXT) == 0) && x<contentLinesBeforeImages){
+      status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
+      x++;
+    }
 
-      ct.addText(descP);
+    boolean addImageOnLeft = true; //we will alternate within articles
+    while (images.hasNext()){
       
-      // every article has a description, so we can assume that:
-      int status = ColumnText.NO_MORE_COLUMN;
-      
-      int descriptionLineHeight=16;
-      
-      while ((status & ColumnText.NO_MORE_TEXT) == 0){
-       //there is still text left in the description.
-       logger.error("adding a line to the description");
-       
-       //but is there room on the page?
-       if (! enoughY(descriptionLineHeight)){
-         newPage();
-       }
-       
-       //now we are set to add a line of descriptive text
-       toYPosition = currentYPosition - descriptionLineHeight;
-       float[] leftDescCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-       float[] rightDescCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-       ct.setColumns(leftDescCols,rightDescCols);
-       ct.setYLine(currentYPosition);
-       ct.setAlignment(Element.ALIGN_JUSTIFIED);
-       status=ct.go();
-       currentYPosition = toYPosition;
+      EntityImages currentImage=(EntityImages) images.next();
+      float img_width=(new Float(currentImage.getValue("img_width"))).floatValue();
+      float img_height=(new Float(currentImage.getValue("img_height"))).floatValue();
+      if (img_height>maxImageHeight){
+       img_width=(new Float((new Float(img_width*(maxImageHeight/img_height))).intValue())).floatValue();
+       img_height=maxImageHeight;
       }
-      
-      // ok, now on to the meat of the job ahead
-      
-      int contentLineHeight=16;
-
-      //let's go ahead and add in all the body text
-      Paragraph contentP=new Paragraph(theContent,new Font(Font.HELVETICA,10));
-      ct.addText(contentP);
-      //and assume we have at least one line of text in the content
-      status = ColumnText.NO_MORE_COLUMN;
-
-      int maxImageHeight=250;
-      int maxImageWidth=250;
-
-      
-      // let's add a little bit of text, like a couple of lines
-      int x = 0;
-      while (((status & ColumnText.NO_MORE_TEXT) == 0) && x<3){
-       //in case we have some text left
-       
-       logger.error("adding a line to the content");
-
-       //but is there room on the page?
-       if (! enoughY(contentLineHeight)){
-         newPage();
-       }
-       
-       //now we are set to add a line of content text
-       toYPosition = currentYPosition - contentLineHeight;
-       float[] leftContentCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-       float[] rightContentCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-       ct.setColumns(leftContentCols,rightContentCols);
-       ct.setYLine(currentYPosition);
-       ct.setAlignment(Element.ALIGN_JUSTIFIED);
-       status=ct.go();
-       currentYPosition = toYPosition;
-       x++;
+      if (img_width>maxImageWidth){
+       img_height=(new Float((new Float(img_height*(maxImageWidth/img_width))).intValue())).floatValue();
+       img_width=maxImageWidth;
       }
 
-
-
-      while (images.hasNext()){
+      String img_title=currentImage.getValue("title");
+      String img_path=currentImage.getValue("publish_path");
+      
+      if ((status & ColumnText.NO_MORE_TEXT) == 0){ 
+       // there is still text, so add an image which will have text wrapped around it, then add the text which 
+       // will be on the left or the right of the image
        
-       EntityImages currentImage=(EntityImages) images.next();
-       float img_width=(new Float(currentImage.getValue("img_width"))).floatValue();
-       float img_height=(new Float(currentImage.getValue("img_height"))).floatValue();
-       if (img_height>maxImageHeight){
-         img_width=(new Float((new Float(img_width*(maxImageHeight/img_height))).intValue())).floatValue();
-         img_height=maxImageHeight;
-       }
-       if (img_width>maxImageWidth){
-         img_height=(new Float((new Float(img_height*(maxImageWidth/img_width))).intValue())).floatValue();
-         img_width=maxImageWidth;
-       }
-
-       String img_title=currentImage.getValue("title");
-       String img_path=currentImage.getValue("publish_path");
+       float templateMinimumHeight = img_height+20;
+       float templateWidth = img_width+10;
+       float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
        
-         
+       PdfTemplate template = cb.createTemplate(templateWidth,templateHeight); 
        
-
-       if ((status & ColumnText.NO_MORE_TEXT) == 0){ 
-         // there is still text, so add an image which will have text wrapped around it, then add the text which 
-         // will be on the left or the right of the image
-
-         float templateMinimumHeight = img_height+20;
-         float templateWidth = img_width+10;
-         
-         float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
-         
-         
-         PdfTemplate template = cb.createTemplate(templateWidth,templateHeight); 
        
-         
-         //here we need a page check
-         if (! enoughY((new Float(templateHeight)).intValue())){
-           //ok, well just fill text to the bottom then
-           toYPosition = bottomEdge+footerHeight;
-           float[] leftBottomCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-           float[] rightBottomCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-           ct.setColumns(leftBottomCols,rightBottomCols);
-           ct.setYLine(currentYPosition);
-           ct.setAlignment(Element.ALIGN_JUSTIFIED);
+       //here we need a page check
+       if (! enoughY((new Float(templateHeight)).intValue())){
+         //ok, well just fill text to the bottom then
+         float toYPosition = bottomEdge+footerHeight;
+         float[] leftBottomCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
+         float[] rightBottomCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
+         ct.setColumns(leftBottomCols,rightBottomCols);
+         ct.setYLine(currentYPosition);
+         ct.setAlignment(Element.ALIGN_JUSTIFIED);
+         try{ 
            status=ct.go();
-           newPage();
          }
+         catch(DocumentException de) {
+           logger.error(de.getMessage());
+         }
+         newPage();
+       }
+       
+       float toYPosition=currentYPosition - templateHeight;
 
-         toYPosition=currentYPosition - templateHeight;
-         
+       try {
          Image theImage = Image.getInstance(localImageDir+img_path);
          theImage.scaleAbsolute(img_width,img_height);
          theImage.setAbsolutePosition(5,13); 
+         
          template.addImage(theImage);
          template.beginText();
          BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
@@ -443,182 +468,213 @@ public class PDFGenerator{
          template.setTextMatrix(5, 3);
          template.showText(img_title);
          template.endText();
-         
-         
-         float leftImageTextEdge=leftEdge;
-         float rightImageTextEdge=rightEdge;
-         
+       }
+       catch(BadElementException de) {
+         logger.error(de.getMessage());
+       }
+       catch(DocumentException de) {
+         logger.error(de.getMessage());
+       }
+       catch (MalformedURLException de){
+        logger.error(de.getMessage());
+       }
+       catch (IOException de){
+         logger.error(de.getMessage());
+       }
 
-         if (addImageOnLeft){
-           cb.addTemplate(template,leftEdge,toYPosition);
-           leftImageTextEdge=leftEdge+templateWidth+5;
-           addImageOnLeft = false;
-         }         
-         else {
-           cb.addTemplate(template,rightEdge-templateWidth,toYPosition);
-           rightImageTextEdge = rightEdge-templateWidth-5;
-           addImageOnLeft = true;
-         }
+       
+       float leftImageTextEdge=leftEdge;
+       float rightImageTextEdge=rightEdge;
+       
+       
+       if (addImageOnLeft){
+         cb.addTemplate(template,leftEdge,toYPosition);
+         leftImageTextEdge=leftEdge+templateWidth+5;
+         addImageOnLeft = false;
+       }           
+       else {
+         cb.addTemplate(template,rightEdge-templateWidth,toYPosition);
+         rightImageTextEdge = rightEdge-templateWidth-5;
+         addImageOnLeft = true;
+       }
 
-         logger.error("adding template at " + leftEdge + "," + toYPosition);
-         
-         //and fill some text while we are at it
-         
-         float[] leftBottomCols = {leftImageTextEdge,currentYPosition,leftImageTextEdge,toYPosition};
-         float[] rightBottomCols = {rightImageTextEdge,currentYPosition,rightImageTextEdge,toYPosition};
-         ct.setColumns(leftBottomCols,rightBottomCols);
-         ct.setYLine(currentYPosition);
-         ct.setAlignment(Element.ALIGN_JUSTIFIED);
-         status=ct.go();
-         
-         currentYPosition=toYPosition;
-         
-         
-         }
-       else { 
-         //add an image on the left with a big caption to the right
-         currentYPosition = currentYPosition - 10;
-         float templateMinimumHeight = img_height;
-         float templateWidth = img_width;
-         float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
-         PdfTemplate template = cb.createTemplate(templateWidth,templateHeight); 
-         if (! enoughY((new Float(templateHeight)).intValue())){
-           newPage();
-         }
-         toYPosition=currentYPosition - templateHeight;
+       logger.debug("adding template at " + leftEdge + "," + toYPosition);
+       
+       //and fill some text while we are at it
+       
+       float[] leftBottomCols = {leftImageTextEdge,currentYPosition,leftImageTextEdge,toYPosition};
+       float[] rightBottomCols = {rightImageTextEdge,currentYPosition,rightImageTextEdge,toYPosition};
+       ct.setColumns(leftBottomCols,rightBottomCols);
+       ct.setYLine(currentYPosition);
+       ct.setAlignment(Element.ALIGN_JUSTIFIED);
+       try{ 
+       status=ct.go();
+       currentYPosition=toYPosition;
+       }
+       catch(DocumentException de) {
+         logger.error(de.getMessage());
+       }
+       
+       
+      }
+      else { 
+       //add an image on the left with a big caption to the right
+       currentYPosition = currentYPosition - 10;
+       float templateMinimumHeight = img_height;
+       float templateWidth = img_width;
+       float templateHeight = templateMinimumHeight+contentLineHeight-(templateMinimumHeight % contentLineHeight);
+       PdfTemplate template = cb.createTemplate(templateWidth,templateHeight); 
+       if (! enoughY((new Float(templateHeight)).intValue())){
+         newPage();
+       }
+       float toYPosition=currentYPosition - templateHeight;
+       try{ 
          Image theImage = Image.getInstance(localImageDir+img_path);
          theImage.setAbsolutePosition(0,13); 
          theImage.scaleAbsolute(img_width,img_height);
          template.addImage(theImage);
-         
-         cb.addTemplate(template,leftEdge,toYPosition);
-         
-         // add a big caption
-         ColumnText cct = new ColumnText(cb);   
-         float[] leftCaptionCols = {leftEdge+templateWidth+5,currentYPosition-5,leftEdge+templateWidth+5,toYPosition};
-         float[] rightCaptionCols = {rightEdge,currentYPosition-5,rightEdge,toYPosition};
-         
-         Paragraph captionP=new Paragraph(img_title,new Font(Font.HELVETICA,16,Font.BOLD));
-         cct.addText(captionP);
-         cct.setColumns(leftCaptionCols,rightCaptionCols);
-         cct.setYLine(currentYPosition-5);
-         cct.setAlignment(Element.ALIGN_LEFT);
-         cct.go();
+       }
+       catch(BadElementException de) {
+         logger.error(de.getMessage());
+       }
+       catch(DocumentException de) {
+         logger.error(de.getMessage());
+       }
+       catch(MalformedURLException de) {
+         logger.error(de.getMessage());
+       }
+       catch(IOException de) {
+         logger.error(de.getMessage());
+       }
 
+       cb.addTemplate(template,leftEdge,toYPosition);
          
-
+       // add a big caption
+       ColumnText cct = new ColumnText(cb);   
+       float[] leftCaptionCols = {leftEdge+templateWidth+5,currentYPosition-5,leftEdge+templateWidth+5,toYPosition};
+       float[] rightCaptionCols = {rightEdge,currentYPosition-5,rightEdge,toYPosition};
+       
+       Paragraph captionP=new Paragraph(img_title,new Font(bigImageCaptionFontFamily,bigImageCaptionFontSize,Font.BOLD));
+       cct.addText(captionP);
+       cct.setColumns(leftCaptionCols,rightCaptionCols);
+       cct.setYLine(currentYPosition-5);
+       cct.setAlignment(Element.ALIGN_LEFT);
+       try{
+         cct.go();
          currentYPosition=toYPosition;
-         
-
        }
-       
+       catch(DocumentException de) {
+         logger.error(de.getMessage());
+       }
       }
+    }
+    
+    //add the rest of the text which might be left
+    int brake = 10000;
+    while ((status & ColumnText.NO_MORE_TEXT) == 0  && brake > 0){
+      status=addTextLine(ct,contentLineHeight,Element.ALIGN_JUSTIFIED,leftEdge,rightEdge);
+      brake --;
+    }
+    if (brake == 0)
+      logger.error("runaway content....try decreasing font size or increasing line height");
+  }
 
-      
-      while ((status & ColumnText.NO_MORE_TEXT) == 0){
-       //in case we have some text left
-       
-       logger.error("adding a line to the content");
+  private void addArticleSource(ColumnText ct,String theSource){
+    Paragraph sourceP = new Paragraph(theSource,new Font(sourceFontFamily,sourceFontSize,Font.BOLD));
+    ct.addText(sourceP);
+    addTextLine(ct,sourceLineHeight,Element.ALIGN_RIGHT,leftEdge,rightEdge);
+  }
 
-       //but is there room on the page?
-       if (! enoughY(contentLineHeight)){
-         newPage();
-       }
-       
-       //now we are set to add a line of content text
-       toYPosition = currentYPosition - contentLineHeight;
-       float[] leftContentCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-       float[] rightContentCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-       ct.setColumns(leftContentCols,rightContentCols);
-       ct.setYLine(currentYPosition);
-       ct.setAlignment(Element.ALIGN_JUSTIFIED);
-       status=ct.go();
-       currentYPosition = toYPosition;
 
-      }
-      
-      // and add the source link 
-      
-      toYPosition = currentYPosition - contentLineHeight;
-      float[] leftSourceCols = {leftEdge,currentYPosition,leftEdge,toYPosition};
-      float[] rightSourceCols = {rightEdge,currentYPosition,rightEdge,toYPosition};
-      ct.setColumns(leftSourceCols,rightSourceCols);
-      Paragraph sourceP = new Paragraph(theSource,new Font(Font.COURIER,12,Font.BOLD));
-      ct.addText(sourceP);
-      ct.setYLine(currentYPosition);
-      ct.setAlignment(Element.ALIGN_RIGHT);
-      status=ct.go();
-      currentYPosition = toYPosition;
+  private boolean enoughY(int heightOfBlockToAdd){
+    if ((currentYPosition - heightOfBlockToAdd - footerHeight) < bottomEdge )
+      return false;
+    else 
+      return true;
+  }
+  
+  
+  public void add(EntityContent entityContent){
+    logger.error("adding a content Entity");
+    
+    /*
+     * initialize
+     * separate
+     * meta info
+     * description
+     * content  
+     * --image with text
+     * --normal text
+     * --image without text
+     * source
+    */
+    
+    EntityList images=DatabaseContentToMedia.getInstance().getImages(entityContent);
+    String theTitle = entityContent.getValue("title");
+    String theCreator = entityContent.getValue("creator");
+    String theDate = entityContent.getValue("webdb_create_formatted");
+    String theDescriptionRaw = entityContent.getValue("description");
+    String theContentRaw = entityContent.getValue("content_data");
+    String theSource =  configuration.getString("Producer.ProductionHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getValue("publish_path") + entityContent.getValue("id") + ".shtml";
 
 
+    
+    String theContent = "";
+    String theDescription = "";
+    
+    try { 
+      RE re1 = new RE("\r?\n\r?\n");
+      String theContent1 = re1.substituteAll(theContentRaw,"BREAKHERE");
+      String theDescription1 = re1.substituteAll(theDescriptionRaw,"BREAKHERE");
       
+      RE re2 = new RE("\r?\n");
+      String theContent2 = re2.substituteAll(theContent1," ");
+      String theDescription2 = re2.substituteAll(theDescription1," ");
       
-      
-    }
-    catch(DocumentException de) {
-      logger.error(de.getMessage());
-    }
-    catch(MalformedURLException de) {
-      logger.error(de.getMessage());
+      RE re3 = new RE("BREAKHERE");
+      theContent = "    " + re3.substituteAll(theContent2,"\n    ");
+      theDescription = re3.substituteAll(theDescription2,"\n    ");
+
     }
-    catch(IOException de) {
-      logger.error(de.getMessage());
+    catch(REException ree){
+      logger.error(ree.getMessage());
     }
-    /*    while(images.hasNext()){
-      
-     EntityImages currentImage=(EntityImages) images.next();
-     float img_width=(new Float(currentImage.getValue("img_width"))).floatValue();
-     float img_height=(new Float(currentImage.getValue("img_height"))).floatValue();
-      if (img_width>250){
-       img_height=(new Float((new Float(img_height*(250.0F/img_width))).intValue())).floatValue();
-       img_width=250.0F;
-      }
-      String img_title=currentImage.getValue("title");
-      String img_path=currentImage.getValue("publish_path");
 
-      PdfTemplate template = cb.createTemplate(img_width+10, img_height+20); 
-      try{
-       Image theImage = Image.getInstance(localImageDir+img_path);
-       theImage.setAbsolutePosition(5,13); 
-       template.addImage(theImage);
-       template.beginText();
-       BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
-       template.setFontAndSize(bf, 8);
-       template.setTextMatrix(5, 3);
-       template.showText(img_title);
-       template.endText();
-       ImgTemplate it = new ImgTemplate(template);
-       it.setAlignment(Image.RIGHT | Image.TEXTWRAP);
-       document.add(it);
-       
-       document.add(new Paragraph("this is a test of adding some text to see if we bump down a line when there is some text"));
-       
-      }
-      catch(DocumentException de) {
-       System.err.println(de.getMessage());
-      }
-      catch(IOException ioe) {
-       System.err.println(ioe.getMessage());
-      }
-      } */
-
-    /*
-    try { 
 
+    addArticleSeparator();
+    
+    ColumnText ct = new ColumnText(cb);
+    
+    addArticleMetaInfo(ct,theTitle,theCreator,theDate);
+    addArticleDescription(ct,theDescription);
+    addArticleContent(ct,theContent,images);
+    addArticleSource(ct,theSource);
       
-      Paragraph p=new Paragraph(theContent,new Font(Font.HELVETICA,11));
-      p.setAlignment(Paragraph.ALIGN_JUSTIFIED);
-      
-      document.add(p);
+  }
+
+  public int getFontByName(String fontName) {
+    int theFont = 0;
+    if (fontName.equalsIgnoreCase("helvetica")){
+      theFont = Font.HELVETICA;
     }
-    catch(DocumentException de) {
-      System.err.println(de.getMessage());
+    else {
+      if (fontName.equalsIgnoreCase("courier")) { 
+       theFont = Font.COURIER;
+      }
+      else {
+       if (fontName.equalsIgnoreCase("times")) { 
+         theFont = Font.TIMES_ROMAN;
+       }
+       else {
+         logger.error("using helvetica because I can't get font for name: "+fontName);
+         theFont = Font.HELVETICA;
+       }
+      }
     }
-
-    */
+    
+    return theFont;
 
   }
-
 }