Exemple #1
0
        private static DocumentPDF setHeader(StampaVO.Document templateDoc, DocumentPDF docPDF)
        {
            //Creazione dell'header
            //TODO: gestire il testo, il numPagine, la dtaStampa

            StampaVO.Font font       = templateDoc.page.headerPage.font;
            Font          font1      = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
            string        str_header = templateDoc.page.headerPage.text;

            if (templateDoc.page.headerPage.dtaStampa != null)
            {
                if (str_header != null && !str_header.Equals(""))
                {
                    str_header += "\n";
                }
                str_header += templateDoc.page.headerPage.dtaStampa.text + DateTime.Parse(DateTime.Now.ToString()).ToShortDateString();
            }
            Phrase p = new Phrase(str_header, font1);

            HeaderFooter header = new HeaderFooter(p, false);

            if (templateDoc.page.headerPage.border == null || templateDoc.page.headerPage.border.Equals("0"))
            {
                header.Border = Rectangle.NO_BORDER;
            }
            header.Alignment       = Utils.getAlign(templateDoc.page.headerPage.align);
            docPDF.Header          = header;
            header.BackgroundColor = Utils.getColor(templateDoc.page.headerPage.bgcolor);
            return(docPDF);
        }
Exemple #2
0
 private static DocumentPDF printParagraph(StampaVO.Paragraph paragraph, DocumentPDF docPDF)
 {
     try
     {
         string[] testo;
         testo = paragraph.text.Split('&');
         StampaVO.Font font  = paragraph.font;
         Font          font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
         for (int i = 0; i < testo.Length; i++)
         {
             Paragraph p = new Paragraph(new Phrase(testo[i], font1));
             p.IndentationLeft  = paragraph.indentationLeft;
             p.IndentationRight = paragraph.indentationRight;
             p.Alignment        = Utils.getAlign(paragraph.align);
             docPDF.Add(p);
         }
     }
     catch (Exception ex)
     {
         docPDF.Close();
         writer.Close();
         throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
     }
     return(docPDF);
 }
Exemple #3
0
        private static DocumentPDF setFooter(StampaVO.Document templateDoc, DocumentPDF docPDF, string overrideFooter)
        {
            //Creazione del footer
            //TODO: gestire numPagine, la dtaStampa ???
            if (templateDoc.page.footerPage == null)
            {
                return(docPDF);
            }
            StampaVO.Font font       = templateDoc.page.footerPage.font;
            Font          font1      = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
            string        str_footer = templateDoc.page.footerPage.text;

            if (templateDoc.page.footerPage.dtaStampa != null)
            {
                if (str_footer != null && !str_footer.Equals(""))
                {
                    str_footer += "\n";
                }
                if (string.IsNullOrEmpty(overrideFooter))
                {
                    str_footer += templateDoc.page.footerPage.dtaStampa.text + DateTime.Parse(DateTime.Now.ToString()).ToShortDateString();
                }
                else
                {
                    str_footer += templateDoc.page.footerPage.dtaStampa.text + overrideFooter;
                }
            }
            Phrase       p = new Phrase(str_footer, font1);
            HeaderFooter footer;

            #region OLD GESTIONE NUM PAGE
            //Phrase pPage = null;
            //if (templateDoc.page.footerPage.numPagine != null)
            //{
            //    string str_Page = templateDoc.page.footerPage.numPagine.text;
            //    StampaVO.Font fontPage = templateDoc.page.footerPage.numPagine.font;
            //    Font font2 = FontFactory.GetFont(fontPage.name, fontPage.size, Utils.getFontStyle(fontPage.style), Utils.getColor(fontPage.color));
            //    pPage = new Phrase(str_Page, font2);
            //}

            //if (pPage != null)
            //    footer = new HeaderFooter(pPage, p);  //il true dovrebbe dare il num. di pagina
            //else
            //    footer = new HeaderFooter(p, false);
            #endregion

            footer = new HeaderFooter(p, false);
            if (templateDoc.page.footerPage.border == null || templateDoc.page.footerPage.border.Equals("0"))
            {
                footer.Border = Rectangle.NO_BORDER;
            }
            footer.Alignment = Utils.getAlign(templateDoc.page.footerPage.align);
            docPDF.Footer    = footer;

            return(docPDF);
        }
Exemple #4
0
 private static StampaVO.Font getFont(XmlNode nodo)
 {
     StampaVO.Font font = null;
     if (nodo != null)
     {
         font       = new StampaVO.Font();
         font.name  = Utils.getAttribute("font", nodo);
         font.size  = Utils.getAttributeF("size", nodo);
         font.style = Utils.getAttribute("style", nodo);
         font.color = Utils.getAttribute("color", nodo);
     }
     return(font);
 }
