Пример #1
0
        private void headerPrint()
        {
            if (cols == null)
            {
                cols   = parser.GetHeaderInfo();
                widths = parser.GetWidths();
                for (int i = 0; i < cols[0].Length; i++)
                {
                    widthSum += cols[0][i].GetWidth();
                }
            }

            cols_stat = cols.Length;

            double[] bg     = RGBColor.GetColor(bgColor);
            double[] border = RGBColor.GetColor(lineColor);
            double   x      = OffsetLeft;
            double   y      = OffsetTop;
            int      lines  = 0;

            for (int row = 0; row < cols.Length; row++)
            {
                x = OffsetLeft;
                if (cols[row][0].IsFooter())
                {
                    continue;
                }
                for (int j = 0; j < cols[row].Length; j++)
                {
                    PDFColumn column = cols[row][j];

                    x += printColumn(column, bg, border, x, y);
                }
                y += HeaderLineHeight;
                lines++;
            }

            headerHeight = lines * HeaderLineHeight;
            footerHeight = (cols.Length - lines) * HeaderLineHeight;
            y            = pageHeight - headerHeight - footerHeight;
            y            = Math.Floor(y / LineHeight) * LineHeight + OffsetTop + headerHeight;

            for (int i = 0; i < cols.Length; i++)
            {
                if (!cols[i][0].IsFooter())
                {
                    continue;
                }
                x = OffsetLeft;
                for (int j = 0; j < cols[i].Length; j++)
                {
                    PDFColumn column = cols[i][j];
                    x += printColumn(column, bg, border, x, y);
                }
                y += HeaderLineHeight;
            }
        }
