Quantcast

problems with table and imported page

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

problems with table and imported page

Kevin Russell-2
After working on this far too many hours, I was hoping someone could
help with the following code.  I have no problems getting an output of
pages with the text and the imported pdf.  However, when I add the
table, all I get is one page of the pdf - no text or table.

Your help is greatly appreciated,
Kevin

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.html.*;
import com.lowagie.text.pdf.*;
import java.sql.*;
import java.text.*;
import java.util.*;

public class PrintFireLossReports {
    public void printFireLossReports( java.util.List claims  ){
        Document fireLossReport = new Document(PageSize.LETTER);
        java.util.Date today = new java.util.Date();
        SimpleDateFormat todayFormat = new SimpleDateFormat(
"MMddyyyyHHmmss" );
        SimpleDateFormat df = new SimpleDateFormat(  "MM/dd/yyyy" );
        String todayString = todayFormat.format( today );
        String outputReport = "c:/lossReports" + todayString + ".pdf";

        Iterator it = claims.iterator();
        Claim claim = new Claim();
        Policy policy = new Policy();
        Item item = new Item();
         
        try {
            FileOutputStream outputPdf = new FileOutputStream( outputReport );
            PdfWriter writer = PdfWriter.getInstance( fireLossReport,
outputPdf );
            PdfReader reader = new PdfReader("../loss_report.pdf");
            // Open the document and add some text to it.
            fireLossReport.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfImportedPage page1 = writer.getImportedPage(reader, 1);
            PolicyLookup policyLookup = new PolicyLookup();
           
            while( it.hasNext() ) {
               
                claim = (Claim) it.next();
                policy = policyLookup.getPolicy( claim.getPolicyNumber() );
                Iterator itemIt = policy.getPolicyItems().iterator();
               
                cb.addTemplate(page1, 0, 0);
                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Font font = new Font(bf, 11, Font.NORMAL);
               
                Phrase details = new Phrase( 0, claim.getClaimDetails());
                ColumnText ct = new ColumnText(cb);
                ct.setSimpleColumn( details,
108,385,515,465,12,Element.ALIGN_LEFT);
                ct.go();
               
                cb.beginText();
                cb.setFontAndSize( bf, 11 );
               
                cb.setTextMatrix( 115,649 );
                cb.showText(policy.getInsured());
               
                cb.setTextMatrix( 115,676 );
                cb.showText(policy.getPolicyNumber());
               
                cb.setTextMatrix( 135,621 );
                cb.showText(claim.getCellPhone());
               
                cb.setTextMatrix( 325,621 );
                cb.showText( claim.getHomePhone() );
               
                cb.setTextMatrix( 505,621 );
                cb.showText( claim.getWorkPhone() );
               
                cb.setTextMatrix( 165,587 );
                cb.showText( claim.getContactPhone() );
               
                cb.setTextMatrix( 391,588 );
                cb.showText( claim.getContactRelationship() );
               
                cb.setTextMatrix( 119,561 );
                cb.showText( claim.getPremisesStreet() );
               
                cb.setTextMatrix( 119,546 );
                cb.showText( claim.getPremisesCity() + " " +
claim.getPremisesState() );

                cb.setTextMatrix( 372,561 );
                cb.showText( policy.getMailingAddressLine1() );
               
                cb.setTextMatrix( 372,546 );
                cb.showText( policy.getMailingAddressLine2() );
               
                cb.setTextMatrix( 372,531 );
                cb.showText( policy.getMailingAddressLine3() );
               
               
                cb.setTextMatrix( 124,508 );
                cb.showText( claim.getDateOfLoss() );
               
                cb.setTextMatrix( 505,506 );
                cb.showText( claim.getDateReported() );
               
                cb.setTextMatrix( 134,476 );
                cb.showText( claim.getLossCause() );
               
                cb.setTextMatrix( 171,397 );
                cb.showText( df.format(
policy.getExpirationDate().getTime() ) );
               
                cb.setTextMatrix( 397,397 );
                cb.showText( policy.getDeductible() );
               
               
                cb.setTextMatrix( 106,59 );
                cb.showText( policy.getAgent().getAgentNumber() );
               
                cb.setTextMatrix( 303, 59 );
                cb.showText( policy.getAgent().getAgentName() );
               
                float[] column = { 25F,10F,15F,25F,25F };
                PdfPTable itemTable = new PdfPTable( column );
                    itemTable.setTotalWidth( 550 );
                    itemTable.setLockedWidth( true );
                    itemTable.addCell( "DESCRIPTION" );
                    itemTable.addCell( "FORMS" );
                    itemTable.addCell( "COVERAGE" );
                    itemTable.addCell( "MORTGAGEE" );
                    itemTable.addCell( "MORTGAGEE" );
                   
                    while( itemIt.hasNext() ){
                        item = (Item) it.next();
                        itemTable.addCell( item.getTypeDescription() );
                        itemTable.addCell( item.getFormsCode() );
                        itemTable.addCell( Double.toString(
item.getCoverage() ) );
                        itemTable.addCell( item.getMortgagee1().getName() );
                        itemTable.addCell( item.getMortgagee2().getName() );
                    }
               
                    itemTable.writeSelectedRows(0,1,30,358,cb);
                   
                cb.endText();
                fireLossReport.newPage();  
             }
       
        } catch(Exception de) {
            System.err.println(de.getMessage());
        }
        fireLossReport.close();
    }    
}


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=click">http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: problems with table and imported page

Paulo Soares
The table must be outside the begin/end text.

