Hi,

I have a requirement which generates a PDF report in Java 


Requirements
-----------------
Page Size - Same dimensions as for Cut Sheet,  plus 1/2 left and right, 
(overall: 9.5 x 11; detached: 8.5 x 11).

10 characters per inch and 6 lines per inch


how can I meet the above requirements.



Please find attached code which I have tried and it is not working correct, 
Please check and guide me

 
Hanumanth
import java.io.ByteArrayOutputStream;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class PDFReport {

        public PdfPCell getCell(String chunkValue) throws BadElementException {
                Chunk chunk = new Chunk(chunkValue, FontFactory.getFont(
                                FontFactory.COURIER, 10, Font.NORMAL));
                PdfPCell cell = new PdfPCell(new Phrase(chunk));
                return cell;
        }

        public ByteArrayOutputStream generateReport() {

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                try {
                        Document document = new Document(PageSize.LETTER);
                        PdfWriter pdfWriter = PdfWriter.getInstance(document, 
baos);
                        pdfWriter.setViewerPreferences(PdfWriter.HideMenubar);
                        document.setMargins(10.8f, 10.8f, 12f, 12f);
                        document.open();

                        String displayData1 = 
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
                        String displayData2 = 
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";

                        PdfPTable pTable = new PdfPTable(1);
                        pTable.setWidthPercentage(100);
                        pTable.getDefaultCell().setFixedHeight(30.48f);
                        pTable.getDefaultCell().setHorizontalAlignment(
                                        Element.ALIGN_JUSTIFIED);
                        
pTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
                        pTable.getDefaultCell().setBorder(1);

                        for (int i = 0; i < 63; i++) {
                                pTable.addCell(getCell(displayData1));
                                pTable.addCell(getCell(displayData2));
                        }

                        document.add(pTable);

                        document.close();
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
                return baos;
        }
}
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to