Esempio n. 1
0
        public void WriteToPdf(PdfDocument doc)
        {
            // kalibracia pozicie z pohladu odsadenia
            if (PosX < doc.Margins[0]) { PosX = (int)(doc.Margins[0]); };
            if (PosX > doc.PageSize.Width - doc.Margins[1]) { PosX = (int)(doc.PageSize.Width - doc.Margins[1]); };
            if (PosY < doc.Margins[3]) { PosY = (int)(doc.Margins[3]); };
            if (PosY > doc.PageSize.Height - doc.Margins[2]) { PosY = (int)(doc.PageSize.Height - doc.Margins[2]); };

            if (Height < 1) Height = 1;
            //if (Height > doc.PageSize.Height - doc.Margins[2] - doc.Margins[3]) Height = (int)(doc.PageSize.Height - doc.Margins[2] - doc.Margins[3]);
            if (Width < 1) Width = 1;
            //if (Width > doc.PageSize.Width - doc.Margins[0] - doc.Margins[1]) Width = (int)(doc.PageSize.Width - doc.Margins[0] - doc.Margins[1]);

            doc.GetWriter.SetLineWidth(1);

            /////////////////////////////////////////////////////////
             //vykreslenie spodneho obdlznika sluziaceho ako podklad
            PDFMaker.RectArea b = new PDFMaker.RectArea(PosX, PosY + Height-18, Width, 18, false);
            b.SetFillColor(_fillC, _fillM, _fillY, _fillK);
            b.SetStrokeColor(_strokeC, _strokeM, _strokeY, _strokeK);
            b.Filled = true;
            b.AddToDocument(doc);
            doc.Flush();
            //////////////////////////////////////////////////////

            // text hlavicky
            if (FontSize > 17)
                FontSize = 17;
            doc.GetWriter.SetCMYKColorStroke(_labelC, _labelM, _labelY, _labelK);
            doc.GetWriter.SetCMYKColorFill(_labelC, _labelM, _labelY, _labelK);
            doc.GetWriter.SetFontAndSize(customfont, FontSize);
            doc.GetWriter.BeginText();
            doc.GetWriter.SetTextMatrix(PosX + 10, PosY + Height - 14);

            doc.GetWriter.ShowText(Label);
            doc.GetWriter.EndText();
            doc.Flush();

            //text tela
            doc.GetWriter.BeginText();
            doc.GetWriter.SetFontAndSize(customfont, FontSize);
            doc.GetWriter.SetCMYKColorStroke(0, 0, 0, 0);
            doc.GetWriter.SetCMYKColorFill(0, 0, 0, 255);

            ColumnText ct = new ColumnText(doc.GetWriter);
            ct.SetSimpleColumn(PosX + 25, PosY + Height - 28, Width-30, Height-30);
            Font font = new Font(customfont, FontSize);
            Phrase p = new Phrase(TextBody, font);
            ct.AddText(p);
            ct.Go();
            doc.GetWriter.EndText();
            doc.Flush();

            while (Rows.Count > 0)
            {
                if (Rows.Peek().PosY < (int)doc.Margins[2])
                {
                    doc.AddNewPage();
                    doc.ActualWritePosition = (int)doc.PageSize.Top - (int)doc.Margins[2];
                    Height = -1;
                    getSectionWidthHeight();
                    this.PosY = doc.ActualWritePosition - Height;
                    this.getRowsPositions();
                    doc.Recalibrate();
                }

                Rows.Dequeue().WriteToPdf(doc);
            }
        }
Esempio n. 2
0
        public void AddToDocument(PdfDocument doc)
        {
            // kalibracia pozicie z pohladu odsadenia
            if (_posx < doc.Margins[0]) { _posx = doc.Margins[0]; };
            if (_posx > doc.PageSize.Width - doc.Margins[1]) { _posx = doc.PageSize.Width - doc.Margins[1]; };
            if (_posy < doc.Margins[3]) { _posy = doc.Margins[3]; };
            if (_posy > doc.PageSize.Height - doc.Margins[2]) { _posy = doc.PageSize.Height - doc.Margins[2]; };

            if (_heigh < 1) _heigh = 1;
            if (_heigh > doc.PageSize.Height - doc.Margins[2] - doc.Margins[3]) _heigh = doc.PageSize.Height - doc.Margins[2] - doc.Margins[3];
            if (_width < 1) _width = 1;
            if (_width > doc.PageSize.Width - doc.Margins[0] - doc.Margins[1]) _width = doc.PageSize.Width - doc.Margins[0] - doc.Margins[1];

            // vykreslenie spodneho obdlznika sluziaceho ako podklad
            doc.GetWriter.SetLineWidth(StrokeSize);
            PDFMaker.RectArea b = new PDFMaker.RectArea(_posx,_posy, _width, _heigh, false);

            b.SetFillColor(_fillC, _fillM, _fillY, _fillK);
            b.SetStrokeColor(_strokeC, _strokeM, _strokeY, _strokeK);
            b.SetStrokeColor(_strokeC, _strokeM, _strokeY, _strokeK);
            b.Filled = true;
            b.AddToDocument(doc);
            if (Stroked)
                if (Filled)
                    doc.GetWriter.FillStroke();
                else
                    doc.GetWriter.Stroke();
            else
                doc.GetWriter.Fill();
            doc.Flush();

            // vykreslenie obdlznika sluziaceho ako horna vrstvva podkladu
            //doc.GetWriter.SetCMYKColorStroke(_strokeC, _strokeM, _strokeY, _strokeK);
            //doc.GetWriter.SetCMYKColorFill(_fillC, _fillM, _fillY, _fillK);
            PDFMaker.RectArea c = new PDFMaker.RectArea(_posx, _posy, _width, _heigh - 21, false);
            c.SetFillColor(0, 0, 0, 30);
            c.Filled = true;
            c.AddToDocument(doc);
            if (Stroked)
                if (Filled)
                    doc.GetWriter.FillStroke();
                else
                    doc.GetWriter.Stroke();
            else
                doc.GetWriter.Fill();
            doc.Flush();

            // text hlavicky
            doc.GetWriter.SetCMYKColorStroke(0, 0, 0, 0);
            doc.GetWriter.SetCMYKColorFill(0, 0, 0, 0);
            doc.GetWriter.BeginText();
            doc.GetWriter.SetTextMatrix(_posx + 25, _posy + _heigh - 18);
            BaseFont customfont = BaseFont.CreateFont();
            Font font = new Font(customfont, 12);
            doc.GetWriter.SetFontAndSize(customfont, 20.0F);
            doc.GetWriter.ShowText(TextHeader);
            doc.GetWriter.EndText();
            doc.Flush();

            //text tela
            doc.GetWriter.BeginText();
            font = new Font(customfont, 12);
            doc.GetWriter.SetFontAndSize(customfont, 12.0F);
            doc.GetWriter.SetCMYKColorStroke(0, 0, 0, 255);
            doc.GetWriter.SetCMYKColorFill(0, 0, 0, 255);

            ColumnText ct = new ColumnText(doc.GetWriter);
            ct.SetSimpleColumn(_posx + 25, _posy + _heigh - 28, _width-30, _heigh-30);
            Phrase p = new Phrase(TextBody, font);
            ct.AddText(p);
            ct.Go();
            doc.GetWriter.EndText();
            doc.Flush();
        }