Exemple #5
0
 // we override the onOpenDocument method
 public void onOpenDocument(PdfWriter writer, Document document)
 {
     try
     {
         if (docTmp.page.numPagine == null)
         {
             return;
         }
         StampaVO.Font font = docTmp.page.numPagine.font;
         fontPage = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
         bf       = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
         cb       = writer.DirectContent;
         template = cb.CreateTemplate(100, 20);
     }
     catch (Exception e)
     {
         throw new ReportException(ErrorCode.ErrorEventPDFFile, e.Message);
     }
 }
Exemple #6
0
        protected static DocumentPDF printTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF)
        {
            if (dt == null)
            {
                return(docPDF);
            }

            //** Operazioni Preliminari
            //reupero del numero di colonne dal DataTable
            int col         = tableTmp.columns.Length;
            int col_visible = 0;

            for (int j = 0; j < tableTmp.columns.Length; j++)
            {
                if (tableTmp.columns[j].visible)
                {
                    col_visible++;
                }
            }

            try
            {
                //creazione della tabella
                iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible);

                //Adattamento delle colonne al contenuto
                aTable.Padding   = tableTmp.padding;
                aTable.Spacing   = tableTmp.spacing;
                aTable.Width     = 100;
                aTable.Alignment = Utils.getAlign(tableTmp.align);
                int[] widths = getColWidths(tableTmp, col_visible);

                aTable.SetWidths(widths);
                aTable.TableFitsPage = true;

                //** Aggiunta automatica dell'header della tabella
                for (int k = 0; k < col; k++)
                {
                    if (((StampaVO.Column)tableTmp.columns[k]).visible)
                    {
                        StampaVO.Font font  = tableTmp.headerTable.font;
                        Font          font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                        string        testo = ((StampaVO.Column)tableTmp.columns[k]).alias;
                        Cell          c     = new Cell(new Phrase(testo, font1));
                        c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align);
                        c.VerticalAlignment   = Utils.getAlign(tableTmp.headerTable.vAlign);
                        //c.NoWrap=true;
                        c.BackgroundColor = Utils.getColor(tableTmp.headerTable.bgColor);
                        aTable.AddCell(c);
                    }
                }

                aTable.EndHeaders();

                //** Popolamento automatico della tabella
                //Scansione dei dati
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //Creazione delle celle
                    for (int h = 0; h < col; h++)
                    {
                        if (((StampaVO.Column)tableTmp.columns[h]).visible)
                        {
                            StampaVO.Font font        = tableTmp.dataTable.font;
                            Font          font1       = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                            string        column_name = tableTmp.columns[h].name;
                            Cell          c1          = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1));
                            c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                            c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                            if (!string.IsNullOrEmpty(tableTmp.columns[h].bgColor))
                            {
                                c1.BackgroundColor = Utils.getColor(tableTmp.columns[h].bgColor);
                            }
                            aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                        }
                    }
                }

                docPDF.Add(aTable);
            }
            catch (Exception ex)
            {
                docPDF.Close();
                writer.Close();
                throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
            }
            return(docPDF);
        }
