I spent all day working on this issue and narrowing it down. It has to do with the use of PdfPTable with four cells in a Web Application. It is unable to be duplicated with a command line application. It generated the PDF file on the command line.

Here is the simple aspx code behind that shows the problem. If the document is not setup in Landscape (rotate) or if it has less than four Cells in the PdfPTable or if the Paragraph is less than 15 characters it generates fine, otherwise the file is damaged. Whew! That was a lot to type... I found it when I started putting in a Paragraph that had a full description (more than 15 characters).

Can someone please verify for me that they are seeing the same behavior in ASP.NET with the code below? And, maybe someone will have an idea of how I can address this. I am trying to create absolute positioned tables for label printing (4 labels per page).

I am new to iTextSharp, so please excuse me if this is a simple mistake on my part or has been addressed already.

Thanks,
Pete Gordon
[EMAIL PROTECTED]


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

namespace iTextSample
{
        /// <summary>
        /// Summary description for WebForm1.
        /// </summary>
        public class WebForm1 : System.Web.UI.Page
        {
                private void Page_Load(object sender, System.EventArgs e)
                {
                        // step 1
                        // need to write to memory first due to IE wanting
                        // to know the length of the pdf beforehand
                        MemoryStream m = new MemoryStream();
                        //Landscape doesn't work...
                        Document document = new Document(PageSize.A4.Rotate());
                        //Portrait works...
                        //Document document = new Document(PageSize.A4);
                        try
                        {
// step 2: we set the ContentType and create an instance of the Writer
                                Response.ContentType = "application/pdf";
                                PdfWriter 
writer=PdfWriter.GetInstance(document, m);
                                writer.CloseStream=false;

                                // step 3
                                document.Open();

iTextSharp.text.pdf.PdfPTable aTable = new iTextSharp.text.pdf.PdfPTable(2);
                                aTable.WidthPercentage = 100.0f;
                                aTable.ExtendLastRow = true;
                                // >=15 characters doesn't work
iTextSharp.text.pdf.PdfPCell aCell = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase("Maintenance xxx"));
                                // <15 characters works
//iTextSharp.text.pdf.PdfPCell aCell = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase("Maintenance xx"));
                                aCell.FixedHeight = 250;
                                aTable.AddCell(aCell);
                                aTable.AddCell("0.1");
                                aTable.AddCell("1.0");
                                aTable.AddCell("1.1");
                                document.Add(aTable);

                }
                        catch (DocumentException ex)
                        {
                                Console.Error.WriteLine(ex.StackTrace);
                                Console.Error.WriteLine(ex.Message);
                        }
                        // step 5: Close document
                        document.Close();

                        // step 6: Write pdf bytes to outputstream
                        Response.OutputStream.Write(m.GetBuffer(), 0, 
m.GetBuffer().Length);
                        Response.OutputStream.Flush();
                        Response.OutputStream.Close();
                        m.Close();
                }

                #region Web Form Designer generated code
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: This call is required by the ASP.NET Web 
Form Designer.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeComponent()
                {
                        this.Load += new System.EventHandler(this.Page_Load);
                }
                #endregion
        }
}





Attachment: WebForm1.aspx.cs
Description: Binary data


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to