Inheritance: VerticalPositionMark
Esempio n. 1
1
        /// <summary>
        /// This method deals with the starting tags.
        /// </summary>
        /// <param name="name">the name of the tag</param>
        /// <param name="attributes">the list of attributes</param>
        public void HandleStartingTags(String name, Properties attributes) {
            //System.err.Println("Start: " + name);
            if (ignore || ElementTags.IGNORE.Equals(name)) {
                ignore = true;
                return;
            }
        
            // maybe there is some meaningful data that wasn't between tags
            if (currentChunk != null) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                }
                catch {
                    if (bf == null) {
                        current = new Paragraph("", new Font());
                    }
                    else {
                        current = new Paragraph("", new Font(this.bf));
                    }
                }
                current.Add(currentChunk);
                stack.Push(current);
                currentChunk = null;
            }

            // registerfont
            if (name.Equals("registerfont")) {
                FontFactory.Register(attributes);
            }

            // header
            if (ElementTags.HEADER.Equals(name)) {
                stack.Push(new HeaderFooter(attributes));
                return;
            }

            // footer
            if (ElementTags.FOOTER.Equals(name)) {
                stack.Push(new HeaderFooter(attributes));
                return;
            }

            // before
            if (name.Equals("before")) {
                HeaderFooter tmp = (HeaderFooter)stack.Pop();

                tmp.Before = ElementFactory.GetPhrase(attributes);
                stack.Push(tmp);
                return;
            }
        
            // after
            if (name.Equals("after")) {
                HeaderFooter tmp = (HeaderFooter)stack.Pop();

                tmp.After = ElementFactory.GetPhrase(attributes);
                stack.Push(tmp);
                return;
            }
        
            // chunks
            if (ElementTags.CHUNK.Equals(name)) {
                currentChunk = ElementFactory.GetChunk(attributes);
                if (bf != null) {
                    currentChunk.Font = new Font(this.bf);
                }
                return;
            }
        
            // symbols
            if (ElementTags.ENTITY.Equals(name)) {
                Font f = new Font();
                if (currentChunk != null) {
                    HandleEndingTags(ElementTags.CHUNK);
                    f = currentChunk.Font;
                }
                currentChunk = EntitiesToSymbol.Get(attributes[ElementTags.ID], f);
                return;
            }

            // phrases
            if (ElementTags.PHRASE.Equals(name)) {
                stack.Push(ElementFactory.GetPhrase(attributes));
                return;
            }
        
            // anchors
            if (ElementTags.ANCHOR.Equals(name)) {
                stack.Push(ElementFactory.GetAnchor(attributes));
                return;
            }
        
            // paragraphs and titles
            if (ElementTags.PARAGRAPH.Equals(name) || ElementTags.TITLE.Equals(name)) {
                stack.Push(ElementFactory.GetParagraph(attributes));
                return;
            }
        
            // lists
            if (ElementTags.LIST.Equals(name)) {
                stack.Push(ElementFactory.GetList(attributes));
                return;
            }
        
            // listitems
            if (ElementTags.LISTITEM.Equals(name)) {
                stack.Push(ElementFactory.GetListItem(attributes));
                return;
            }
        
            // cells
            if (ElementTags.CELL.Equals(name)) {
                stack.Push(ElementFactory.GetCell(attributes));
                return;
            }
        
            // tables
            if (ElementTags.TABLE.Equals(name)) {
                Table table = ElementFactory.GetTable(attributes);
                float[] widths = table.ProportionalWidths;
                for (int i = 0; i < widths.Length; i++) {
                    if (widths[i] == 0) {
                        widths[i] = 100.0f / (float)widths.Length;
                    }
                }
                try {
                    table.Widths = widths;
                }
                catch (BadElementException bee) {
                    // this shouldn't happen
                    throw new Exception("", bee);
                }
                stack.Push(table);
                return;
            }
        
            // sections
            if (ElementTags.SECTION.Equals(name)) {
                IElement previous = (IElement) stack.Pop();
                Section section;
                section = ElementFactory.GetSection((Section) previous, attributes);
                stack.Push(previous);
                stack.Push(section);
                return;
            }
        
            // chapters
            if (ElementTags.CHAPTER.Equals(name)) {
                stack.Push(ElementFactory.GetChapter(attributes));
                return;
            }
        
            // images
            if (ElementTags.IMAGE.Equals(name)) {
                try {
                    Image img = ElementFactory.GetImage(attributes);
                    try {
                        AddImage(img);
                        return;
                    }
                    catch {
                        // if there is no element on the stack, the Image is added to the document
                        try {
                            document.Add(img);
                        }
                        catch (DocumentException de) {
                            throw new Exception("", de);
                        }
                        return;
                    }
                }
                catch (Exception e) {
                    throw new Exception("", e);
                }
            }
        
            // annotations
            if (ElementTags.ANNOTATION.Equals(name)) {
                Annotation annotation = ElementFactory.GetAnnotation(attributes);
                ITextElementArray current;
                try {
                    try {
                        current = (ITextElementArray) stack.Pop();
                        try {
                            current.Add(annotation);
                        }
                        catch {
                            document.Add(annotation);
                        }
                        stack.Push(current);
                    }
                    catch {
                        document.Add(annotation);
                    }
                    return;
                }
                catch (DocumentException de) {
                    throw de;
                }
            }
        
            // newlines
            if (IsNewline(name)) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                    current.Add(Chunk.NEWLINE);
                    stack.Push(current);
                }
                catch {
                    if (currentChunk == null) {
                        try {
                            document.Add(Chunk.NEWLINE);
                        }
                        catch (DocumentException de) {
                            throw de;
                        }
                    }
                    else {
                        currentChunk.Append("\n");
                    }
                }
                return;
            }
        
            // newpage
            if (IsNewpage(name)) {
                ITextElementArray current;
                try {
                    current = (ITextElementArray) stack.Pop();
                    Chunk newPage = new Chunk("");
                    newPage.SetNewPage();
                    if (bf != null) {
                        newPage.Font = new Font(this.bf);
                    }
                    current.Add(newPage);
                    stack.Push(current);
                }
                catch {
                    document.NewPage();
                }
                return;
            }
        
            if (ElementTags.HORIZONTALRULE.Equals(name)) {
                ITextElementArray current;
                LineSeparator hr = new LineSeparator(1.0f, 100.0f, null, Element.ALIGN_CENTER, 0);
                try {
                    current = (ITextElementArray)stack.Pop();
                    current.Add(hr);
                    stack.Push(current);
                } catch (InvalidOperationException) {
                    document.Add(hr);
                }
                return;
            }
            
            // documentroot
            if (IsDocumentRoot(name)) {
                String value;
                // pagesize and orientation specific code suggested by Samuel Gabriel
                // Updated by Ricardo Coutinho. Only use if set in html!
                Rectangle pageSize = null;
                String orientation = null;
                foreach (string key in attributes.Keys) {
                    value = attributes[key];
                    // margin specific code suggested by Reza Nasiri
                    if (Util.EqualsIgnoreCase(ElementTags.LEFT, key))
                        leftMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.RIGHT, key))
                        rightMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.TOP, key))
                        topMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (Util.EqualsIgnoreCase(ElementTags.BOTTOM, key))
                        bottomMargin = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    if (ElementTags.PAGE_SIZE.Equals(key)) {
                        pageSize = (Rectangle)typeof(PageSize).GetField(value).GetValue(null);
                    } else if (ElementTags.ORIENTATION.Equals(key)) {
                        if ("landscape".Equals(value)) {
                            orientation = "landscape";
                        }
                    } else {
                        document.Add(new Meta(key, value));
                    }
                }
                if (pageSize != null) {
                    if ("landscape".Equals(orientation)) {
                        pageSize = pageSize.Rotate();
                    }
                    document.SetPageSize(pageSize);
                }
                document.SetMargins(leftMargin, rightMargin, topMargin,
                        bottomMargin);
                if (controlOpenClose)
                    document.Open();
            }
        }
 /* (non-Javadoc)
  * @see com.itextpdf.tool.xml.css.CssApplier#apply(com.itextpdf.text.Element, com.itextpdf.tool.xml.Tag)
  */
 virtual public LineSeparator Apply(LineSeparator ls, Tag t, IPageSizeContainable psc) {
     float lineWidth = 1;
     IDictionary<String, String> css = t.CSS;
     if (css.ContainsKey(CSS.Property.HEIGHT)) {
         lineWidth = CssUtils.GetInstance().ParsePxInCmMmPcToPt(css[CSS.Property.HEIGHT]);
     }
     ls.LineWidth = lineWidth;
     BaseColor lineColor = BaseColor.BLACK;
     if (css.ContainsKey(CSS.Property.COLOR)) {
         lineColor  = HtmlUtilities.DecodeColor(css[CSS.Property.COLOR]);
     } else if (css.ContainsKey(CSS.Property.BACKGROUND_COLOR)) {
         lineColor = HtmlUtilities.DecodeColor(css[CSS.Property.BACKGROUND_COLOR]);
     }
     ls.LineColor = lineColor;
     float percentage = 100;
     String widthStr;
     css.TryGetValue(CSS.Property.WIDTH, out widthStr);
     if (widthStr != null) {
         if (widthStr.Contains("%")) {
             percentage = float.Parse(widthStr.Replace("%", ""), CultureInfo.InvariantCulture);
         } else {
             percentage = (CssUtils.GetInstance().ParsePxInCmMmPcToPt(widthStr)/psc.PageSize.Width)*100;
         }
     }
     ls.Percentage = percentage;
     ls.Offset = 9;
     return ls;
 }
