It looks like it worked in 4.0 by accident. You have several extra CR that
are messing the result. Where you have:

<%@ page
import="java.util.*,java.io.*,com.lowagie.text.*,com.lowagie.text.pdf.*,java
x.servlet.*,javax.servlet.http.*"
%>

<%!
String templateFile = "c:\\dbaco\\DBA4.pdf";

Replace with:

<%@ page
import="java.util.*,java.io.*,com.lowagie.text.*,com.lowagie.text.pdf.*,java
x.servlet.*,javax.servlet.http.*"
%><%!
String templateFile = "c:\\dbaco\\DBA4.pdf";

And so on.

----- Original Message ----- 
From: "Sammy" <[EMAIL PROTECTED]>
To: "Paulo Soares" <[EMAIL PROTECTED]>
Sent: Tuesday, April 26, 2005 10:05 PM
Subject: Re: [iText-questions] Why would iText work with 4.0 websphere, but
not with 6.0


Hi Paulo,

Yes it works with firefox as well - when I use websphere 4.0. When
migrated to 6.0 (I guess different jdk?), it does not work with IE or
firefox. Here is the jsp code.

<%@ page
import="java.util.*,java.io.*,com.lowagie.text.*,com.lowagie.text.pdf.*,java
x.servlet.*,javax.servlet.http.*"
%>

<%!
String templateFile = "c:\\dbaco\\DBA4.pdf";
PdfReader reader = null;
float width = 0;
float height = 0;

Rectangle psize;

public void jspInit(){
           try{

            reader = new PdfReader(templateFile);
            psize = reader.getPageSize(1);
            width = psize.width();
            height = psize.height();


   }catch(Exception e){
   log("Faild to load template file "+ e.getMessage());
   }
        }
%>
<%  response.setContentType("application/pdf"); %>
<jsp:useBean id="billBean" class="dba.NhawbLabelBean" />
<!-- set dbBillNumber from cyber bill to direcly set all the fields -->
<jsp:setProperty
name="billBean"
property="*"
/>


