Exemple #1
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);
        }
Exemple #2
0
 public void AddElement(PDFelement element)
 {
     Content.Enqueue(element);
 }