Esempio n. 3
0
        void WriteAlgorithmBenchmark(iTextSharp.text.Document doc, ISearchAlgorithm <string> algorithm, SearchReport <string> report)
        {
            iTextSharp.text.pdf.draw.LineSeparator line = new iTextSharp.text.pdf.draw.LineSeparator(1f, 100f, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.Element.ALIGN_CENTER, -1);
            iTextSharp.text.Chunk linebreak             = new iTextSharp.text.Chunk(line);
            Chunk c = new Chunk(algorithm.Name, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 24, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE));

            c.SetGenericTag(algorithm.Name);
            doc.Add(new Paragraph(c));
            // algorithm description
            Chunk desc = new Chunk(algorithm.Description, new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.ITALIC, iTextSharp.text.BaseColor.BLACK));

            doc.Add(new Paragraph(desc));
            // algorithm benchmark
            Chunk time = new Chunk("The algorithm took " + report.ElapsedTime + " to find the goal.", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK));

            doc.Add(new Paragraph(time));

            // path
            time = new Chunk("The result path costs " + algorithm.CalculateCost(report.Result), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK));
            doc.Add(new Paragraph(time));
            // write steps
            foreach (var step in report.Steps)
            {
                WriteAlgorithmStep(doc, step.StepInformation, step.GraphCapture);
            }

            doc.NewPage();
        }
