private void printWatermark(PdfPage currentPage, XGraphics graph)
        {
            if (Watermark == null)
            {
                return;
            }
            XTextFormatter text = new XTextFormatter(graph);

            text.Text = Watermark;
            text.Font = f1;

            XRect  placeholder = new XRect();
            double x           = OffsetLeft;
            double y           = pageHeight + OffsetTop + f1.Size;

            placeholder.Location = new XPoint(x, y);
            placeholder.Size     = new XSize(graph.MeasureString(text.Text, text.Font).Width, graph.MeasureString(text.Text, text.Font).Height);
            text.DrawString(text.Text, text.Font, new XSolidBrush(RGBColor.GetXColor(watermarkTextColor)), placeholder);
        }
        private void printPageNumbers()
        {
            for (var i = 1; i <= pages.Count; i++)
            {
                var    page  = pages[i - 1];
                var    graph = graphics[i - 1];
                String str   = PageNumTemplate;
                str = str.Replace("{pageNum}", i.ToString());
                str = str.Replace("{allNum}", pages.Count.ToString());

                XTextFormatter text = new XTextFormatter(graph);
                double         x    = pageWidth + OffsetLeft - graph.MeasureString(str, f1).Width;
                double         y    = pageHeight + OffsetTop + f1.Size;
                text.DrawString(str, f1, new XSolidBrush(RGBColor.GetXColor(pageTextColor)), new XRect(x, y, graph.MeasureString(str, f1).Width, f1.Size));


                printWatermark(page, graph);
            }
        }
Example #3
0
        public static double[] GetColor(String color)
        {
            if (parsedColors.ContainsKey(color))
            {
                return((double[])parsedColors[color]);
            }
            String original = color;

            color = RGBColor.ProcessColorForm(color);
            double[] result = new double[3];
            String   r      = color.Substring(0, 2);
            String   g      = color.Substring(2, 2);
            String   b      = color.Substring(4, 2);

            result[0] = int.Parse(r, System.Globalization.NumberStyles.HexNumber) / 255.0;
            result[1] = int.Parse(g, System.Globalization.NumberStyles.HexNumber) / 255.0;
            result[2] = int.Parse(b, System.Globalization.NumberStyles.HexNumber) / 255.0;
            parsedColors.Add(original, result);
            return(result);
        }
        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));
                }
            }
        }