I have seen it successfully implemented a line at a
time with Paragraphs by two different coworkers.  This
seemed very similar to what Ian was doing, though, so
I reread the FAQ.  It may not intend to say to use the
entire document in a single Paragraph but I have
reread it and I still think that interpretation of the
FAQ entry is valid.

-Matt

--- Paulo Soares <[EMAIL PROTECTED]> wrote:
> I hope it doesn't, it would go at snail pace. This,
> using
> document.add(Paragraph), ColumnText does not have
> that problem.
> 
> Best Regards,
> Paulo Soares
> 
> 
> ----- Original Message -----
> From: "Matt Benson" <[EMAIL PROTECTED]>
> To: " Alex, Ian" <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Thursday, May 29, 2003 19:13
> Subject: Re: [iText-questions] Question about line
> height for paging
> 
> 
> > There is a FAQ entry on this that appears to
> advocate
> > putting the entire contents of the file into a
> String
> > and adding that to the document in a single
> Paragraph.
> >
> >
>
http://www.lowagie.com/iText/faq.html#preformattedtext
> >
> > -Matt
> >
> > --- " Alex, Ian" <[EMAIL PROTECTED]> wrote:
> > > I am having a problem with writing a
> Unix-created
> > > document to PDF using
> > > iText.   Unix output files don't use any fonts
> and
> > > there is minimal spacing
> > > between lines (using the lpr output).   My
> algorithm
> > > was to read each line
> > > in from the original file and then write it to
> PDF
> > > landscape document with
> > > the appropriate font (Courier) to preserve the
> > > alignment, just using code
> > > like this:
> > >
> > > String line;
> > > PdfWriter.getInstance(document, new
> > > FileOutputStream(PDFname));
> > > BaseFont bf1 = BaseFont.createFont("Courier",
> > > BaseFont.WINANSI,
> > > BaseFont.EMBEDDED);
> > > bf1.setDirectTextToByte(true);
> > > Font font = new Font(bf1, (float)10,
> Font.NORMAL);
> > > Document document = new
> > > Document(PageSize.A4.rotate(), 0, 0, 0, 0);
> > > document.open();
> > > document.setLinesRequired(56);
> > > BufferedReader reader = new BufferedReader(new
> > > FileReader(inFile));
> > > while ((line = reader.readLine()) != null) {
> > >    document.add(new Paragraph(line,font));
> > > }
> > >
> > > This didn't work since  each *line* occupied a
> large
> > > height (twice the size
> > > as the text height regardless of font).  I
> wanted to
> > > adjust this but
> > > couldn't.   I saw a class in the API called
> > > com.lowagie.text.pdf.PdfLine
> > > that has a height() method but no "get" methods
> to
> > > adjust the height.
> > > Furthermore, there is no binding between PdfLine
> > > objects and the Document
> > > class.
> > >
> > > Next I tried mapping each page to a table so
> that
> > > all the cells would "fit".
> > > The number of lines in each page of the unix
> file
> > > was 56.    My code for
> > > this looked something like:
> > >
> > > String line;
> > > cnt=1;
> > > Document document = new
> > > Document(PageSize.A4.rotate(), 0, 0, 0, 0);
> > > document.open();
> > > BufferedReader reader = new BufferedReader(new
> > > FileReader(inFile));
> > > Table datatable;
> > > datatable = new Table(1);
> > > datatable.setWidth(160);
> > > datatable.setDefaultCellBorderWidth(0);
> > > atatable.setDefaultHorizontalAlignment(0);
> > > datatable.setDefaultRowspan(1);
> > > datatable.setSpaceBetweenCells(0);
> > > datatable.setBorderWidth(0);
> > > datatable.setCellsFitPage(true);
> > > while ((line = reader.readLine()) != null) {
> > >     BaseFont bf1 =
> BaseFont.createFont("Courier",
> > > BaseFont.WINANSI,
> > > BaseFont.EMBEDDED);
> > >     bf1.setDirectTextToByte(true);
> > >     cell = new Cell(new
> Phrase(padStringWidth(line,
> > > 132), new Font(bf1, 10,
> > > Font.COURIER)));
> > >
> > >
> cell.setHorizontalAlignment(Element.ALIGN_CENTER);
> > >    
> cell.setVerticalAlignment(Element.ALIGN_TOP);
> > >     cell.setColspan(1);
> > >     cell.setRowspan(1);
> > >     cell.setNoWrap(true);
> > >    // cell.setBorder(Rectangle.NO_BORDER);
> > >     cell.setBorderColor(java.awt.Color.gray);
> > >     datatable.addCell(cell);
> > >     if (cnt == 56) {
> > >        document.add(datatable);
> > >        document.newPage();
> > >        datatable = new Table(1);
> > >        datatable.setWidth(160);
> > >        datatable.setDefaultCellBorderWidth(0);
> > >       
> datatable.setDefaultHorizontalAlignment(0);
> > >        datatable.setDefaultRowspan(1);
> > >        datatable.setBorderWidth(0);
> > >        datatable.setSpaceBetweenCells(0);
> > >        datatable.setCellsFitPage(true);
> > >        cnt=0;
> > >      }
> > >      cnt++;
> > > }
> > >
> > > Please note that I used
> > > cell.setBorderColor(java.awt.Color.gray) in
> order to
> > > display the cell boundaries.   In experimenting
> with
> > > different font sizes, I
> > > noted that just as was the case with just lines,
> the
> > > text height only
> > > occupied half the cell (the cell size increased
> > > proportionally along with
> > > the font - just as with lines).  I used various
> > > suggestions I saw previously
> > > such as calling datatable.setBorderWidth(0),
> > > datatable.setSpaceBetweenCells(0)
> > > datatable.setCellsFitPage(true) and none
> > > of these worked.
> > >
> > > The most promising suggestion I saw was from
> > >
> >
>
http://article.gmane.org/gmane.comp.java.lib.itext.general/1225/match=li
> > ne+h
> > > eight which suggested using the height method of
> the
> > > Cell class (inherited
> > > from Rectangle).   height() is a "get" method so
> I
> > > instead thought of
> > > working with the setBottom() & setTop() methods
> > > (inherited by Cell from
> > > Rectangle).  It compiled OK, but I got the
> run-time
> > > error:
> > >
> > > java.lang.UnsupportedOperationException:
> Dimensions
> > > of a Cell are attributed
> > > aut
> > > omagically. See the FAQ.
> > >         at
> com.lowagie.text.Cell.setBottom(Unknown
> > > Source)
> > >         at TestPDF.putPDF(TestPDF.java:158)
> > >         at TestPDF.run(TestPDF.java:28)
> > >         at TestPDF.main(TestPDF.java:17)
> > >
> > > Could you give me some suggestions as to how to
> > > adjust my application so
> > > that I can reduce the height of a line (or cell)
> > > holding text.
> > >
> > > Thanks for your attention.
> > >
> > >
> > >
> > >
> > >
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to