Esempio n. 4
0
        public override iTextSharp.text.IElement GeneratePdfElement()
        {
            SeparatorStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style;

            iTextDraw.LineSeparator separator = new iTextDraw.LineSeparator()
            {
                LineWidth = style.Width ?? SeparatorStyle.Default.Width.Value,
                LineColor = new BaseColor(style.BorderColor ?? SeparatorStyle.Default.BorderColor.Value),
            };
            return new iText.Chunk(separator);
        }
Esempio n. 5
0
        void WriteHeader(iTextSharp.text.Document doc)
        {
            iTextSharp.text.pdf.draw.LineSeparator line = new iTextSharp.text.pdf.draw.LineSeparator(2f, 100f, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.Element.ALIGN_CENTER, -1);
            iTextSharp.text.Chunk linebreak             = new iTextSharp.text.Chunk(line);
            iTextSharp.text.Font  black = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 9f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            var logo = new iTextSharp.text.Paragraph()
            {
                Alignment = 0
            };

            logo.Add(new iTextSharp.text.Chunk("Graph", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 36, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK)));
            logo.Add(new iTextSharp.text.Chunk("SEA", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 36, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(26, 188, 156))));
            doc.Add(logo);
            doc.Add(new iTextSharp.text.Chunk(line));
            // add front page
            doc.Add(new Paragraph(new iTextSharp.text.Chunk("GraphSEA", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 72, iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(26, 188, 156)))));
            doc.Add(new Paragraph(new iTextSharp.text.Chunk("Graph Search Algorithms Benchmark Report", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 36, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK))));
        }
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
            Rectangle pageSize = document.PageSize;
            PdfPTable table    = new PdfPTable(1);

            table.SetTotalWidth(new float[] { 800f });
            table.LockedWidth = (true);
            PdfPCell  cell;
            Paragraph header;

            header = new Paragraph(title, PDFUtil.font_heading_1);
            iTextSharp.text.pdf.draw.VerticalPositionMark seperator = new iTextSharp.text.pdf.draw.LineSeparator();
            seperator.Offset = -4f;
            header.Add(seperator);
            cell        = new PdfPCell(header);
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);
            table.WriteSelectedRows(0, -1, pageSize.GetLeft(15), pageSize.GetTop(15), writer.DirectContent);
        }
