Exemplo n.º 1
0
        //	http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics

        public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
                                        BaseLine line,
                                        IBaseStyleDecorator style,
                                        iTextSharp.text.Rectangle rectangle)
        {
            if (contentByte == null)
            {
                throw new ArgumentNullException("contentByte");
            }

            if (style == null)
            {
                throw new ArgumentNullException("style");
            }
            if (rectangle == null)
            {
                throw new ArgumentNullException("rectangle");
            }

            if (line == null)
            {
                BaseShape.FillBackGround(contentByte, style, rectangle);
            }
            else
            {
                BaseShape.SetupShape(contentByte, style);
                contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
                contentByte.RoundRectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height, CornerRadius);
                BaseShape.FinishShape(contentByte);
            }
        }
Exemplo n.º 2
0
        public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
                                        BaseLine line,
                                        IBaseStyleDecorator style,
                                        iTextSharp.text.Rectangle rectangle)
        {
            if (contentByte == null)
            {
                throw new ArgumentNullException("contentByte");
            }
            if (rectangle == null)
            {
                throw new ArgumentNullException("rectangle");
            }

            if ((line == null) || (line.Thickness < 1))
            {
                BaseShape.FillBackGround(contentByte, style, rectangle);
            }
            else if ((style.BackColor == GlobalValues.DefaultBackColor))
            {
                BaseShape.SetupShape(contentByte, style);
                contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
                contentByte.Ellipse(rectangle.Left,
                                    rectangle.Top,
                                    rectangle.Left + rectangle.Width,
                                    rectangle.Top - rectangle.Height);
                BaseShape.FinishShape(contentByte);
            }
            else
            {
                BaseShape.FillBackGround(contentByte, style, rectangle);
            }
        }
Exemplo n.º 3
0
        public void DrawBorder(iTextSharp.text.pdf.PdfContentByte contentByte,
                               iTextSharp.text.Rectangle rectangle,
                               ICSharpCode.Reports.Core.Exporter.IBaseStyleDecorator style)
        {
            if (contentByte == null)
            {
                throw new ArgumentNullException("contentByte");
            }

            contentByte.SetColorStroke(style.PdfFrameColor);
            contentByte.SetLineWidth(UnitConverter.FromPixel(baseline.Thickness).Point);

            contentByte.MoveTo(rectangle.Left, rectangle.Top);

            contentByte.LineTo(rectangle.Left, rectangle.Top - rectangle.Height);

            contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top - rectangle.Height);

            contentByte.LineTo(rectangle.Left + rectangle.Width, rectangle.Top);

            contentByte.LineTo(rectangle.Left, rectangle.Top);

            contentByte.FillStroke();
            contentByte.ResetRGBColorFill();
        }