Пример #2
0
        private void printRows()
        {
            PDFRow[] rows = parser.GetGridContent();
            rows_stat = rows.Length;
            double[] rowColor;
            double[] border     = RGBColor.GetColor(lineColor);
            double   y          = OffsetTop + headerHeight;
            bool     cellsLined = false;
            XFont    cf;
            int      rowsOnPage = 0;

            for (int rowNum = 0; rowNum < rows.Length; rowNum++)
            {
                double    x     = OffsetLeft;
                PDFCell[] cells = rows[rowNum].GetCells();
                if (rowNum % 2 == 0)
                {
                    rowColor = RGBColor.GetColor(scaleOneColor);
                }
                else
                {
                    rowColor = RGBColor.GetColor(scaleTwoColor);
                }
                rowsOnPage++;

                for (int colNum = 0; colNum < cells.Length; colNum++)
                {
                    #region columnDrawing
                    double height = cols[0][colNum].GetHeight() * LineHeight;
                    double width  = widths[colNum] * pageWidth / widthSum;
                    String al     = cells[colNum].GetAlign();
                    if (al.ToLower().Equals(""))
                    {
                        al = cols[0][colNum].GetAlign();
                    }
                    String tp = cols[0][colNum].getType();

                    XRect cellIn = new XRect();
                    cellIn.Location = new XPoint(x, y);
                    cellIn.Size     = new XSize(width, LineHeight);


                    gfx.DrawRectangle(new XSolidBrush(RGBColor.GetXColor(((!cells[colNum].GetBgColor().Equals("")) && (parser.GetProfile() == ColorProfile.FullColor)) ? RGBColor.GetColor(cells[colNum].GetBgColor()) : rowColor)), cellIn);

                    if (cells[colNum].GetBold())
                    {
                        if (cells[colNum].GetItalic())
                        {
                            if (f4 == null)
                            {
                                f4 = createFont("Helvetica-BoldOblique", fontSize);
                            }
                            cf = f4;
                        }
                        else
                        {
                            if (f2 == null)
                            {
                                f2 = createFont("Helvetica-Bold", fontSize);
                            }
                            cf = f2;
                        }
                    }
                    else if (cells[colNum].GetItalic())
                    {
                        if (f3 == null)
                        {
                            f3 = createFont("Helvetica-Oblique", fontSize);
                        }
                        cf = f3;
                    }
                    else
                    {
                        cf = f1;
                    }

                    XTextFormatter text = new XTextFormatter(gfx);
                    text.Font = cf;
                    text.Text = textWrap(cells[colNum].GetValue(), width - 2 * CellOffset, cf);


                    String label = textWrap(cells[colNum].GetValue(), width - 2 * CellOffset, cf);



                    if (al.ToLower().Equals("left") == true)
                    {
                        text.Alignment = XParagraphAlignment.Left;
                    }
                    else
                    {
                        if (al.ToLower().Equals("right") == true)
                        {
                            text.Alignment = XParagraphAlignment.Right;
                        }
                        else
                        {
                            text.Alignment = XParagraphAlignment.Center;
                        }
                    }



                    var checkbox_width = 15 / 2;//approxmatelly...
                    if (tp.ToLower().Equals("ch"))
                    {
                        double ch_x = width / 2 - checkbox_width;
                        double ch_y = LineHeight / 2 - checkbox_width;
                        if (text.Text.ToLower().Equals("1") == true)
                        {
                            drawCheckbox(true, ch_x, ch_y, cellIn);
                        }
                        else
                        {
                            drawCheckbox(false, ch_x, ch_y, cellIn);
                        }
                    }
                    else
                    {
                        if (tp.ToLower().Equals("ra"))
                        {
                            double ch_x = width / 2 - checkbox_width;
                            double ch_y = LineHeight / 2 - checkbox_width;
                            if (text.Text.ToLower().Equals("1") == true)
                            {
                                drawRadio(true, ch_x, ch_y, cellIn);
                            }
                            else
                            {
                                drawRadio(false, ch_x, ch_y, cellIn);
                            }
                        }
                        else
                        {
                            double text_y = (LineHeight + f1.Size) / 2;

                            XRect text_cell = new XRect();
                            text_cell.Size = new XSize(width - 2 * LineHeight / 5, gfx.MeasureString(text.Text, text.Font).Height);

                            text_cell.Location = new XPoint(x + LineHeight / 5, y + (LineHeight - text_cell.Size.Height) / 1.7);


                            text.DrawString(text.Text, text.Font, new XSolidBrush((!cells[colNum].GetTextColor().Equals("") && parser.GetProfile().Equals("full_color")) ? RGBColor.GetXColor(cells[colNum].GetTextColor()) : RGBColor.GetXColor(gridTextColor)), text_cell);
                        }
                    }
                    x += width;
                    #endregion
                }



                gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(OffsetLeft, y), new XPoint(OffsetLeft + pageWidth, y));

                y += LineHeight;
                gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(OffsetLeft, y), new XPoint(OffsetLeft + pageWidth, y));


                if (y + LineHeight - OffsetTop + footerHeight >= pageHeight)
                {
                    var left = OffsetLeft;
                    var top  = OffsetTop + headerHeight;

                    top = OffsetTop + headerHeight;
                    gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));

                    var widths = parser.GetWidths();
                    for (int colNum = 0; colNum < widths.Length; colNum++)
                    {
                        left += widths[colNum] * pageWidth / widthSum;
                        gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));
                    }

                    newPage();
                    rowsOnPage = 0;
                    if (firstPage == true)
                    {
                        pageHeight += HeaderImgHeight;
                        OffsetTop  -= HeaderImgHeight;
                        firstPage   = false;
                    }
                    headerPrint();
                    y = OffsetTop + headerHeight;
                }
                x = OffsetLeft;
            }
            f1 = createFont("Helvetica", fontSize);

            if (!cellsLined)
            {
                var left = OffsetLeft;
                var top  = OffsetTop + headerHeight;


                top = OffsetTop + headerHeight;
                gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));

                var widths = parser.GetWidths();
                for (int colNum = 0; colNum < widths.Length; colNum++)
                {
                    left += widths[colNum] * pageWidth / widthSum;
                    gfx.DrawLine(new XPen(RGBColor.GetXColor(border), BorderWidth), new XPoint(left, top), new XPoint(left, top + rowsOnPage * LineHeight));
                }
            }
        }