Hi,

 I'm trying to print a text in a PDF. But the text is not getting wrapped.
Depending on the alignment I use, some portion of the text gets cut always.
I need to use PdfContentByte class because I need to write text at a
particular location. I'm attaching the resultant PDF produced as a
reference.

 The code is given below. Pls help me in fixing the issue. Any help will be
appreciated.

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

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfTextArray;
import com.lowagie.text.pdf.PdfWriter;

/**
* This example was written by Bruno Lowagie. It is part of the book 'iText
in
* Action' by Manning Publications.
* ISBN: 1932394796
* http://itext.ugent.be/itext-in-action/
* http://www.manning.com/lowagie/
*/

public class TextOperators {

   /**
    * Generates a PDF file showing the different text operators.
    *
    * @param args
    *            no arguments needed here
    */
   public static void main(String[] args) {
       System.out.println("Chapter 11: example TextOperators");
       System.out.println("-> Creates a PDF file demonstrating PDF's Text
State.");
       System.out.println("-> jars needed: iText.jar");
       System.out.println("-> file generated: text_operators.pdf");
       // step 1: creation of a document-object
       Document document = new Document();
       try {
           // step 2:
           // we create a writer
           PdfWriter writer = PdfWriter.getInstance(
           // that listens to the document
                   document,
                   // and directs a PDF-stream to a file
                   new FileOutputStream("text_operators.pdf"));
           // step 3: we open the document
           document.open();
           // step 4:
           String text =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+
           "I'm here to serve you in any way I can. ";

           PdfContentByte cb = writer.getDirectContent();
           BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                   BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
           bf=BaseFont.createFont("ShelleyScript.ttf", "Cp1252",
BaseFont.EMBEDDED);
           cb.beginText();
           cb.moveText(36, 806);
           cb.setFontAndSize(bf, 12);
           cb.setColorFill(Color.red);
           cb.moveTextWithLeading(0, -36);
           cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, 36, 806,
0);
           cb.newlineText();
           cb.endText();
       } catch (DocumentException de) {
           System.err.println(de.getMessage());
       } catch (IOException ioe) {
           System.err.println(ioe.getMessage());
       }

       // step 5: we close the document
       document.close();
   }
}


--
Regards,
Magi

Attachment: text_operators.pdf
Description: Adobe PDF document

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to