----- Original Message -----
From: "Kevin Russell" <[hidden email]>
To: <[hidden email]>
Sent: Friday, July 15, 2005 5:26 PM
Subject: [iText-questions] problems with table and imported page


After working on this far too many hours, I was hoping someone could
help with the following code.  I have no problems getting an output of
pages with the text and the imported pdf.  However, when I add the
table, all I get is one page of the pdf - no text or table.

Your help is greatly appreciated,
Kevin

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.html.*;
import com.lowagie.text.pdf.*;
import java.sql.*;
import java.text.*;
import java.util.*;

public class PrintFireLossReports {
    public void printFireLossReports( java.util.List claims  ){
        Document fireLossReport = new Document(PageSize.LETTER);
        java.util.Date today = new java.util.Date();
        SimpleDateFormat todayFormat = new SimpleDateFormat(
"MMddyyyyHHmmss" );
        SimpleDateFormat df = new SimpleDateFormat(  "MM/dd/yyyy" );
        String todayString = todayFormat.format( today );
        String outputReport = "c:/lossReports" + todayString + ".pdf";

        Iterator it = claims.iterator();
        Claim claim = new Claim();
        Policy policy = new Policy();
        Item item = new Item();

        try {
            FileOutputStream outputPdf = new FileOutputStream(
outputReport );
            PdfWriter writer = PdfWriter.getInstance( fireLossReport,
outputPdf );
            PdfReader reader = new PdfReader("../loss_report.pdf");
            // Open the document and add some text to it.
            fireLossReport.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfImportedPage page1 = writer.getImportedPage(reader, 1);
            PolicyLookup policyLookup = new PolicyLookup();

            while( it.hasNext() ) {

                claim = (Claim) it.next();
                policy = policyLookup.getPolicy( claim.getPolicyNumber() );
                Iterator itemIt = policy.getPolicyItems().iterator();

                cb.addTemplate(page1, 0, 0);
                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Font font = new Font(bf, 11, Font.NORMAL);

                Phrase details = new Phrase( 0, claim.getClaimDetails());
                ColumnText ct = new ColumnText(cb);
                ct.setSimpleColumn( details,
108,385,515,465,12,Element.ALIGN_LEFT);
                ct.go();

                cb.beginText();
                cb.setFontAndSize( bf, 11 );

                cb.setTextMatrix( 115,649 );
                cb.showText(policy.getInsured());

                cb.setTextMatrix( 115,676 );
                cb.showText(policy.getPolicyNumber());

                cb.setTextMatrix( 135,621 );
                cb.showText(claim.getCellPhone());

                cb.setTextMatrix( 325,621 );
                cb.showText( claim.getHomePhone() );

                cb.setTextMatrix( 505,621 );
                cb.showText( claim.getWorkPhone() );

                cb.setTextMatrix( 165,587 );
                cb.showText( claim.getContactPhone() );

                cb.setTextMatrix( 391,588 );
                cb.showText( claim.getContactRelationship() );

                cb.setTextMatrix( 119,561 );
                cb.showText( claim.getPremisesStreet() );

                cb.setTextMatrix( 119,546 );
                cb.showText( claim.getPremisesCity() + " " +
claim.getPremisesState() );

                cb.setTextMatrix( 372,561 );
                cb.showText( policy.getMailingAddressLine1() );

                cb.setTextMatrix( 372,546 );
                cb.showText( policy.getMailingAddressLine2() );

                cb.setTextMatrix( 372,531 );
                cb.showText( policy.getMailingAddressLine3() );


                cb.setTextMatrix( 124,508 );
                cb.showText( claim.getDateOfLoss() );

                cb.setTextMatrix( 505,506 );
                cb.showText( claim.getDateReported() );

                cb.setTextMatrix( 134,476 );
                cb.showText( claim.getLossCause() );

                cb.setTextMatrix( 171,397 );
                cb.showText( df.format(
policy.getExpirationDate().getTime() ) );

                cb.setTextMatrix( 397,397 );
                cb.showText( policy.getDeductible() );


                cb.setTextMatrix( 106,59 );
                cb.showText( policy.getAgent().getAgentNumber() );

                cb.setTextMatrix( 303, 59 );
                cb.showText( policy.getAgent().getAgentName() );

                float[] column = { 25F,10F,15F,25F,25F };
                PdfPTable itemTable = new PdfPTable( column );
                    itemTable.setTotalWidth( 550 );
                    itemTable.setLockedWidth( true );
                    itemTable.addCell( "DESCRIPTION" );
                    itemTable.addCell( "FORMS" );
                    itemTable.addCell( "COVERAGE" );
                    itemTable.addCell( "MORTGAGEE" );
                    itemTable.addCell( "MORTGAGEE" );

                    while( itemIt.hasNext() ){
                        item = (Item) it.next();
                        itemTable.addCell( item.getTypeDescription() );
                        itemTable.addCell( item.getFormsCode() );
                        itemTable.addCell( Double.toString(
item.getCoverage() ) );
                        itemTable.addCell( item.getMortgagee1().getName() );
                        itemTable.addCell( item.getMortgagee2().getName() );
                    }

                    itemTable.writeSelectedRows(0,1,30,358,cb);

                cb.endText();
                fireLossReport.newPage();
             }

        } catch(Exception de) {
            System.err.println(de.getMessage());
        }
        fireLossReport.close();
    }
}


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. <a href="http://ads.osdn.com/?ad_idt77&alloc_id492&op=ick">http://ads.osdn.com/?ad_idt77&alloc_id492&op=ick
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Loading...