Exemplo n.º 4
0
        public override void CreatePath(iTextSharp.text.pdf.PdfContentByte contentByte,
                                        BaseLine line,
                                        IBaseStyleDecorator style,
                                        Point from, Point to)
        {
            if (contentByte == null)
            {
                throw new ArgumentNullException("contentByte");
            }

            BaseShape.SetupShape(contentByte, style);
            contentByte.SetLineWidth(UnitConverter.FromPixel(line.Thickness).Point);
            contentByte.MoveTo(from.X, from.Y);
            contentByte.LineTo(to.X, to.Y);
            BaseShape.FinishShape(contentByte);
        }
        public Boolean Obtener_Pdf_CC(String pRutaArchivo, FirmaElectronicaModel oFirmaElectronicaModel, String pImg64)
        //Fin E.Z. 13/05/2016
        {
            Boolean b_Resultado = false;

            iTextSharp.text.Document           oDocument       = null;
            iTextSharp.text.pdf.PdfWriter      oPdfWriter      = null;
            iTextSharp.text.pdf.PdfContentByte oPdfContentByte = null;
            iTextSharp.text.Chunk        oChunk  = null;
            iTextSharp.text.HeaderFooter oFooter = null;
            try
            {
                using (FileStream fs = new FileStream(pRutaArchivo, FileMode.Create, FileAccess.Write))
                {
                    // Crear PDF
                    oDocument  = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 30, 30, 15, 25);
                    oPdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(oDocument, fs);

                    oDocument.Open();
                    oPdfContentByte = oPdfWriter.DirectContent;
                    oPdfContentByte.Stroke();
                    oPdfContentByte.SetLineWidth(0.2f);

                    oDocument.Add(Obtener_Logos(null));
                    oDocument.Add(Obtener_Blanco());
                    oDocument.Add(Obtener_Titulo("098923"));
                    oDocument.Add(Obtener_Blanco());
                    oDocument.Add(Obtener_Cliente(oFirmaElectronicaModel));
                    oDocument.Add(Obtener_Blanco());
                    oDocument.Add(Obtener_Cuenta(oFirmaElectronicaModel));
                    oDocument.Add(Obtener_Blanco());
                    oDocument.Add(Obtener_Solicitud(oFirmaElectronicaModel, "ARamirez"));
                    oDocument.Add(Obtener_Blanco());
                    oDocument.Add(Obtener_Blanco());
                    oDocument.Add(Obtener_Pie(oFirmaElectronicaModel));
                    #region "Firma"
                    //Firma 1
                    //oPdfContentByte.Rectangle(59f, 40.5f, 300f, 72.5f);
                    oPdfContentByte.BeginText();
                    oPdfContentByte.SetFontAndSize(iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.WINANSI, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED), (float)8);
                    oPdfContentByte.ShowTextAligned(iTextSharp.text.Element.ALIGN_BASELINE, "Asesor de Servicio al Cliente Finantienda", 59f, 122.5f, 0);
                    oPdfContentByte.EndText();
                    oPdfContentByte.Stroke();
                    oPdfContentByte.BeginText();
                    oPdfContentByte.SetFontAndSize(iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.WINANSI, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED), (float)8);
                    oPdfContentByte.ShowTextAligned(iTextSharp.text.Element.ALIGN_BASELINE, "Cesar Mariñoas Asmat", 59f, 102.5f, 0);
                    oPdfContentByte.EndText();
                    oPdfContentByte.Stroke();

                    oPdfContentByte.Rectangle(385.5f, 40.5f, 150f, 72.5f);
                    oPdfContentByte.BeginText();
                    oPdfContentByte.SetFontAndSize(iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.WINANSI, iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED), (float)8);
                    oPdfContentByte.ShowTextAligned(iTextSharp.text.Element.ALIGN_BASELINE, "Firma del Cliente Titular", 430.5f, 122.5f, 0);
                    oPdfContentByte.EndText();
                    oPdfContentByte.Stroke();

                    if (!string.IsNullOrEmpty(pImg64))
                    {
                        iTextSharp.text.Image _imagen = iTextSharp.text.Image.GetInstance(ConvertStringBase64ToImage(oFirmaElectronicaModel.oFirmaElectronica.SIGSTRING_64));
                        _imagen.Border      = iTextSharp.text.Rectangle.NO_BORDER;
                        _imagen.BorderColor = iTextSharp.text.Color.WHITE;
                        _imagen.SetAbsolutePosition(385.5f, 55.8f);
                        _imagen.ScaleToFit(150f, 81.5f);

                        oDocument.Add(_imagen);
                    }
                    oDocument.Close();
                    b_Resultado = true;
                }
                #endregion
            }
            catch (Exception ex) { b_Resultado = false; }
            //
            return(b_Resultado);
        }
