diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java index c72aa9d..2a3b1ad 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/HtmlTypeHandler.java @@ -8,6 +8,7 @@ import org.fugerit.java.doc.base.config.DocTypeHandler; import org.fugerit.java.doc.base.config.DocTypeHandlerDefault; import org.fugerit.java.doc.base.model.DocBase; +import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler; import com.lowagie.text.Document; import com.lowagie.text.html.HtmlWriter; @@ -22,7 +23,7 @@ public class HtmlTypeHandler extends DocTypeHandlerDefault { public static final DocTypeHandler HANDLER = new HtmlTypeHandler(); public HtmlTypeHandler() { - super( ITextDocHandler.DOC_OUTPUT_HTML, ITextDocHandler.MODULE ); + super( OpenPpfDocHandler.DOC_OUTPUT_HTML, OpenPpfDocHandler.MODULE ); } @Override @@ -32,7 +33,7 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { Document document = new Document( ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); HtmlWriter.getInstance( document, baos ); - ITextDocHandler handler = new ITextDocHandler( document, ITextDocHandler.DOC_OUTPUT_HTML ); + OpenPpfDocHandler handler = new OpenPpfDocHandler( document, OpenPpfDocHandler.DOC_OUTPUT_HTML ); handler.handleDoc( docBase ); baos.writeTo( outputStream ); baos.close(); diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java index 2cf9981..294f6a8 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfTypeHandler.java @@ -8,6 +8,7 @@ import org.fugerit.java.doc.base.config.DocTypeHandler; import org.fugerit.java.doc.base.config.DocTypeHandlerDefault; import org.fugerit.java.doc.base.model.DocBase; +import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler; import com.lowagie.text.Document; import com.lowagie.text.PageSize; @@ -23,7 +24,7 @@ public class PdfTypeHandler extends DocTypeHandlerDefault { public static DocTypeHandler HANDLER = new PdfTypeHandler(); public PdfTypeHandler() { - super( ITextDocHandler.DOC_OUTPUT_PDF, ITextDocHandler.MODULE ); + super( OpenPpfDocHandler.DOC_OUTPUT_PDF, OpenPpfDocHandler.MODULE ); } @Override @@ -40,7 +41,7 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { // create pdf writer PdfWriter pdfWriter = PdfWriter.getInstance( document, baos ); // create doc handler - ITextDocHandler handler = new ITextDocHandler( document, pdfWriter ); + OpenPpfDocHandler handler = new OpenPpfDocHandler( document, pdfWriter ); if ( "true".equalsIgnoreCase( docBase.getInfo().getProperty( "set-total-page" ) ) ) { handler.handleDoc( docBase ); int totalPageCount = pdfWriter.getCurrentPageNumber()-1; @@ -50,7 +51,7 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { Integer.parseInt( margins[3] ) ); baos = new ByteArrayOutputStream(); pdfWriter = PdfWriter.getInstance( document, baos ); - handler = new ITextDocHandler(document, pdfWriter, totalPageCount ); + handler = new OpenPpfDocHandler(document, pdfWriter, totalPageCount ); } handler.handleDoc( docBase ); baos.writeTo( outputStream ); diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java index 63cfbef..7549329 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/RtfTypeHandler.java @@ -8,6 +8,7 @@ import org.fugerit.java.doc.base.config.DocTypeHandler; import org.fugerit.java.doc.base.config.DocTypeHandlerDefault; import org.fugerit.java.doc.base.model.DocBase; +import org.fugerit.java.doc.mod.openpdf.helpers.OpenPpfDocHandler; import com.lowagie.text.Document; import com.lowagie.text.PageSize; @@ -23,7 +24,7 @@ public class RtfTypeHandler extends DocTypeHandlerDefault { public static final DocTypeHandler HANDLER = new RtfTypeHandler(); public RtfTypeHandler() { - super( ITextDocHandler.DOC_OUTPUT_RTF, ITextDocHandler.MODULE ); + super( OpenPpfDocHandler.DOC_OUTPUT_RTF, OpenPpfDocHandler.MODULE ); } @Override @@ -37,7 +38,7 @@ public void handle(DocInput docInput, DocOutput docOutput) throws Exception { Integer.parseInt( margins[3] ) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); RtfWriter2 rtfWriter2 = RtfWriter2.getInstance( document, baos ); - ITextDocHandler handler = new ITextDocHandler( document, rtfWriter2 ); + OpenPpfDocHandler handler = new OpenPpfDocHandler( document, rtfWriter2 ); handler.handleDoc( docBase ); baos.writeTo( outputStream ); baos.close(); diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPdfDocTableHelper.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPdfDocTableHelper.java new file mode 100644 index 0000000..23fe583 --- /dev/null +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPdfDocTableHelper.java @@ -0,0 +1,187 @@ +package org.fugerit.java.doc.mod.openpdf.helpers; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; + +import org.fugerit.java.core.log.LogFacade; +import org.fugerit.java.doc.base.model.DocBarcode; +import org.fugerit.java.doc.base.model.DocBorders; +import org.fugerit.java.doc.base.model.DocCell; +import org.fugerit.java.doc.base.model.DocElement; +import org.fugerit.java.doc.base.model.DocImage; +import org.fugerit.java.doc.base.model.DocPara; +import org.fugerit.java.doc.base.model.DocPhrase; +import org.fugerit.java.doc.base.model.DocRow; +import org.fugerit.java.doc.base.model.DocTable; +import org.fugerit.java.doc.base.xml.DocModelUtils; + +import com.lowagie.text.Cell; +import com.lowagie.text.Chunk; +import com.lowagie.text.Element; +import com.lowagie.text.Font; +import com.lowagie.text.Paragraph; +import com.lowagie.text.Table; +import com.lowagie.text.alignment.HorizontalAlignment; +import com.lowagie.text.alignment.VerticalAlignment; + +public class OpenPdfDocTableHelper { + + private static void handleBolders( DocCell docCell, Cell cell ) { + DocBorders docBorders = docCell.getDocBorders(); + if ( docBorders != null ) { + if ( docBorders.getBorderColorBottom() != null ) { + cell.setBorderColorBottom( DocModelUtils.parseHtmlColor( docBorders.getBorderColorBottom() ) ); + } + if ( docBorders.getBorderColorTop() != null ) { + cell.setBorderColorTop( DocModelUtils.parseHtmlColor( docBorders.getBorderColorTop() ) ); + } + if ( docBorders.getBorderColorLeft() != null ) { + cell.setBorderColorLeft( DocModelUtils.parseHtmlColor( docBorders.getBorderColorLeft() ) ); + } + if ( docBorders.getBorderColorRight() != null ) { + cell.setBorderColorRight( DocModelUtils.parseHtmlColor( docBorders.getBorderColorRight() ) ); + } + if ( docBorders.getBorderWidthBottom() != -1 ) { + cell.setBorderWidthBottom( docBorders.getBorderWidthBottom() ); + } + if ( docBorders.getBorderWidthTop() != -1 ) { + cell.setBorderWidthTop( docBorders.getBorderWidthTop() ); + } + if ( docBorders.getBorderWidthLeft() != -1 ) { + cell.setBorderWidthLeft( docBorders.getBorderWidthLeft() ); + } + if ( docBorders.getBorderWidthRight() != -1 ) { + cell.setBorderWidthRight( docBorders.getBorderWidthRight() ); + } + } + } + + private static void handleAligns( DocCell docCell, Cell cell ) { + if ( docCell.getAlign() != DocPara.ALIGN_UNSET ) { + Optional ha = HorizontalAlignment.of( docCell.getAlign() ); + if ( ha.isPresent() ) { + cell.setHorizontalAlignment( ha.get() ); + } + } + if ( docCell.getValign() != DocPara.ALIGN_UNSET ) { + Optional va = VerticalAlignment.of( docCell.getAlign() ); + if ( va.isPresent() ) { + cell.setVerticalAlignment( va.get() ); + } + } + } + + private static List handleContent( Table table, CellParent cellParent, DocCell docCell, Cell cell, OpenPdfHelper docHelper ) throws Exception { + List fontList = new ArrayList<>(); + Iterator itCurrent = docCell.docElements(); + while ( itCurrent.hasNext() ) { + DocElement docElement = (DocElement) itCurrent.next(); + if ( docElement instanceof DocPara ) { + DocPara docPara = (DocPara)docElement; + OpenPpfDocHandler.setStyle( docCell , docPara ); + Paragraph paragraph = OpenPpfDocHandler.createPara( docPara, docHelper, fontList ); + cellParent.add( paragraph ); + } else if ( docElement instanceof DocPhrase ) { + DocPhrase docPhrase = (DocPhrase)docElement; + //setStyle( docCell , docPara ); + cellParent.add( OpenPpfDocHandler.createPhrase( docPhrase, docHelper, fontList ) ); + } else if ( docElement instanceof DocTable ) { + LogFacade.getLog().debug( "nested table" ); + table.insertTable( createTable( (DocTable)docElement, docHelper ) ); + } else if ( docElement instanceof DocImage ) { + LogFacade.getLog().debug( "cell DocImage : "+docElement ); + cellParent.add( OpenPpfDocHandler.createImage( (DocImage)docElement ) ); + } else if ( docElement instanceof DocBarcode ) { + LogFacade.getLog().info( "cell DocBarcode : "+docElement ); + cellParent.add( OpenPpfDocHandler.createBarcode( (DocBarcode)docElement, docHelper ) ); + } + } + return fontList; + } + + private static boolean handleCell( Table table, DocCell docCell, boolean startHeader, DocTable docTable, OpenPdfHelper docHelper ) throws Exception { + OpenPpfDocHandler.setStyle( docTable, docCell ); + Cell cell = new Cell(); + if ( docCell.isHeader() ) { + cell.setHeader( true ); + startHeader = true; + } else { + if ( startHeader ) { + startHeader = false; + table.endHeaders(); + } + } + cell.setColspan( docCell.getCSpan() ); + cell.setRowspan( docCell.getRSpan() ); + + handleBolders(docCell, cell); + + if ( docCell.getBackColor() != null ) { + cell.setBackgroundColor( DocModelUtils.parseHtmlColor( docCell.getBackColor() ) ); + } + + handleAligns(docCell, cell); + + CellParent cellParent = new CellParent( cell ); + + List fontList = handleContent(table, cellParent, docCell, cell, docHelper); + + table.addCell( cell ); + List listChunk = cell.getChunks(); + if ( listChunk.size() == fontList.size() ) { + for ( int k=0; k itRow = docTable.docElements(); + while ( itRow.hasNext() ) { + DocRow docRow = (DocRow)itRow.next(); + Iterator itCell = docRow.docElements(); + while ( itCell.hasNext() ) { + DocCell docCell = (DocCell)itCell.next(); + startHeader = handleCell(table, docCell, startHeader, docTable, docHelper); + } + } + + return table; + } + + +} diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/ITextHelper.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPdfHelper.java similarity index 90% rename from src/main/java/org/fugerit/java/doc/mod/openpdf/ITextHelper.java rename to src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPdfHelper.java index 12bd789..ea80aec 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/ITextHelper.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPdfHelper.java @@ -1,12 +1,12 @@ -package org.fugerit.java.doc.mod.openpdf; +package org.fugerit.java.doc.mod.openpdf.helpers; import java.util.Properties; import com.lowagie.text.pdf.PdfWriter; -public class ITextHelper { +public class OpenPdfHelper { - public ITextHelper() { + public OpenPdfHelper() { this.params = new Properties(); } diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/ITextDocHandler.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPpfDocHandler.java similarity index 70% rename from src/main/java/org/fugerit/java/doc/mod/openpdf/ITextDocHandler.java rename to src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPpfDocHandler.java index f8d1977..ce7b0fb 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/ITextDocHandler.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/OpenPpfDocHandler.java @@ -1,4 +1,4 @@ -package org.fugerit.java.doc.mod.openpdf; +package org.fugerit.java.doc.mod.openpdf.helpers; import java.awt.Color; @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Optional; import java.util.Properties; import org.fugerit.java.core.lang.helpers.StringUtils; @@ -16,8 +15,6 @@ import org.fugerit.java.doc.base.helper.SourceResolverHelper; import org.fugerit.java.doc.base.model.DocBarcode; import org.fugerit.java.doc.base.model.DocBase; -import org.fugerit.java.doc.base.model.DocBorders; -import org.fugerit.java.doc.base.model.DocCell; import org.fugerit.java.doc.base.model.DocElement; import org.fugerit.java.doc.base.model.DocFooter; import org.fugerit.java.doc.base.model.DocHeader; @@ -27,15 +24,11 @@ import org.fugerit.java.doc.base.model.DocPageBreak; import org.fugerit.java.doc.base.model.DocPara; import org.fugerit.java.doc.base.model.DocPhrase; -import org.fugerit.java.doc.base.model.DocRow; import org.fugerit.java.doc.base.model.DocStyle; import org.fugerit.java.doc.base.model.DocTable; import org.fugerit.java.doc.base.xml.DocModelUtils; -import org.fugerit.java.doc.mod.openpdf.helpers.CellParent; -import org.fugerit.java.doc.mod.openpdf.helpers.DocumentParent; import com.lowagie.text.Anchor; -import com.lowagie.text.Cell; import com.lowagie.text.Chunk; import com.lowagie.text.Document; import com.lowagie.text.Element; @@ -46,9 +39,6 @@ import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; -import com.lowagie.text.Table; -import com.lowagie.text.alignment.HorizontalAlignment; -import com.lowagie.text.alignment.VerticalAlignment; import com.lowagie.text.html.HtmlTags; import com.lowagie.text.pdf.Barcode; import com.lowagie.text.pdf.Barcode128; @@ -62,7 +52,7 @@ import com.lowagie.text.rtf.RtfWriter2; import com.lowagie.text.rtf.headerfooter.RtfHeaderFooter; -public class ITextDocHandler { +public class OpenPpfDocHandler { private static final ParamFinder PARAM_FINDER = ParamFinder.newFinder(); @@ -89,7 +79,7 @@ public static BaseFont findFont( String name ) { return res; } - private static void setStyle( DocStyle parent, DocStyle current ) { + protected static void setStyle( DocStyle parent, DocStyle current ) { if ( current.getBackColor() == null ) { current.setBackColor( parent.getBackColor() ); } @@ -120,22 +110,22 @@ private static void setStyle( DocStyle parent, DocStyle current ) { private int totalPageCount; - public ITextDocHandler( Document document, RtfWriter2 rtfWriter2 ) { + public OpenPpfDocHandler( Document document, RtfWriter2 rtfWriter2 ) { this( document, DOC_OUTPUT_RTF ); //this.rtfWriter2 = rtfWriter2; } - public ITextDocHandler( Document document, PdfWriter pdfWriter ) { + public OpenPpfDocHandler( Document document, PdfWriter pdfWriter ) { this(document, pdfWriter, -1); } - public ITextDocHandler( Document document, PdfWriter pdfWriter, int totalPageCount ) { + public OpenPpfDocHandler( Document document, PdfWriter pdfWriter, int totalPageCount ) { this( document, DOC_OUTPUT_PDF ); this.pdfWriter = pdfWriter; this.totalPageCount = totalPageCount; } - public ITextDocHandler( Document document, String docType ) { + public OpenPpfDocHandler( Document document, String docType ) { this.document = document; this.docType = docType; } @@ -176,7 +166,7 @@ public static String createText( Properties params, String text ) { return PARAM_FINDER.substitute( text , params ); } - protected static Chunk createChunk( DocPhrase docPhrase, ITextHelper docHelper ) throws Exception { + protected static Chunk createChunk( DocPhrase docPhrase, OpenPdfHelper docHelper ) throws Exception { String text = createText( docHelper.getParams(), docPhrase.getText() ); int style = docPhrase.getStyle(); String fontName = docPhrase.getFontName(); @@ -185,7 +175,7 @@ protected static Chunk createChunk( DocPhrase docPhrase, ITextHelper docHelper ) return p; } - protected static Phrase createPhrase( DocPhrase docPhrase, ITextHelper docHelper, List fontMap ) throws Exception { + protected static Phrase createPhrase( DocPhrase docPhrase, OpenPdfHelper docHelper, List fontMap ) throws Exception { String text = createText( docHelper.getParams(), docPhrase.getText() ); int style = docPhrase.getStyle(); String fontName = docPhrase.getFontName(); @@ -208,15 +198,15 @@ protected static Phrase createPhrase( DocPhrase docPhrase, ITextHelper docHelper return p; } - protected static Phrase createPhrase( DocPhrase docPhrase, ITextHelper docHelper ) throws Exception { + protected static Phrase createPhrase( DocPhrase docPhrase, OpenPdfHelper docHelper ) throws Exception { return createPhrase(docPhrase, docHelper, null); } - protected static Paragraph createPara( DocPara docPara, ITextHelper docHelper ) throws Exception { + protected static Paragraph createPara( DocPara docPara, OpenPdfHelper docHelper ) throws Exception { return createPara(docPara, docHelper, null); } - protected static Paragraph createPara( DocPara docPara, ITextHelper docHelper, List fontMap ) throws Exception { + protected static Paragraph createPara( DocPara docPara, OpenPdfHelper docHelper, List fontMap ) throws Exception { int style = docPara.getStyle(); String text = createText( docHelper.getParams(), docPara.getText() ); // if ( DOC_OUTPUT_HTML.equals( this.docType ) ) { @@ -258,139 +248,7 @@ protected static Paragraph createPara( DocPara docPara, ITextHelper docHelper, L return p; } - protected static Table createTable( DocTable docTable, ITextHelper docHelper ) throws Exception { - - boolean startHeader = false; - Table table = new Table( docTable.getColumns() ); - table.setBorderWidth(0); - table.setWidth( docTable.getWidth() ); - table.setBorderColor( Color.black ); - table.setPadding( docTable.getPadding() ); - table.setSpacing( docTable.getSpacing() ); - table.setCellsFitPage( true ); - - - if ( docTable.getSpaceBefore() != null ) { - table.setSpacing( docTable.getSpaceBefore().floatValue() ); - } - if ( docTable.getSpaceAfter() != null ) { - table.setSpacing( docTable.getSpaceAfter().floatValue() ); - } - - int[] cw = docTable.getColWithds(); - if ( cw != null ) { - float[] w = new float[ cw.length ]; - for ( int k=0; k itRow = docTable.docElements(); - while ( itRow.hasNext() ) { - DocRow docRow = (DocRow)itRow.next(); - Iterator itCell = docRow.docElements(); - while ( itCell.hasNext() ) { - DocCell docCell = (DocCell)itCell.next(); - setStyle( docTable, docCell ); - Cell cell = new Cell(); - if ( docCell.isHeader() ) { - cell.setHeader( true ); - startHeader = true; - } else { - if ( startHeader ) { - startHeader = false; - table.endHeaders(); - } - } - cell.setColspan( docCell.getCSpan() ); - cell.setRowspan( docCell.getRSpan() ); - DocBorders docBorders = docCell.getDocBorders(); - if ( docBorders != null ) { - if ( docBorders.getBorderColorBottom() != null ) { - cell.setBorderColorBottom( DocModelUtils.parseHtmlColor( docBorders.getBorderColorBottom() ) ); - } - if ( docBorders.getBorderColorTop() != null ) { - cell.setBorderColorTop( DocModelUtils.parseHtmlColor( docBorders.getBorderColorTop() ) ); - } - if ( docBorders.getBorderColorLeft() != null ) { - cell.setBorderColorLeft( DocModelUtils.parseHtmlColor( docBorders.getBorderColorLeft() ) ); - } - if ( docBorders.getBorderColorRight() != null ) { - cell.setBorderColorRight( DocModelUtils.parseHtmlColor( docBorders.getBorderColorRight() ) ); - } - if ( docBorders.getBorderWidthBottom() != -1 ) { - cell.setBorderWidthBottom( docBorders.getBorderWidthBottom() ); - } - if ( docBorders.getBorderWidthTop() != -1 ) { - cell.setBorderWidthTop( docBorders.getBorderWidthTop() ); - } - if ( docBorders.getBorderWidthLeft() != -1 ) { - cell.setBorderWidthLeft( docBorders.getBorderWidthLeft() ); - } - if ( docBorders.getBorderWidthRight() != -1 ) { - cell.setBorderWidthRight( docBorders.getBorderWidthRight() ); - } - } - if ( docCell.getBackColor() != null ) { - cell.setBackgroundColor( DocModelUtils.parseHtmlColor( docCell.getBackColor() ) ); - } - if ( docCell.getAlign() != DocPara.ALIGN_UNSET ) { - Optional ha = HorizontalAlignment.of( docCell.getAlign() ); - if ( ha.isPresent() ) { - cell.setHorizontalAlignment( ha.get() ); - } - } - if ( docCell.getValign() != DocPara.ALIGN_UNSET ) { - Optional va = VerticalAlignment.of( docCell.getAlign() ); - if ( va.isPresent() ) { - cell.setVerticalAlignment( va.get() ); - } - } - CellParent cellParent = new CellParent( cell ); - Iterator itCurrent = docCell.docElements(); - List fontList = new ArrayList<>(); - while ( itCurrent.hasNext() ) { - DocElement docElement = (DocElement) itCurrent.next(); - if ( docElement instanceof DocPara ) { - DocPara docPara = (DocPara)docElement; - setStyle( docCell , docPara ); - Paragraph paragraph = createPara( docPara, docHelper, fontList ); - cellParent.add( paragraph ); - } else if ( docElement instanceof DocPhrase ) { - DocPhrase docPhrase = (DocPhrase)docElement; - //setStyle( docCell , docPara ); - cellParent.add( createPhrase( docPhrase, docHelper, fontList ) ); - } else if ( docElement instanceof DocTable ) { - LogFacade.getLog().debug( "nested table" ); - table.insertTable( createTable( (DocTable)docElement, docHelper ) ); - } else if ( docElement instanceof DocImage ) { - LogFacade.getLog().debug( "cell DocImage : "+docElement ); - cellParent.add( createImage( (DocImage)docElement ) ); - } else if ( docElement instanceof DocBarcode ) { - LogFacade.getLog().info( "cell DocBarcode : "+docElement ); - cellParent.add( createBarcode( (DocBarcode)docElement, docHelper ) ); - } - } - table.addCell( cell ); - List listChunk = cell.getChunks(); - if ( listChunk.size() == fontList.size() ) { - for ( int k=0; k list = new ArrayList<>(); Iterator itDoc = docHeaderFooter.docElements(); while ( itDoc.hasNext() ) { @@ -427,11 +285,11 @@ private static RtfHeaderFooter createRtfHeaderFooter( DocHeaderFooter docHeaderF return rtfHeaderFooter; } - public static Font createFont( String fontName, int fontSize, int fontStyle, ITextHelper docHelper, String color ) throws Exception { + public static Font createFont( String fontName, int fontSize, int fontStyle, OpenPdfHelper docHelper, String color ) throws Exception { return createFont(fontName, fontName, fontSize, fontStyle, docHelper, color); } - private static Font createFont( String fontName, String fontPath, int fontSize, int fontStyle, ITextHelper docHelper, String color ) throws Exception { + private static Font createFont( String fontName, String fontPath, int fontSize, int fontStyle, OpenPdfHelper docHelper, String color ) throws Exception { Font font = null; int size = fontSize; int style = Font.NORMAL; @@ -488,7 +346,7 @@ public void handleDoc(DocBase docBase) throws Exception { String defaultFontName = info.getProperty( DOC_DEFAULT_FONT_NAME, "helvetica" ); String defaultFontSize = info.getProperty( DOC_DEFAULT_FONT_SIZE, "10" ); String defaultFontStyle = info.getProperty( DOC_DEFAULT_FONT_STYLE, "normal" ); - ITextHelper docHelper = new ITextHelper(); + OpenPdfHelper docHelper = new OpenPdfHelper(); if ( this.pdfWriter != null ) { docHelper.setPdfWriter( this.pdfWriter ); @@ -584,14 +442,14 @@ public void handleDoc(DocBase docBase) throws Exception { this.document.close(); } - public static void handleElements( Document document, Iterator itDoc, ITextHelper docHelper ) throws Exception { + public static void handleElements( Document document, Iterator itDoc, OpenPdfHelper docHelper ) throws Exception { while ( itDoc.hasNext() ) { DocElement docElement = (DocElement)itDoc.next(); getElement(document, docElement, true, docHelper ); } } - public static Element getElement( Document document, DocElement docElement, boolean addElement, ITextHelper docHelper ) throws Exception { + public static Element getElement( Document document, DocElement docElement, boolean addElement, OpenPdfHelper docHelper ) throws Exception { Element result = null; DocumentParent documentParent = new DocumentParent( document ); if ( docElement instanceof DocPhrase ) { @@ -605,7 +463,7 @@ public static Element getElement( Document document, DocElement docElement, bool documentParent.add( result ); } } else if ( docElement instanceof DocTable ) { - result = createTable( (DocTable)docElement, docHelper ); + result = OpenPdfDocTableHelper.createTable( (DocTable)docElement, docHelper ); if ( addElement ) { document.add( result ); } @@ -620,7 +478,7 @@ public static Element getElement( Document document, DocElement docElement, bool return result; } - private HeaderFooter createHeaderFooter( DocHeaderFooter container, int align, ITextHelper docHelper ) throws Exception { + private HeaderFooter createHeaderFooter( DocHeaderFooter container, int align, OpenPdfHelper docHelper ) throws Exception { Iterator it = container.docElements(); Phrase phrase = new Phrase(); float leading = (float)-1.0; diff --git a/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfHelper.java b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/PdfHelper.java similarity index 93% rename from src/main/java/org/fugerit/java/doc/mod/openpdf/PdfHelper.java rename to src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/PdfHelper.java index 7eb22b1..94646bb 100644 --- a/src/main/java/org/fugerit/java/doc/mod/openpdf/PdfHelper.java +++ b/src/main/java/org/fugerit/java/doc/mod/openpdf/helpers/PdfHelper.java @@ -1,4 +1,4 @@ -package org.fugerit.java.doc.mod.openpdf; +package org.fugerit.java.doc.mod.openpdf.helpers; import java.io.IOException; import java.util.Iterator; @@ -27,7 +27,7 @@ */ public class PdfHelper extends PdfPageEventHelper { - public PdfHelper( ITextHelper docHelper ) { + public PdfHelper( OpenPdfHelper docHelper ) { this.docHelper = docHelper; this.docHeader = null; this.docFooter = null; @@ -38,7 +38,7 @@ public PdfHelper( ITextHelper docHelper ) { private float footerTextSize = 8f; private int pageNumberAlignment = Element.ALIGN_CENTER; - private ITextHelper docHelper; + private OpenPdfHelper docHelper; private int currentPageNumber; @@ -48,10 +48,10 @@ public PdfHelper( ITextHelper docHelper ) { public void onStartPage(PdfWriter writer, Document document) { this.currentPageNumber = writer.getPageNumber(); - this.docHelper.getParams().setProperty( ITextDocHandler.PARAM_PAGE_CURRENT , String.valueOf( writer.getPageNumber() ) ); + this.docHelper.getParams().setProperty( OpenPpfDocHandler.PARAM_PAGE_CURRENT , String.valueOf( writer.getPageNumber() ) ); if ( this.getDocHeader() != null ) { try { - ITextDocHandler.handleElements( document, this.getDocHeader().docElements(), docHelper ); + OpenPpfDocHandler.handleElements( document, this.getDocHeader().docElements(), docHelper ); } catch (Exception e) { LogFacade.getLog().error( "ITextDocHandler - PdfHelper.onStartPage : "+e ); throw new RuntimeException( e ); @@ -86,7 +86,7 @@ public void onEndPage(PdfWriter writer, Document document) { DocElement current = (DocElement)itElements.next(); if ( current instanceof DocPara ) { DocPara para = (DocPara) current;; - String text = ITextDocHandler.createText( docHelper.getParams(), para.getText() ); + String text = OpenPpfDocHandler.createText( docHelper.getParams(), para.getText() ); float textSize = baseFont.getWidthPoint(text, footerTextSize); float textBase = document.bottom() - totalOffset; int rowOffset = 10;