예제 #1
0
        private Font GetNodeFont(XmlElement elem)
        {
            const string METHOD_NAME = "GetNodeFont";

            try {
                Font   font       = null;
                string fontFamily = "";
                if (elem.Attributes["font-family"] != null)
                {
                    fontFamily = elem.Attributes["font-family"].Value;
                }
                string fontSize = "0";
                if (elem.Attributes["font-size"] != null)
                {
                    fontSize = elem.Attributes["font-size"].Value;
                }

                string fontStyle = "NORMAL";
                if (elem.Attributes["font-style"] != null)
                {
                    fontStyle = elem.Attributes["font-style"].Value;
                }

                if (fontSize != "0" && fontFamily != "")
                {
                    font = PdfReports.GetFont(fontFamily, fontSize, fontStyle);
                }

                return(font);
            }
            catch (Exception ex) {
                ApplicationException aex = new ApplicationException(MOD_NAME + METHOD_NAME, ex);
                throw (aex);
            }
        }
예제 #2
0
 public static void FillHeaderLabels(ref PdfPTable table, string[] hdrNameList, iTextSharp.text.Font font)
 {
     foreach (string hdr in hdrNameList)
     {
         PdfReports.AddText2Table(table, hdr, font, "center");
     }
 }
예제 #3
0
        private PdfPTable GetTable(XmlNode xmlTable)
        {
            const string METHOD_NAME = "GetTable";

            try {
                XmlNodeList trs   = xmlTable.SelectNodes("tr");
                PdfPTable   table = null;

                for (int i = 0; i < trs.Count; i++)
                {
                    if (i == 0)
                    {
                        XmlNodeList ths     = trs[i].SelectNodes("th");
                        float[]     columns = new float[ths.Count];

                        for (int j = 0; j < ths.Count; j++)
                        {
                            XmlNode node = ths.Item(j);
                            columns[j] = float.Parse(node.Attributes["width"].Value);
                        }
                        table = PdfReports.CreateTable(columns, 0);
                    }
                    else
                    {
                        XmlNodeList tds = trs[i].SelectNodes("td");
                        foreach (XmlNode td in tds)
                        {
                            iTextSharp.text.pdf.PdfPCell cell = null;
                            int align = GetHAlignment(td);

                            if (td.ChildNodes.Count == 0)
                            {
                                table.AddCell(" ");
                            }
                            else
                            {
                                foreach (XmlNode node in td.ChildNodes)
                                {
                                    Paragraph para   = null;
                                    Phrase    phrase = null;
                                    string    text   = null;

                                    switch (node.Name)
                                    {
                                    case "custom":
                                        phrase = GetCustomTag(node, ref text);
                                        cell   = new iTextSharp.text.pdf.PdfPCell(phrase);
                                        cell.HorizontalAlignment = align;
                                        cell.Border = 0;
                                        table.AddCell(cell);
                                        break;

                                    case "addressBlock":
                                        para = GetAddressBlock(node);
                                        cell = new iTextSharp.text.pdf.PdfPCell(para);
                                        cell.HorizontalAlignment = align;
                                        cell.Border = 0;
                                        table.AddCell(cell);
                                        break;

                                    case "paragraph":
                                        para = GetParagraph(node);
                                        cell = new iTextSharp.text.pdf.PdfPCell(para);
                                        cell.HorizontalAlignment = align;
                                        cell.Border = 0;
                                        table.AddCell(cell);
                                        break;

                                    case "image":
                                        iTextSharp.text.Image img = GetImage(node);
                                        cell = new iTextSharp.text.pdf.PdfPCell(img);
                                        cell.HorizontalAlignment = align;
                                        cell.Border = 0;
                                        table.AddCell(cell);
                                        break;

                                    case "phrase":
                                        phrase = GetPhrase(node);
                                        cell   = new iTextSharp.text.pdf.PdfPCell(phrase);
                                        cell.HorizontalAlignment = align;
                                        cell.Border = 0;
                                        table.AddCell(cell);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                return(table);
            }
            catch (Exception ex) {
                ApplicationException aex = new ApplicationException(MOD_NAME + METHOD_NAME, ex);
                throw (aex);
            }
        }