Exemplo n.º 6
0
    void CreateFromRawdataFile(string sourceTxtPath, string destinationPDFPath)
    {
        pdfdoc = new iTextSharp.text.Document();
        pdfdoc.SetPageSize(currentPageSize);

        gridCountInBlockRowHorizontal = (int)(currentPageSize.Width / gridSideLength);
        blockRowHeight         = gridSideLength * gridCountInBlockRowVertical;
        blockRowCount          = (int)(currentPageSize.Height / (blockRowHeight + blockRowInterval));
        rawDataCountInBlockRow = (int)(gridCountInBlockRowHorizontal * 40 * 512 / 1000);
        rawDataInterval        = currentPageSize.Width / rawDataCountInBlockRow;

        Debug.Log("gridCountInBlockRowHorizontal:" + gridCountInBlockRowHorizontal);
        Debug.Log("rawDataCountInBlockRow" + rawDataCountInBlockRow);

        if (File.Exists(destinationPDFPath))
        {
            File.Delete(destinationPDFPath);
        }

        pdfwriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfdoc, new FileStream(destinationPDFPath, FileMode.CreateNew));

        pdfdoc.Open();

        iTextSharp.text.pdf.PdfContentByte cb = pdfwriter.DirectContent;

        pdfdoc.NewPage();
        blockRowIndex = 0;
        rawDataIndex  = 0;

        iTextSharp.text.pdf.BaseFont font = iTextSharp.text.pdf.BaseFont.CreateFont();
        cb.SetFontAndSize(font, 60);
        cb.BeginText();
        cb.SetTextMatrix(100, currentPageSize.Height - 50);
        cb.ShowText("Test String .......");
        cb.EndText();

        System.IO.StreamReader reader = new StreamReader(sourceTxtPath);
        string theLine;
        int    rawData;

        while (!reader.EndOfStream)
        {
            theLine = reader.ReadLine();
            try{
                rawData = int.Parse(theLine);
            }catch (Exception e) {
                Debug.Log("Exception");
                continue;
            }

            rawData       = rawData > maxRawData ? maxRawData : rawData;
            rawData       = rawData < -maxRawData ? -maxRawData : rawData;
            scaledRawData = (rawData * (blockRowHeight / 2)) / maxRawData;

            if (rawDataIndex == 0)
            {
                currentBaseLine = currentPageSize.Height - (firstBlockRowOffsetInVertical + blockRowIndex * (blockRowHeight + blockRowInterval) + (blockRowHeight / 2));

                cb.SetColorStroke(iTextSharp.text.BaseColor.RED);

                //draw horizontal lines
                for (int i = 0; i <= gridCountInBlockRowVertical; i++)
                {
                    if (i % 5 == 0)
                    {
                        cb.SetLineWidth(2.5f);
                    }
                    else
                    {
                        cb.SetLineWidth(0.5f);
                    }
                    cb.MoveTo(0, currentPageSize.Height - (firstBlockRowOffsetInVertical + blockRowIndex * (blockRowHeight + blockRowInterval) + i * gridSideLength));
                    cb.LineTo(currentPageSize.Width, currentPageSize.Height - (firstBlockRowOffsetInVertical + blockRowIndex * (blockRowHeight + blockRowInterval) + i * gridSideLength));
                    cb.Stroke();
                }

                //draw vertical lines
                for (int j = 0; j <= gridCountInBlockRowHorizontal; j++)
                {
                    if (j % 5 == 0)
                    {
                        cb.SetLineWidth(2.5f);
                    }
                    else
                    {
                        cb.SetLineWidth(0.5f);
                    }
                    cb.MoveTo(j * gridSideLength, currentPageSize.Height - (firstBlockRowOffsetInVertical + blockRowIndex * (blockRowHeight + blockRowInterval)));
                    cb.LineTo(j * gridSideLength, currentPageSize.Height - (firstBlockRowOffsetInVertical + blockRowIndex * (blockRowHeight + blockRowInterval) + blockRowHeight));
                    cb.Stroke();
                }
                //prepare to draw ECG
                cb.SetLineWidth(1.5f);
                cb.SetColorStroke(iTextSharp.text.BaseColor.BLACK);

                cb.MoveTo(0, currentBaseLine);
            }

            cb.LineTo(rawDataIndex * rawDataInterval, currentBaseLine + scaledRawData);
            rawDataIndex++;
            if (rawDataIndex >= rawDataCountInBlockRow)
            {
                cb.Stroke();
                rawDataIndex = 0;
                blockRowIndex++;
            }
        }
        cb.Stroke();
        reader.Close();



        pdfdoc.Dispose();
        System.Diagnostics.Process.Start(destinationPDFPath);
    }