Beispiel #1
0
 public PDFsplitLine(PDFline leftLine, PDFline rightLine) :
     base(leftLine.ElementIndex, leftLine.FontSize, Color.Black, PdfTextAlignment.Left)
 {
     Height    = leftLine.Height;
     LeftLine  = leftLine;
     RightLine = rightLine;
 }
Beispiel #2
0
        public void InsertNewSplitLine(float fontSize, string textLeft, string textRight)
        {
            PDFline leftLine = new PDFline(
                _elementCounter, fontSize, LINE_SPACING, Color.Black, PdfTextAlignment.Left, false, textLeft);
            PDFline rightLine = new PDFline(
                _elementCounter, fontSize, LINE_SPACING, Color.Black, PdfTextAlignment.Right, false, textRight);

            _document.AddElement(new PDFsplitLine(leftLine, rightLine));

            _elementCounter++;
        }
Beispiel #3
0
        public string Save(string path)
        {
            float currentPageHeight   = _pagePaddingLeft;
            int   prevElementCount    = 0;
            int   currentElementCount = 0;

            while (_document.Content.Count > 0)
            {
                PDFelement element = _document.Content.Dequeue();
                currentElementCount = element.ElementIndex;

                float posY = currentPageHeight;
                float posX = _pagePaddingLeft;

                if (element.GetType() == typeof(PDFline))
                {
                    PDFline line = (PDFline)element;

                    posX = GetElementHorizontalPosition(element.TextAlignment);
                    _currentPage.Canvas.DrawString(line.Text, line.Font, line.Brush, posX, posY, line.TextFormat);
                }
                else if (element.GetType() == typeof(PDFsplitLine))
                {
                    PDFsplitLine splitLine = (PDFsplitLine)element;

                    PDFline leftLine  = splitLine.LeftLine;
                    PDFline rightLine = splitLine.RightLine;

                    _currentPage.Canvas.DrawString(
                        leftLine.Text, leftLine.Font, leftLine.Brush,
                        GetElementHorizontalPosition(PdfTextAlignment.Left), posY,
                        leftLine.TextFormat
                        );
                    _currentPage.Canvas.DrawString(
                        rightLine.Text, rightLine.Font, rightLine.Brush,
                        GetElementHorizontalPosition(PdfTextAlignment.Right), posY,
                        rightLine.TextFormat
                        );
                }
                else if (element.GetType() == typeof(PDFtable))
                {
                    PDFtable table = (PDFtable)element;

                    PdfTable spireTable = new PdfTable();
                    spireTable.DataSource        = table.Table;
                    spireTable.BeginRowLayout   += Table_BeginRowLayout;
                    spireTable.Style.CellPadding = table.CellPadding;
                    spireTable.Style.BorderPen   = new PdfPen(table.Brush);
                    spireTable.Style.HeaderStyle.StringFormat = new PdfStringFormat(table.TextAlignment);
                    spireTable.Style.HeaderRowCount           = 1;
                    spireTable.Style.ShowHeader = true;
                    spireTable.Style.HeaderStyle.BackgroundBrush = PdfBrushes.LightGray;


                    foreach (PdfColumn column in spireTable.Columns)
                    {
                        column.StringFormat = new PdfStringFormat(table.TextAlignment, PdfVerticalAlignment.Middle);
                    }

                    spireTable.Draw(_currentPage, new PointF(posX, posY));
                }

                currentPageHeight += element.Height;
                if (currentPageHeight >= _pageMaxHeight)
                {
                    _currentPage      = _section.Pages.Add();
                    currentPageHeight = 0;
                }

                prevElementCount = currentElementCount;
            }

            _path = path;
            _spirePDF.SaveToFile(path, FileFormat.PDF);

            return(path);
        }