Exemplo n.º 1
0
 public float calculateHeights()
 {
     maxHeight = 0;
     for (int k = 0; k < cells.Length; ++k)
     {
         PdfPCell cell = cells[k];
         if (cell == null)
         {
             continue;
         }
         PdfPTable table = cell.Table;
         if (table == null)
         {
             float      rightLimit = cell.isNoWrap() ? 20000 : cell.Right - cell.PaddingRight;
             ColumnText ct         = new ColumnText(null);
             ct.setSimpleColumn(cell.Phrase,
                                cell.Left + cell.PaddingLeft,
                                cell.Top - cell.PaddingTop,
                                rightLimit,
                                -20000,
                                0, cell.HorizontalAlignment);
             ct.setLeading(cell.Leading, cell.MultipliedLeading);
             ct.Indent = cell.Indent;
             ct.ExtraParagraphSpace = cell.ExtraParagraphSpace;
             ct.FollowingIndent     = cell.FollowingIndent;
             ct.RightIndent         = cell.RightIndent;
             ct.RunDirection        = cell.RunDirection;
             try {
                 ct.go(true);
             }
             catch (DocumentException e) {
                 throw e;
             }
             float yLine = ct.YLine;
             cell.Bottom = yLine - cell.PaddingBottom;
         }
         else
         {
             table.TotalWidth = cell.Right - cell.PaddingRight - cell.PaddingLeft - cell.Left;
             cell.Bottom      = cell.Top - cell.PaddingTop - cell.PaddingBottom - table.TotalHeight;
         }
         float height = cell.FixedHeight;
         if (height <= 0)
         {
             height = cell.Height;
         }
         if (height < cell.FixedHeight)
         {
             height = cell.FixedHeight;
         }
         else if (height < cell.MinimumHeight)
         {
             height = cell.MinimumHeight;
         }
         if (height > maxHeight)
         {
             maxHeight = height;
         }
     }
     calculated = true;
     return(maxHeight);
 }