Esempio n. 7
0
        protected override void FillContents()
        {
                        

            Paragraph dateParagraph = new Paragraph("Data: " + this.movimento.Data.ToShortDateString());
            this.mDoc.Add(dateParagraph);

            Paragraph entityParagraph = new Paragraph("Entidade: " + this.movimento.MovimentoEntidadeRow.Entidade);
            this.mDoc.Add(entityParagraph);

            Paragraph notesParagraph = new Paragraph("Notas: " + (this.movimento["Notas"] == DBNull.Value ? "" : this.movimento.Notas));
            this.mDoc.Add(notesParagraph);

            Paragraph documentsParagraph = new Paragraph("Documentos: ");
            this.mDoc.Add(documentsParagraph);

            for (int i = 0; i < this.documents.Count; i++)
            {
                string id = this.documents[i].IDNivel.ToString();
                string des = this.documents[i].Designacao;
                Paragraph docParagraph = new Paragraph("     " + id + " - " + des);
                this.mDoc.Add(docParagraph);
            } 
            
            //Signatures                                              

            Paragraph separator = new Paragraph("");            
            separator.SpacingBefore = 80;

            LineSeparator hline = new LineSeparator();
            hline.Percentage = 50;
            hline.LineWidth = 0.5f;            

            Paragraph signServicoArquivo = new Paragraph("(Serviço de Arquivo)");
            signServicoArquivo.Alignment = Element.ALIGN_CENTER;            

            Paragraph signServicoProdutor = new Paragraph("(Serviço Produtor)");
            signServicoProdutor.Alignment = Element.ALIGN_CENTER;            

            this.mDoc.Add(separator);
            this.mDoc.Add(hline);            

            if (this.movimento.CatCode.Trim().Equals("DEV"))
            {
                this.mDoc.Add(signServicoArquivo);                                
            }
            else
            {
                this.mDoc.Add(signServicoProdutor);                
            }
            
            this.mDoc.Add(separator);
            this.mDoc.Add(hline);

            if (this.movimento.CatCode.Trim().Equals("DEV"))
            {
                this.mDoc.Add(signServicoProdutor);
            }
            else
            {
                this.mDoc.Add(signServicoArquivo);
            }            
            
        }
Esempio n. 8
0
// ---------------------------------------------------------------------------
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        Director director;
        // creates line separators
        Chunk CONNECT = new Chunk(
          new LineSeparator(0.5f, 95, BaseColor.BLUE, Element.ALIGN_CENTER, 3.5f)
        );
        LineSeparator UNDERLINE = new LineSeparator(
          1, 100, null, Element.ALIGN_CENTER, -2
        );
        // creates tabs
        Chunk tab1 = new Chunk(new VerticalPositionMark(), 200, true);
        Chunk tab2 = new Chunk(new VerticalPositionMark(), 350, true);
        Chunk tab3 = new Chunk(new DottedLineSeparator(), 450, true);
        
        using (var c =  AdoDB.Provider.CreateConnection()) {
          c.ConnectionString = AdoDB.CS;
          using (DbCommand cmd = c.CreateCommand()) {
            cmd.CommandText = SQL;
            c.Open();
            using (var r = cmd.ExecuteReader()) {
              // loops over the directors
              while (r.Read()) {
                // creates a paragraph with the director name
                director = PojoFactory.GetDirector(r);
                Paragraph p = new Paragraph(
                    PojoToElementFactory.GetDirectorPhrase(director));
                // adds a separator
                p.Add(CONNECT);
                // adds more info about the director
                p.Add(string.Format("movies: {0}", Convert.ToInt32(r["c"])));
                // adds a separator
                p.Add(UNDERLINE);
                // adds the paragraph to the document
                document.Add(p);
                // gets all the movies of the current director
                var director_id = Convert.ToInt32(r["id"]);
                // LINQ allows us to sort on any movie object property inline;
                // let's sort by Movie.Year, Movie.Title
                var by_year = from m in PojoFactory.GetMovies(director_id)
                    orderby m.Year, m.Title
                    select m;
                // loops over the movies
                foreach (Movie movie in by_year) {
                // create a Paragraph with the movie title
                  p = new Paragraph(movie.MovieTitle);
                  // insert a tab
                  p.Add(new Chunk(tab1));
                  // add the original title
                  var mt = movie.OriginalTitle;
                  if (mt != null) p.Add(new Chunk(mt));
                  // insert a tab
                  p.Add(new Chunk(tab2));
                  // add the run length of the movie
                  p.Add(new Chunk(string.Format("{0} minutes", movie.Duration)));
                  // insert a tab
                  p.Add(new Chunk(tab3));
                  // add the production year of the movie
                  p.Add(new Chunk(
                    string.Format("{0}", movie.Year.ToString())
                  ));
                  // add the paragraph to the document
                  document.Add(p);
                }
                document.Add(Chunk.NEWLINE);           
              }
            }
          }
        }
      }
    }
