You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by sreejithyes <sr...@gmail.com> on 2014/06/18 12:30:02 UTC

Formatting a RtfTable using RTFLib

How to format a table (RtfTable) using RTFLib in java. Like setting padding,
aligning, border, font...I couldn't find any examples. Can some body give
some examples. 

Thanks in advance.



--
View this message in context: http://apache-fop.1065347.n5.nabble.com/Formatting-a-RtfTable-using-RTFLib-tp40808.html
Sent from the FOP - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: Formatting a RtfTable using RTFLib

Posted by sreejithyes <sr...@gmail.com>.
Hi Robert,


Thank you very much for your answer. That helped me to get it half way. I
was able to set border and border colour to the table. *But I am still not
sure how to set padding top, padding bottom and align center of the table
column values* in the table. The method I used to generate a sample table
is:

public void generateSiteVariantTable(RtfSection sect) throws IOException {
    	
    	RtfTable tbl = sect.newTable(new DummyTableColumnsInfo());
        
        FOPRtfAttributes attrs = new FOPRtfAttributes();
        attrs.set(IBorderAttributes.BORDER_COLOR, new Color(200,200,200));
        attrs.set(IBorderAttributes.BORDER_SINGLE_THICKNESS);
        attrs.set(IBorderAttributes.BORDER_WIDTH, 3);
        attrs.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, 10);
        attrs.set(ITableAttributes.ATTR_CELL_U_PADDING_BOTTOM, 5);
        attrs.set(ITableAttributes.ATTR_CELL_PADDING_TOP, 10);
        attrs.set(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, 5);
        attrs.set(ITableAttributes.ATTR_CELL_VERT_ALIGN_CENTER);
        
        
        RtfAttributes atr = new RtfAttributes();
        atr.set(ITableAttributes.CELL_BORDER_TOP, attrs)
        		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
        		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
        		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs)
        		.set(ITableAttributes.ATTR_CELL_PADDING_TOP, attrs)
        		.set(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, attrs)
        		.set(ITableAttributes.ATTR_CELL_VERT_ALIGN_CENTER, attrs);

        tbl.setBorderAttributes(atr);
        RtfTableRow header = tbl.newTableRow();

        RtfTableCell hCol1 = header.newTableCell(INCH_TO_TWIPS*1);
        hCol1.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
attrs)
		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs)
		.set(ITableAttributes.ATTR_CELL_PADDING_TOP, attrs)
		.set(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, attrs)
		.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, attrs)
		.set(ITableAttributes.ATTR_CELL_U_PADDING_BOTTOM, attrs)
		.set(ITableAttributes.ATTR_CELL_VERT_ALIGN_CENTER, attrs);
        hCol1.newParagraph().newText("GENE", attr_bold_center);
        RtfTableCell hCol2 = header.newTableCell(INCH_TO_TWIPS*2);
        hCol2.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
attrs)
		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs)
		.set(ITableAttributes.ATTR_CELL_PADDING_TOP, attrs)
		.set(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, attrs)
		.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, attrs)
		.set(ITableAttributes.ATTR_CELL_U_PADDING_BOTTOM, attrs)
		.set(ITableAttributes.ATTR_CELL_VERT_ALIGN_CENTER, attrs);
        hCol2.newParagraph().newText("TRANSLATION", attr_bold_center);
        RtfTableCell hCol3 = header.newTableCell(INCH_TO_TWIPS*3);
        hCol3.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
attrs)
		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs)
		.set(ITableAttributes.ATTR_CELL_PADDING_TOP, attrs)
		.set(ITableAttributes.ATTR_CELL_PADDING_BOTTOM, attrs)
		.set(ITableAttributes.ATTR_CELL_U_PADDING_TOP, attrs)
		.set(ITableAttributes.ATTR_CELL_U_PADDING_BOTTOM, attrs)
		.set(ITableAttributes.ATTR_CELL_VERT_ALIGN_CENTER, attrs);
        hCol3.newParagraph().newText("TRANSCRIPT", attr_bold_center);
        
        for (int row = 0; row < MAX_ROW; row++) {
            RtfTableRow r=tbl.newTableRow();

            RtfTableCell col1 = r.newTableCell(INCH_TO_TWIPS*1);
            col1.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
attrs)
    		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
    		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
    		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs);
            col1.newParagraph().newText("SLC26A2", attr_tbl_center);
            
            RtfTableCell col2 = r.newTableCell(INCH_TO_TWIPS*2);
            col2.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
attrs)
    		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
    		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
    		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs);
            col2.newParagraph().newText("p.Thr689Ser", attr_tbl_center);
            
            RtfTableCell col3 = r.newTableCell(INCH_TO_TWIPS*3);
            col3.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP,
attrs)
    		.set(ITableAttributes.CELL_BORDER_BOTTOM, attrs)
    		.set(ITableAttributes.CELL_BORDER_LEFT, attrs)
    		.set(ITableAttributes.CELL_BORDER_RIGHT, attrs);
            col3.newParagraph().newText("ENST00000286298", attr_tbl_center);
        }
    }

Thanks again for your kind help.

Sreejith



--
View this message in context: http://apache-fop.1065347.n5.nabble.com/Formatting-a-RtfTable-using-RTFLib-tp40808p40822.html
Sent from the FOP - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: Formatting a RtfTable using RTFLib

Posted by Robert Meyer <rm...@hotmail.co.uk>.
Hi,

The only examples we have are here as the project is not really maintained anymore:

http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/rtf/rtflib/testdocs/

but these only show some basic table examples. I'm guessing you're using this in conjunction with FOP as opposed to using it separately? From taking a quick look at the code there seems to be another method in RtfTableRow which is newTableCell(int cellWidth, RtfAttributes attrs). Looking around it appears as though you can specify features such as padding and borders by adding them to the attrs list. For example, in BorderAttributesConverter there are the following:

            FOPRtfAttributes attrs = new FOPRtfAttributes();
            attrs.set(IBorderAttributes.BORDER_COLOR, border.getBorderColor(side));
            attrs.set(IBorderAttributes.BORDER_WIDTH, border.getBorderWidth(side, false) / 50);
            attributes.set(ITableAttributes.CELL_BORDER_TOP, attrs);

and...

            double paddingPt = border.getPadding(side, false, null) / 1000.0;
            // Padding in twips
            int padding = (int) Math.round(paddingPt * FoUnitsConverter.POINT_TO_TWIPS);

            // Add padding to corresponding space (space-before or space-after)
            // if side == START or END, do nothing
            if (padding != 0) {
                if (side == CommonBorderPaddingBackground.BEFORE) {
                    attributes.addIntegerValue(padding, RtfText.SPACE_BEFORE);
                } else if (side == CommonBorderPaddingBackground.AFTER) {
                    attributes.addIntegerValue(padding, RtfText.SPACE_AFTER);
                }
            }

Hope this helps,

Regards,

Robert Meyer

> Date: Wed, 18 Jun 2014 03:30:02 -0700
> From: sreejithyes@gmail.com
> To: fop-users@xmlgraphics.apache.org
> Subject: Formatting a RtfTable using RTFLib
> 
> How to format a table (RtfTable) using RTFLib in java. Like setting padding,
> aligning, border, font...I couldn't find any examples. Can some body give
> some examples. 
> 
> Thanks in advance.
> 
> 
> 
> --
> View this message in context: http://apache-fop.1065347.n5.nabble.com/Formatting-a-RtfTable-using-RTFLib-tp40808.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>