Exemplo n.º 2
0
        public void writeCells(float xPos, float yPos, PdfContentByte[] canvases)
        {
            if (!calculated)
            {
                calculateHeights();
            }
            for (int k = 0; k < cells.Length; ++k)
            {
                PdfPCell cell = cells[k];
                if (cell == null)
                {
                    continue;
                }
                writeBorderAndBackgroung(xPos, yPos, cell, canvases);
                PdfPTable table = cell.Table;
                float     tly   = 0;
                switch (cell.VerticalAlignment)
                {
                case Element.ALIGN_BOTTOM:
                    tly = cell.Top + yPos - maxHeight + cell.Height - cell.PaddingTop;
                    break;

                case Element.ALIGN_MIDDLE:
                    tly = cell.Top + yPos + (cell.Height - maxHeight) / 2 - cell.PaddingTop;
                    break;

                default:
                    tly = cell.Top + yPos - cell.PaddingTop;
                    break;
                }
                if (table == null)
                {
                    float fixedHeight = cell.FixedHeight;
                    float rightLimit  = cell.Right + xPos - cell.PaddingRight;
                    float leftLimit   = cell.Left + xPos + cell.PaddingLeft;
                    if (cell.isNoWrap())
                    {
                        switch (cell.HorizontalAlignment)
                        {
                        case Element.ALIGN_CENTER:
                            rightLimit += 10000;
                            leftLimit  -= 10000;
                            break;

                        case Element.ALIGN_RIGHT:
                            leftLimit -= 20000;
                            break;

                        default:
                            rightLimit += 20000;
                            break;
                        }
                    }
                    ColumnText ct  = new ColumnText(canvases[PdfPTable.TEXTCANVAS]);
                    float      bry = -20000;
                    if (fixedHeight > 0)
                    {
                        if (cell.Height > maxHeight)
                        {
                            tly = cell.Top + yPos - cell.PaddingTop;
                            bry = cell.Top + yPos - maxHeight + cell.PaddingBottom;
                        }
                    }
                    ct.setSimpleColumn(cell.Phrase,
                                       leftLimit,
                                       tly,
                                       rightLimit,
                                       bry,
                                       0, cell.HorizontalAlignment);
                    ct.setLeading(cell.Leading, cell.MultipliedLeading);
                    ct.Indent = cell.Indent;
                    ct.ExtraParagraphSpace = cell.ExtraParagraphSpace;
                    ct.FollowingIndent     = cell.FollowingIndent;
                    ct.RightIndent         = cell.RightIndent;
                    ct.SpaceCharRatio      = cell.SpaceCharRatio;
                    ct.RunDirection        = cell.RunDirection;
                    try {
                        ct.go();
                    }
                    catch (DocumentException e) {
                        throw e;
                    }
                }
                else
                {
                    float remainingHeight = 0;
                    float maxLastRow      = 0;
                    //add by Jin-Hsia Yang, to add remaining height to last row
                    if (table.Size > 0)
                    {
                        PdfPRow row = table.getRow(table.Size - 1);
                        remainingHeight = maxHeight - table.TotalHeight - cell.PaddingBottom - cell.PaddingTop;
                        if (remainingHeight > 0)
                        {
                            maxLastRow     = row.MaxHeights;
                            row.MaxHeights = row.MaxHeights + remainingHeight;
                            //table.setTotalHeight(table.TotalHeight + remainingHeight);
                        }
                    }
                    //end add

                    table.writeSelectedRows(0, -1, cell.Left + xPos + cell.PaddingLeft,
                                            tly, canvases);
                    if (remainingHeight > 0)
                    {
                        table.getRow(table.Size - 1).MaxHeights = maxLastRow;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public bool getPDF(ref MemoryStream mem, int quoteId, out string filename)
        {
            filename = "";
            bool pass = false;
            try
            {

                setDT(quoteId);
                row = dt.Rows[0];
                string extnumber = row["ExtNumber"].ToString();
                 if (row["ExtNumber"].ToString().IndexOf('-') > 0)
                {
                  extnumber=row["ExtNumber"].ToString().Substring(0, row["ExtNumber"].ToString().IndexOf('-'));
                }

                filename = row["OEM"].ToString() + "_" +extnumber + "_" + row["CustomerPartNumber"].ToString().Trim();
                filename = filename.Replace("\"", "").Replace("'", "").Replace(";", "").Replace(":", "") + "_" + DateTime.Now.ToString("mmssffff");
                //filename = HttpUtility.HtmlEncode(filename) + "_"+DateTime.Now.ToString("mmss");///.Minute.ToString() + DateTime.Now.Second.ToString();
                if (dt.Rows.Count > 0)
                {
                    pass = true;

                    init();
                    PdfWriter writer = PdfWriter.getInstance(doc, mem);
                    doc.Open();
                    addHeader();
                    part1();
                    part2();
                    part3();
                    part4();
                    part5();
                    PdfContentByte cb = writer.DirectContent;

                    ColumnText ct1 = new ColumnText(cb);
                    ColumnText ct2 = new ColumnText(cb);
                    ColumnText ct3 = new ColumnText(cb);
                    Phrase p1 = new Phrase(10f, "Multek Warranty T&C ",pageFont());
                    Phrase p2 = new Phrase(10f, "1",pageFont());
                    Phrase p3 = new Phrase(10f, "Rev. B 11/10/2011",pageFont());
                    ct1.setSimpleColumn(p1, 65f, 35f, 595f, 0f,10f, Element.ALIGN_LEFT);
                    ct2.setSimpleColumn(p2, 380f, 35f, 240f, 0f, 10f, Element.ALIGN_CENTER);
                    ct3.setSimpleColumn(p3, 530f, 35f, 65f, 0f, 10f, Element.ALIGN_RIGHT);
                    //ct2.setSimpleColumn(p1, 300f, 36.23f, 363.22f, 36.23f, 10f, Element.ALIGN_CENTER);
                    //ct2.setSimpleColumn(p2, 350.22f, 36.23f, 239.22f, 36.23f, 10f, Element.ALIGN_CENTER);
                    //ct3.setSimpleColumn(p3, 550.02f, 36.23f, 510f, 36.23f,10f, Element.ALIGN_RIGHT);
                    //ct.SetSimpleColumn(dd,25,50,50,500,10,Element.ALIGN_CENTER);
                    ct1.go();
                    ct2.go();
                    ct3.go();

                    string file = HttpContext.Current.Server.MapPath("~/tmp/template_1.pdf");
                    PdfReader reader = new PdfReader(file);

                    for (int i = 2; i < reader.NumberOfPages + 1; i++)
                    {
                        doc.setPageSize(reader.getPageSizeWithRotation(1));
                        doc.newPage();
                        if (i == 1)
                        {
                            Chunk fileref = new Chunk(" ");
                            fileref.setLocalDestination(file);
                            doc.Add(fileref);
                        }
                        PdfImportedPage p = writer.getImportedPage(reader, i);
                        cb.addTemplate(p, 1f, 0, 0, 1f, 0, 0);
                    }
                    doc.Close();
                }
                dt.Dispose();
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                // throw ex;
            }
            finally
            {
                dt.Dispose();

            }
            return pass;
        }