Esempio n. 9
0
        private void CreateANewPdfDocument(string fileName, IEnumerable<ReportDataModel> dataModels, string groupByClauseHeader, bool includeLeavingDetails)
        {
            //Create new PDF document
            //- See more at: http://www.dotnetfox.com/articles/how-to-create-table-in-pdf-document-using-Asp-Net-with-C-Sharp-and-itextsharp-1027.aspx#sthash.x7pcQj64.dpuf
            var document = new Document(PageSize.A4, 20f, 20f, 20f, 20f);

            // set the page size, set the orientation
            //document.SetPageSize(PageSize.A4.Rotate());
            document.SetPageSize(PageSize.A4);

            int noOfColumns;
            float[] widths;

            if (includeLeavingDetails)
            {
                noOfColumns = 9;
                widths = new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f};
            }
            else
            {
                noOfColumns = 7;
                widths = new float[] {1f, 1f, 1f, 1f, 1f, 1f, 1f};
            }

            try
            {
                using (var writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create)))
                {
                    var pageEventHelper = new PageEventHelper();
                    writer.PageEvent = pageEventHelper;

                    document.Open();

                    document.Add(new Paragraph(string.Empty));
                    var image = iTextSharp.text.Image.GetInstance(Request.MapPath("~/content/images/loginimage.png"));
                    image.ScalePercent(75f);
                    //image.SetAbsolutePosition(0f, 0f);
                    document.Add(image);

                    //iTextSharp.text.Image imageHeader = iTextSharp.text.Image.GetInstance(Request.MapPath("~/content/images/bgimg.png"));
                    ////add image; PdfPCell() overload sizes image to fit cell
                    //var imageParagraph = new Paragraph();
                    //imageParagraph.Add(new Chunk(imageHeader, 50f, 50f));
                    //imageHeader.SetAbsolutePosition(0, 0);
                    ////var c = new PdfPCell(imageHeader, true);
                    ////c.HorizontalAlignment = Element.ALIGN_RIGHT;
                    ////c.FixedHeight = document.TopMargin;
                    ////c.Border = PdfPCell.NO_BORDER;
                    //document.Add(imageParagraph);
                    //var tableHeader = new PdfPTable(2);
                    //tableHeader.TotalWidth = 550f;
                    //fix the absolute width of the table
                    //tableHeader.LockedWidth = true;
                    //var imageHeader = iTextSharp.text.Image.GetInstance(Request.MapPath("~/content/images/bgimg.png"));
                    //var c = new PdfPCell(imageHeader, true);
                    ////c.HorizontalAlignment = Element.ALIGN_RIGHT;
                    //c.FixedHeight = document.TopMargin;
                    ////c.Border = PdfPCell.NO_BORDER;
                    //tableHeader.AddCell(c);



                    // create a paragraph and add it to the document
                    var title = new Paragraph(); // new Paragraph("St Mary Abbotts Rehabiliation & Training\n");
                    title.Add(new Chunk("St Mary Abbotts Rehabiliation & Training\n", _addressMainFont));
                    title.Add(new Chunk("The Basement,\n", _addressRowsFont));
                    title.Add(new Chunk("15 Gertrude Street,\n", _addressRowsFont));
                    title.Add(new Chunk("London SW10 0JN", _addressRowsFont));
                    title.IndentationLeft = 10f;
                    document.Add(title);

                    // add line below title
                    var line = new LineSeparator(1f, 100f, BaseColor.BLACK, Element.ALIGN_CENTER, -1);
                    document.Add(new Chunk(line));

                    var table = new PdfPTable(noOfColumns);
                    table.TotalWidth = 550f;
                    //fix the absolute width of the table
                    table.LockedWidth = true;

                    table.SetWidths(widths);
                    table.HorizontalAlignment = 0;
                    //leave a gap before and after the table
                    table.SpacingBefore = 10f;
                    table.SpacingAfter = 10f;

                    PdfPCell titleColumn;

                    var reportDataModels = dataModels as IList<ReportDataModel> ?? dataModels.ToList();

                    var grandTotal = reportDataModels.Count();

                    var groupData = GetQueryByGrouping(reportDataModels, groupByClauseHeader);
                    
                    int counter = 0;
                    foreach (var data in groupData)
                    {
                        counter++;
                        var rowSpan = data.Count();
                        
                        PdfPTable resultTable = null;
                        switch (groupByClauseHeader.ToLower())
                        {
                            case "nomination":
                                resultTable = CreateNominationData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "project":
                                resultTable = CreateProjectData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "gender":
                                resultTable = CreateGenderData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "ethnicity":
                                resultTable = CreateEthnicityData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "fundingresponsibility":
                            case "funding responsibility":
                                resultTable = CreateBoroughData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "agebracket":
                            case "age bracket":
                                resultTable = CreateAgeBracketData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "startdate":
                            case "start date":
                                resultTable = CreateStartDateData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                            case "membername":
                            case "member name":
                                resultTable = CreateMemberNameData(table, data, groupByClauseHeader, includeLeavingDetails, counter <= 1);
                                break;
                        }

                        table = resultTable;
                        
                        //GROUP TOTAL
                        titleColumn = GetTotalCell("Total", _groupRowFont);;
                        titleColumn.Colspan = 1;
                        table.AddCell(titleColumn);


                        var groupTotalCell = GetTotalCell(rowSpan.ToString(CultureInfo.InvariantCulture), _groupRowFont);
                        groupTotalCell.Colspan = noOfColumns - 2;
                        groupTotalCell.HorizontalAlignment = 2; //0=Left, 1=Centre, 2=Right
                        table.AddCell(groupTotalCell);



                        var perc = Math.Round((double) (((double) rowSpan/grandTotal)*100), 2);
                        //GROUP PERCENTAGE
                        titleColumn = GetPercentageCell("Percentage", _groupRowFont);
                        titleColumn.Colspan = 1;
                        table.AddCell(titleColumn);

                        var groupPercentageCell = GetPercentageCell(perc.ToString(CultureInfo.InvariantCulture) + "%", _groupRowFont);
                        groupPercentageCell.HorizontalAlignment = 2;
                        groupPercentageCell.Colspan = noOfColumns - 2;
                        table.AddCell(groupPercentageCell);
                    }

                    //Grand Total
                    titleColumn = GetGrandTotalCell("Grand Total", _groupRowFont);
                    titleColumn.Colspan = 1;
                    table.AddCell(titleColumn);

                    var grandeTotalCell = GetGrandTotalCell(grandTotal.ToString(CultureInfo.InvariantCulture), _groupRowFont);
                    grandeTotalCell.HorizontalAlignment = 2;
                    grandeTotalCell.Colspan = noOfColumns - 1;
                    table.AddCell(grandeTotalCell);

                    document.Add(table);
                }
            }
            catch(Exception ex)
            {
            }
            finally
            {
                document.Close();
                //ShowPdf(fileName);
            }

        }