Exemple #7
0
        /// <summary>
        /// overloading per passare nome e cognome dell'utente loggato,in modo da evidenziare le trasmissioni di cui l'utente è destinatario
        /// Dimitri
        /// </summary>
        /// <param name="tableTmp"></param>
        /// <param name="dt"></param>
        /// <param name="docPDF"></param>
        /// <param name="infoUt"></param>
        /// <returns></returns>
        protected static DocumentPDF printCustomTable(StampaVO.Table tableTmp, DataTable dt, DocumentPDF docPDF, DocsPaVO.utente.InfoUtente infoUt)
        {
            if (dt == null)
            {
                return(docPDF);
            }

            //** Operazioni Preliminari
            //reupero del numero di colonne dal DataTable
            int col         = tableTmp.columns.Length;
            int col_visible = 0;

            for (int j = 0; j < tableTmp.columns.Length; j++)
            {
                if (tableTmp.columns[j].visible)
                {
                    col_visible++;
                }
            }
            try
            {
                //creazione della tabella
                iTextSharp.text.Table aTable = new iTextSharp.text.Table(col_visible);

                //Adattamento delle colonne al contenuto
                aTable.Padding = tableTmp.padding;
                aTable.Spacing = tableTmp.spacing;
                //aTable.WidthPercentage = 100;
                aTable.Width     = 100;
                aTable.Alignment = Utils.getAlign(tableTmp.align);
                int[] widths = getColWidths(tableTmp, col_visible);

                aTable.SetWidths(widths);
                //aTable.hasToFitPageCells();
                aTable.TableFitsPage = true;

                //** Aggiunta automatica dell'header della tabella
                for (int k = 0; k < col; k++)
                {
                    if (((StampaVO.Column)tableTmp.columns[k]).visible)
                    {
                        StampaVO.Font font       = tableTmp.headerTable.font;
                        Font          font1      = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));
                        string        testo      = ((StampaVO.Column)tableTmp.columns[k]).alias;
                        string[]      testoSplit = testo.Split(';');
                        string        testo_1    = string.Empty;
                        if (testoSplit.Length > 1)
                        {
                            testo_1 = @testoSplit[0] + "\n" + testoSplit[1];
                        }
                        else
                        {
                            testo_1 = testoSplit[0];
                        }
                        Cell c = new Cell(new Phrase(testo_1, font1));
                        if (((StampaVO.Column)tableTmp.columns[k]).name == "DESCR" || ((StampaVO.Column)tableTmp.columns[k]).name == "MITT_UT" || ((StampaVO.Column)tableTmp.columns[k]).name == "DEST" || ((StampaVO.Column)tableTmp.columns[k]).name == "NOTE_GENER")
                        {
                            c.HorizontalAlignment = Utils.getAlign("LEFT");
                        }
                        else
                        {
                            c.HorizontalAlignment = Utils.getAlign(tableTmp.headerTable.align);
                        }
                        c.VerticalAlignment = Utils.getAlign(tableTmp.headerTable.vAlign);
                        c.NoWrap            = true;
                        c.BackgroundColor   = Utils.getColor(tableTmp.headerTable.bgColor);
                        aTable.AddCell(c);
                    }
                }
                aTable.EndHeaders();

                //** Popolamento automatico della tabella
                //Scansione dei dati
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //Creazione delle celle
                    for (int h = 0; h < col; h++)
                    {
                        if (((StampaVO.Column)tableTmp.columns[h]).visible)
                        {
                            StampaVO.Font font          = tableTmp.dataTable.font;
                            string        style         = font.style;
                            string        column_name   = tableTmp.columns[h].name;
                            string        evidenziaDest = "";
                            if (dt.Rows[i]["SYSTEM_ID_DEST_UT"].ToString() == infoUt.idPeople && column_name == "DEST_UT")
                            {
                                evidenziaDest = "  *";
                                style         = "BOLD";
                            }

                            Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(style), Utils.getColor(font.color));
                            // Font font1 = FontFactory.GetFont(font.name, font.size, Utils.getFontStyle(font.style), Utils.getColor(font.color));

                            Cell c1;

                            if (column_name == "ID_REG_PROTO_ANNO")
                            {
                                string s = string.Empty;
                                if (dt.Rows[i]["COD_REG"].ToString() != "")
                                {
                                    s = @dt.Rows[i]["ID"].ToString() + "\n" + dt.Rows[i]["COD_REG"].ToString() + " - " + dt.Rows[i]["NUM_PROTO"].ToString() + " - " + dt.Rows[i]["ANNO"].ToString();
                                }
                                else
                                {
                                    s = dt.Rows[i]["ID"].ToString() + "\n Non Protocollato";
                                }
                                c1 = new Cell(new Phrase(s, font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }
                            if (column_name == "MITT_UT")
                            {
                                string s = @dt.Rows[i][column_name].ToString();
                                c1 = new Cell(new Phrase(s, font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }
                            if (column_name == "MITT_RU")
                            {
                                string s = dt.Rows[i]["MITT_RU"].ToString();
                                c1 = new Cell(new Phrase(s, font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }

                            //Aggiunta note individuali alle generali
                            if (column_name == "NOTE_GENER")
                            {
                                if (dt.Rows[i]["NOTE_INDIVID"] != null)
                                {
                                    string s = @dt.Rows[i]["NOTE_GENER"].ToString() + Environment.NewLine + "--------------" + Environment.NewLine;
                                    if (dt.Rows[i]["SYSTEM_ID_MITT_UT"].ToString() == infoUt.idPeople)
                                    {
                                        s += dt.Rows[i]["NOTE_INDIVID"].ToString();
                                    }
                                    c1 = new Cell(new Phrase(s, font1));
                                    c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                    c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                    aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                                }
                            }

                            if (column_name == "DEST_UT")
                            {
                                if (dt.Rows[i]["DEST_UT"] != null)
                                {
                                    string s = @dt.Rows[i]["DEST_UT"].ToString() + evidenziaDest;
                                    c1 = new Cell(new Phrase(s, font1));
                                    c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                    c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                    aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                                }
                            }

                            if (column_name != "ID_REG_PROTO_ANNO" && column_name != "MITT_UT" && column_name != "MITT_RU" && column_name != "NUM_PROTO" && column_name != "ANNO" && column_name != "NOTE_GENER" && column_name != "DEST_UT")
                            {
                                c1 = new Cell(new Phrase(dt.Rows[i][column_name].ToString(), font1));
                                c1.HorizontalAlignment = Utils.getAlign(tableTmp.columns[h].align);
                                c1.VerticalAlignment   = Utils.getAlign(tableTmp.columns[h].vAlign);
                                aTable.AddCell(c1, new System.Drawing.Point(i + 1, h));
                            }
                        }
                    }
                }

                //     aTable.Complete();
                //     aTable.FlushContent();

                docPDF.Add(aTable);
            }

            catch (Exception ex)
            {
                docPDF.Close();
                writer.Close();
                throw new ReportException(ErrorCode.IncompletePDFFile, "Errore nella scrittura dei dati: " + ex.Message);
            }
            return(docPDF);
        }