Sorry, example below which my explain my babblings - code below and attached
aswell as the image

http://www.nabble.com/file/p18214493/ImagesAlignment.java
ImagesAlignment.java 

http://www.nabble.com/file/p18214493/otsoe.jpg otsoe.jpg 

import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.*;

import com.lowagie.text.*;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
import com.solidstategroup.nhs.pdf.PDFUtils;

/**
 * Testing Image alignment.
 */
public class ImagesAlignment {

        /**
         * Generates a PDF with Images that are aligned.
         * @param args no arguments needed
         */
        public static void main(java.lang.String[] args) {
                System.out.println("Image alignment");
        // step 1: creation of a document-object
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("c:\\imagesAlignment.pdf"));
            writer.setFullCompression();
            writer.setLinearPageMode();

            // step 3: we open the document
            document.open();

            // normal paragraph
            Paragraph p = new Paragraph("Lorem ipsum dolor sit amet,
constetue adipiscing elit. neque lectus. Lorem ipsum dolor sit amet,
constetue adipiscing elit. Nam volutpat, ligula volutpat adipiscing
semper.");

            // image
            Image jpeg = Image.getInstance("c:\\otsoe.jpg");
            jpeg.setAlignment(Image.LEFT | Image.TEXTWRAP);

            float wp = PDFUtils.lengthParse(Integer.toString(320),
(int)jpeg.getWidth());
            float lp = PDFUtils.lengthParse(Integer.toString(240),
(int)jpeg.getHeight());

            if (wp > 0 && lp > 0) {
                jpeg.scalePercent(wp > lp ? lp : wp);
            } else if (wp > 0) {
                jpeg.scalePercent(wp);
            } else if (lp > 0) {
                jpeg.scalePercent(lp);
            }

            jpeg.setWidthPercentage(0);

            // table
            Paragraph header = new Paragraph("Test Content");
            header.setSpacingBefore(5f);
            header.setSpacingAfter(0);

            PdfPTable table = new PdfPTable(1);
            table.setTotalWidth(document.getPageSize().getWidth() -
(document.leftMargin() + document.rightMargin()));
            table.setLockedWidth(true);
            table.setSpacingBefore(5f);
            table.setSpacingAfter(15f);

            PdfPCell cell = new PdfPCell(header);
            cell.setPadding(0);
            cell.setPaddingTop(5f);
            cell.setBorder(0);
            cell.setBorderWidthTop(5f);
            cell.setBorderColorTop(new Color(229, 229, 229));

            table.addCell(cell);

            // table normal going full width of the page
            document.add(table);

            // image set to have text wrap but table with full width is also
trying to wrap
            document.add(jpeg);
            document.add(p);
            document.add(table);

        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        // step 5: we close the document
        document.close();
        }
}
-- 
View this message in context: 
http://www.nabble.com/Image-text-wrap-%2B-PdfPTable-problem-tp18197955p18214493.html
Sent from the iText - General mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Do you like iText?
Buy the iText book: http://www.1t3xt.com/docs/book.php
Or leave a tip: https://tipit.to/itexttipjar

Reply via email to