Esempio n. 10
0
        /// <summary>
        /// 输出到PDF
        /// </summary>
        /// <param name="list"></param>
        /// <param name="sysFont"></param>
        /// <param name="multiRow"></param>
        /// <param name="export">算高度的情况最后输出时使用</param>
        /// <returns></returns>
        public Table WriteFields(List<List<PdfDesc>> list, System.Drawing.Font sysFont, int multiRow, bool export)
        {
            #region Variable Definition
            Cell cell = null;
            int maxColumnCount = -1;
            int maxRowCount = -1;
            LineSeparator lineSeparator = null;
            int tempCount = 0;
            int previousFieldCells = 0;
            Table tb = null;
            #endregion

            //try
            //{
                Font pdfFont = this.GetPdfFont(sysFont);

                //Hashtable allStartIndex = new Hashtable();

                Dictionary<int, int> allStartIndex = new Dictionary<int, int>();

                if (export)
                {
                    foreach (List<PdfDesc> row in list)
                    {
                        if (!allStartIndex.ContainsKey(row[0].FieldNum))
                        {
                            allStartIndex.Add(row[0].FieldNum, list.IndexOf(row));
                        }
                    }
                }
                else
                {
                    allStartIndex.Add(0, 0);
                }

                List<int> startIndex = new List<int>();

                foreach (int index in allStartIndex.Values)
                {
                    startIndex.Add(index);
                }

                for (int l = 0; l < startIndex.Count; l++)
                {
                    //計算最大Column和最大Row

                    maxColumnCount = 0;

                    if (startIndex.Count == 1)
                    {
                        maxRowCount = list.Count;
                    }
                    else if (l != startIndex.Count - 1)
                    {
                        maxRowCount = startIndex[l + 1] - startIndex[l];
                    }
                    else
                    {
                        maxRowCount = list.Count - startIndex[l];
                    }

                    for (int s = startIndex[l]; s < list.Count; s++)
                    //foreach (List<PdfDesc> row in list)
                    {
                        if (startIndex.Count != 1)
                        {
                            if (l != startIndex.Count - 1 && s == startIndex[l + 1])
                            {
                                break;
                            }
                        }

                        List<PdfDesc> row = list[s];

                        foreach (PdfDesc pdfDesc in row)
                        {
                            tempCount += pdfDesc.Cells;
                        }

                        if (tempCount > maxColumnCount)
                        {
                            maxColumnCount = tempCount;
                        }

                        tempCount = 0;
                    }

                    tb = new Table(maxColumnCount, maxRowCount);

                    #region 計算欄位寬度
                    if (multiRow == 1)
                    {
                        int[] widths = new int[maxColumnCount];

                        previousFieldCells = 0;

                        List<PdfDesc> firstRow = list[startIndex[l]];

                        for (int i = 0; i < firstRow.Count; i++)
                        {
                            int widthPercent = Convert.ToInt32(Math.Truncate((UnitConversion.GetPdfLetterWidth(firstRow[i].Width, sysFont)
                                / Convert.ToDouble((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin))) * 100)); //算出百分比

                            if (i == 0)
                            {
                                widths[i] = widthPercent;

                                if (firstRow[i].Cells > 1)
                                {
                                    for (int j = 0; j < firstRow[i].Cells - 1; j++)
                                    {
                                        widths[i + j + 1] = widthPercent;
                                    }
                                }
                            }
                            else
                            {
                                widths[previousFieldCells] = widthPercent;

                                if (firstRow[i].Cells > 1)
                                {
                                    for (int j = 0; j < firstRow[i].Cells - 1; j++)
                                    {
                                        widths[previousFieldCells + j + 1] = widthPercent;
                                    }
                                }
                            }

                            previousFieldCells += firstRow[i].Cells;
                        }

                        tb.SetWidths(widths);

                        previousFieldCells = 0;
                    }
                    #endregion

                    if (!this.report.Format.ColumnGridLine)
                    {
                        tb.Border = Rectangle.NO_BORDER;
                    }

                    tb.Cellpadding = PdfSizeConfig.Cellpadding;
                    //tb.Width = ((this.pdfDoc.PageSize.Width - this.pdfDoc.LeftMargin - this.pdfDoc.RightMargin) / this.pdfDoc.PageSize.Width) * 100; //此處為百分比
                    tb.Width = 100;
                    tb.Alignment = Element.ALIGN_LEFT;

                    for (int j = startIndex[l]; j < list.Count; j++)
                    {
                        if (startIndex.Count != 1)
                        {
                            if (l != startIndex.Count - 1 && j == startIndex[l + 1])
                            {
                                break;
                            }
                        }

                        List<PdfDesc> row = list[j];

                        previousFieldCells = 0;
                        for (int i = 0; i < row.Count; i++)
                        {
                            PdfDesc pdfDesc = row[i];

                            switch (pdfDesc.GroupGap)
                            {
                                case DataSourceItem.GroupGapType.None:
                                    cell = new Cell(new Chunk(pdfDesc.Value, pdfFont));
                                    cell.Colspan = pdfDesc.Cells;
                                    cell.HorizontalAlignment = this.GetPdfHAlignByStr(pdfDesc.HAlign);
                                    break;
                                case DataSourceItem.GroupGapType.EmptyRow:
                                    if (i == 0)
                                    {
                                        cell = new Cell(new Chunk(String.Empty, pdfFont));
                                        cell.Colspan = maxColumnCount;
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.SingleLine:
                                    if (i == 0)
                                    {
                                        cell = new Cell();
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU;
                                        cell.AddElement(lineSeparator);
                                        cell.Colspan = tb.Columns;
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.DoubleLine:
                                    if (i == 0)
                                    {
                                        cell = new Cell();
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetU;
                                        cell.AddElement(lineSeparator);
                                        lineSeparator = new LineSeparator();
                                        lineSeparator.LineWidth = cell.Width;
                                        lineSeparator.Offset = PdfSizeConfig.LineSeparatorOffsetD;
                                        cell.AddElement(lineSeparator);
                                        cell.Colspan = tb.Columns;
                                    }
                                    break;
                            }

                            cell.BorderWidthLeft = pdfDesc.LeftLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthRight = pdfDesc.RightLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthTop = pdfDesc.TopLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            cell.BorderWidthBottom = pdfDesc.BottomLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;

                            if (j == list.Count - 1)
                            {
                                cell.BorderWidthBottom = report.Format.RowGridLine == true ? PdfSizeConfig.BorderWidth : PdfSizeConfig.BorderWidthZero;
                            }

                            cell.UseAscender = true; //此屬性設置為True的時候VerticalAlignment才會起作用
                            cell.VerticalAlignment = Cell.ALIGN_MIDDLE;

                            switch (pdfDesc.GroupGap)
                            {
                                case DataSourceItem.GroupGapType.None:
                                    if (i == 0)
                                    {
                                        tb.AddCell(cell, j, i);
                                    }
                                    else
                                    {
                                        tb.AddCell(cell, j, previousFieldCells);
                                    }
                                    break;
                                case DataSourceItem.GroupGapType.EmptyRow:
                                case DataSourceItem.GroupGapType.SingleLine:
                                case DataSourceItem.GroupGapType.DoubleLine:
                                    if (i == 0)
                                    {
                                        tb.AddCell(cell, j, i);
                                    }
                                    break;
                            }

                            previousFieldCells += pdfDesc.Cells;
                        }
                    }

                    if (!ExportByHeight || export)
                    {
                        this.pdfDoc.Add(tb);
                    }
                }
            //}
            //catch (Exception ex)
            //{
            //    log.WriteExceptionInfo(ex);
            //    throw ex;
            //}

            return tb;
        }
Esempio n. 11
0
 public void NuevaLineaDivisoria()
 {
     var linea = new LineSeparator ();
     var espacio = new Chunk (" ", FontFactory.GetFont (FontFactory.HELVETICA, 4));
     document.Add (new Paragraph (espacio));
     document.Add (linea);
     document.Add (new Paragraph (espacio));
 }
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         Director director;
         // creating separators
         LineSeparator line
             = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);
         Paragraph stars = new Paragraph(20);
         stars.Add(new Chunk(StarSeparator.LINE));
         stars.SpacingAfter = 30;
         using (var c = AdoDB.Provider.CreateConnection())
         {
             c.ConnectionString = AdoDB.CS;
             using (DbCommand cmd = c.CreateCommand())
             {
                 cmd.CommandText = SQL;
                 c.Open();
                 using (var r = cmd.ExecuteReader())
                 {
                     while (r.Read())
                     {
                         // get the director object and use it in a Paragraph
                         director = PojoFactory.GetDirector(r);
                         Paragraph p = new Paragraph(
                             PojoToElementFactory.GetDirectorPhrase(director));
                         // if there are more than 2 movies for this director
                         // an arrow is added to the left
                         var count = Convert.ToInt32(r["c"]);
                         if (count > 2)
                         {
                             p.Add(PositionedArrow.LEFT);
                         }
                         p.Add(line);
                         // add the paragraph with the arrow to the document
                         document.Add(p);
                         // Get the movies of the director
                         var director_id = Convert.ToInt32(r["id"]);
                         // LINQ allows us to sort on any movie object property inline;
                         // let's sort by Movie.Year, Movie.Title
                         var by_year = from m in PojoFactory.GetMovies(director_id)
                                       orderby m.Year, m.Title
                                       select m;
                         foreach (Movie movie in by_year)
                         {
                             p = new Paragraph(movie.MovieTitle);
                             p.Add(": ");
                             p.Add(new Chunk(movie.Year.ToString()));
                             if (movie.Year > 1999) p.Add(PositionedArrow.RIGHT);
                             document.Add(p);
                         }
                         // add a star separator after the director info is added
                         document.Add(stars);
                     }
                 }
             }
         }
     }
 }