<%
   String terminalPhone = null;
   try
   {
      terminalPhone = session.getValue("terminalPhone").toString();
   }catch(Exception e) {
   log("Session does not contain terminalPhone...redirecting. Error:
"+ e.getMessage());
   response.sendRedirect("../html/onlineforms.htm");
   }

   if (terminalPhone == null || terminalPhone.length() < 5)
   terminalPhone = "1-800-272-1379";

   //SSS 11/14/2003 allow upto 50 labels at a time
   int startValue = billBean.getStartValue();

   System.out.println("****"+ startValue);

   String custRefNum = billBean.getCustRefNum();
   if (custRefNum == null)
   custRefNum = " ";

   StringBuffer cnAddress = new StringBuffer();
   cnAddress.append(billBean.getCnName() + "\n");
   cnAddress.append(billBean.getCnAddrs1() + "\n" );
   if (billBean.getCnAddrs2()!= null)
   cnAddress.append(billBean.getCnAddrs2() + "\n");
   if ( billBean.getCnCity()!= null)
   cnAddress.append(billBean.getCnCity() );

   if (billBean.getCnState() != null)
        cnAddress.append( "," + billBean.getCnState());

   if (billBean.getCnZip() != null)
    cnAddress.append( " - " + billBean.getCnZip());
   if (billBean.getCnCountry() != null)
    cnAddress.append("\n" + billBean.getCnCountry() );
   if (billBean.getCnContact() != null){ // from cyber bill it returns
" " rather then null
   if (billBean.getCnContact().trim().length()>1){
    cnAddress.append("\nContact: " + billBean.getCnContact() );
   if (billBean.getCnPhone() != null || !billBean.getCnPhone().equals(" "))
    cnAddress.append(" " + billBean.getCnPhone() + "\n" );
    }
   }

   StringBuffer csAddress = new StringBuffer();
      csAddress.append(billBean.getCsAddr1() + "\n" );
      if (billBean.getCsAddr2()!= null)
      csAddress.append(billBean.getCsAddr2() + "\n");
      if ( billBean.getCsCity()!= null)
      csAddress.append(billBean.getCsCity() );

      if (billBean.getCsState() != null)
           csAddress.append( "," + billBean.getCsState());

      if (billBean.getCsZip() != null)
    csAddress.append( " - " + billBean.getCsZip() + "\n" );
      if (billBean.getCsCountry() != null)
    csAddress.append( billBean.getCsCountry() + "\n" );
      if (billBean.getCsContact() != null){
        if (billBean.getCsContact().trim().length()>1)
        csAddress.append("Contact: " + billBean.getCsContact() + "\n");
      }

      if (billBean.getCsPhone() != null){
      if (billBean.getCsPhone().trim().length()>1)
    csAddress.append("Phone: " + billBean.getCsPhone() + "\n" );
      }


   StringBuffer remarks = new StringBuffer();
         if (billBean.getInstruction1()!= null)
         remarks.append(billBean.getInstruction1() + "\n");
         if (billBean.getInstruction2()!= null)
         remarks.append(billBean.getInstruction2() + "\n");
         if (billBean.getInstruction3()!= null)
         remarks.append(billBean.getInstruction3() + "\n");
         if (billBean.getInstruction4()!= null)
         remarks.append(billBean.getInstruction4() + "\n");


  float a =0.5f;   //a,d scale
  float b =0;   //b,c rotate
  float c =0;
  float d =0.5f;
  float e =0;  //e,f move x,y
  float f =0;

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ByteArrayOutputStream baosBuff = new ByteArrayOutputStream();
  ByteArrayOutputStream baosT = new ByteArrayOutputStream();

  int pcs=billBean.getPieces();
  System.out.println("--Labels Used-- Pieces " + pcs);

  /* SSS 10/21/2003 Don't set many fields again and again - use fos or
byteArray(use memory instead)
  and don't read file again and again in loop
  */
  /*
  String tFile = "c:\\dbaco\\DBAT" + System.currentTimeMillis()+".pdf";
  File ft = new File(tFile);
  FileOutputStream fos = new FileOutputStream(tFile);
  */


  Document document = null;

try {
            PdfReader reader = new PdfReader(templateFile);
            psize = reader.getPageSize(1);
            //PdfStamper stampT = new PdfStamper(reader,fos);
            PdfStamper stampT = new PdfStamper(reader,baosT);
    AcroFields formT = stampT.getAcroFields();
    formT.setField("cnAddress",cnAddress.toString());
    formT.setField("ctName",billBean.getCsName());
            formT.setField("ctAddress",csAddress.toString());
            //formT.setField("ctContact",csContact.toString());
    formT.setField("remark", remarks.toString());
    formT.setField("airbill",billBean.getBillNumber());
            formT.setField("tPhone",terminalPhone);
            formT.setField("custRefNum",custRefNum);
            stampT.close();

            document = new Document(psize, 50, 50, 50, 50);
            document.addAuthor("DBA");
            document.addTitle("Cyber Labels");
            document.addKeywords("Java Architecture by I-Solutions");
            //PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("c:\\temp\\import_page.pdf"));
            PdfWriter writer = PdfWriter.getInstance(document,baos);
            document.open();
            int pageTracker=0;

            byte[] baT = baosT.toByteArray();


    for(int i= startValue;i<=pcs;i++){

        if (pageTracker == 4){
        document.newPage();
        pageTracker=0;
        }

            //reader = new PdfReader(templateFile);
            //reader = new PdfReader(tFile);
            reader = new PdfReader(baT);
            psize = reader.getPageSize(1);
            baosBuff.reset();
            //PdfStamper stamp1 = new PdfStamper(reader, new
FileOutputStream("c:\\temp\\import_page2.pdf"));
            PdfStamper stamp1 = new PdfStamper(reader,baosBuff );
            AcroFields form1 = stamp1.getAcroFields();
            //form1.setField("cnAddress",cnAddress.toString());
            //form1.setField("ctName",billBean.getCsName());
            //form1.setField("ctAddress",csAddress.toString());
            //form1.setField("remark", remarks.toString());
            //form1.setField("airbill",billBean.getBillNumber());
            form1.setField("PieceX",Integer.toString(i));
            form1.setField("PieceY",Integer.toString(pcs));
            //form1.setField("tPhone",terminalPhone);
            //formT.setField("custRefNum",custRefNum);
            stamp1.setFormFlattening(true);
            stamp1.close();

            //PdfReader reader2 = new
PdfReader("c:\\temp\\import_page2.pdf");
            PdfReader reader2 = new PdfReader(baosBuff.toByteArray());
            PdfImportedPage page1 = writer.getImportedPage(reader2, 1);

            switch (pageTracker){
                    case 0: e=0;f=height / 2; break;
                    case 2: e=0;f=0;break;
                    case 3: e=width /2; f=0; break;
                    case 1: e=width /2; f=height /2; break;
            }
            PdfContentByte cb = writer.getDirectContent();
            cb.addTemplate(page1, a,b,c,d,e,f );

            pageTracker++;
            //SSS 11/14/2003 allow upto 50 labels at a time
            if ((billBean.getBillNumber()=="") ||
(billBean.getBillNumber()==null)){ // from cyber, no break

            if ((i-startValue)>=49){
            System.out.println("Lables printed from Shipping link");
               break;
               }
            }
         }//for
            document.close();
            //baos.writeTo(new
FileOutputStream("c:\\temp\\import_page.pdf"));
            baos.writeTo(response.getOutputStream());
            response.getOutputStream().flush();
            System.out.println("Finished.");
        }


catch (Exception de)
{
log("**Error Creating pdf doc.."+ de.getMessage());
out.println("Error generating labels. "+ de.getMessage());
}
finally
{
if (baos != null)
{
baos.reset();
}
if (document != null)
{
document.close();
}
if (baosT != null)
{
baosT.reset();
}

/*
if (fos != null){
        fos.close();
}
        ft.delete();
        */

}//finally



  %>


On 4/26/05, Paulo Soares <[EMAIL PROTECTED]> wrote:
> Does it work with firefox? Post the servlet code related to sending the
pdf.
>
> ----- Original Message -----
> From: "Sammy" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Tuesday, April 26, 2005 7:26 PM
> Subject: [iText-questions] Why would iText work with 4.0 websphere, but
not
> with 6.0
>
> hi,
>
> I developed JSP using iText and it worked fine for a year, unitl I
> moved to webspere 6.0, suddelnly, now I get the following error - "The
> file is damaged and could not be repaired".
>
> Tried it on diffrent versions of Adobe, same result. The code is
> the same, but I can't think of anything else changed besides the
> container (same iText lib).
>
> Anything you can do to help will be great!
>
> Sam
> p.s. Sorry for reposting, but I need help. Can send code if needed.
> Since there is no support, I am willing to pay a reasonable amount -
> if this is not legal, my apology.
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Tell us your software development plans!
> Take this survey and enter to win a one-year sub to SourceForge.net
> Plus IDC's 2005 look-ahead and a copy of this survey
> Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id5hix
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
>



-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id=105hix
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to