コード例 #1
0
        // ====================================================================================================
        // USEFULL MIGRADOC EXAMPLES ==========================================================================
        // ====================================================================================================

        static void SamplePage1(PdfDocument document)
        {
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH = PdfFontEncoding.Unicode;
            //gfx.MFEH = PdfFontEmbedding.Default;

            //XFont font = new XFont("Verdana", 13, XFontStyle.Bold);
            //gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black,
            //    new XRect(100, 100, page.Width - 200, 300), XStringFormats.Center);

            // You always need a MigraDoc document for rendering.
            Document doc = new Document();
            Section  sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            Paragraph para = sec.AddParagraph();

            para.Format.Alignment  = ParagraphAlignment.Justify;
            para.Format.Font.Name  = "Times New Roman";
            para.Format.Font.Size  = 12;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            para.AddText("Duisism odigna acipsum delesenisl ");
            para.AddFormattedText("ullum in velenit", TextFormat.Bold);
            para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " +
                         "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " +
                         "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " +
                         "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " +
                         "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠");
            para.Format.Borders.Distance = "5pt";
            para.Format.Borders.Color    = Colors.Gold;

            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para);
        }
コード例 #2
0
        public override PdfDocument ToPdf()
        {
            var watch = new Stopwatch();

            watch.Start();
            //http://www.pdfsharp.net/wiki/Unicode-sample.ashx
            // Create new document
            var document = new PdfDocument();

            var pdfString = "eXPRS Plan of Care - Services Delivered Report Form\n\n" +
                            "Timesheet ID: " + Id + "\n" +
                            "Status of Timesheet: " + Status + "\n" +
                            "Customer Name: " + ClientName + "\n" +
                            "Prime: " + ClientPrime + "\n" +
                            "Provider Name: " + ProviderName + "\n" +
                            "Provider Num: " + ProviderId + "\n" +
                            "CM Organization: Multnomah Case Management\n" +
                            "Form Type: " + FormType + "\n\n" +
                            "Service Goal: " + ServiceGoal + "\n\n" +
                            "Progress Notes: " + ProgressNotes + "\n\n" +
                            "Submitted on: " + Submitted + "\n";

            // Set font encoding to unicode
            var options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            var font = new XFont("Times New Roman", 12, XFontStyle.Regular, options);


            var page = document.AddPage();
            var gfx  = XGraphics.FromPdfPage(page);
            var tf   = new XTextFormatter(gfx)
            {
                Alignment = XParagraphAlignment.Left
            };

            tf.DrawString(pdfString, font, XBrushes.Black,
                          new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft);

            // TABLE
            var doc     = new Document();
            var section = doc.AddSection();
            var table   = section.AddTable();

            table.Style               = "Table";
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;

            // Before you can add a row, you must define the columns
            var column = table.AddColumn("2.5cm");

            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn("2.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn("3cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn("3.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn("2cm");
            column.Format.Alignment = ParagraphAlignment.Center;

            // Create the header of the table
            var row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = Colors.LightGreen;
            row.Cells[0].AddParagraph("Date");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].AddParagraph("Start/Time IN");
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[2].AddParagraph("End/Time OUT");
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[3].AddParagraph("Total hours for entry");
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[4].AddParagraph("Group? (yes/no)");
            row.Cells[4].Format.Alignment = ParagraphAlignment.Left;

            double totalHours = 0;

            foreach (var entry in TimeEntries)
            {
                row = table.AddRow();
                row.HeadingFormat    = true;
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Format.Font.Bold = true;
                row.Cells[0].AddParagraph(entry.Date.ToShortDateString());
                row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
                row.Cells[1].AddParagraph(entry.In.ToShortTimeString());
                row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                row.Cells[2].AddParagraph(entry.Out.ToShortTimeString());
                row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
                totalHours += entry.Hours;
                row.Cells[3].AddParagraph(entry.Hours.ToString(CultureInfo.CurrentCulture));
                row.Cells[3].Format.Alignment = ParagraphAlignment.Left;

                row.Cells[4].AddParagraph(entry.Group ? "Yes" : "No");
                row.Cells[4].Format.Alignment = ParagraphAlignment.Left;
            }

            row = table.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Cells[0].AddParagraph("Total");
            row.Cells[0].MergeRight       = 2;
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[3].AddParagraph(totalHours + " Hours");
            row.Cells[3].MergeRight       = 1;
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;

            table.SetEdge(0, 0, 5, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);

            // Create a renderer and prepare (=layout) the document
            var docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);

            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(13), "12cm", table);

            //END OF TABLE

            //This code section will add new pages with images.
            foreach (var uri in UriList)
            {
                using var wc       = new WebClient();
                using var objImage = XImage.FromStream(wc.OpenRead(uri));
                //do stuff with the image
                var newPage = document.AddPage();
                var gfx2    = XGraphics.FromPdfPage(newPage);
                gfx2.DrawImage(objImage, 0, 0, newPage.Width, newPage.Height);
            }

            watch.Stop();
            Console.WriteLine("Time to Generate PDF: " + watch.Elapsed.Seconds + "." + watch.Elapsed.Milliseconds + " seconds");
            return(document);
        }
コード例 #3
0
        public void GenerateReceipt(string filepath)
        {
            var document = new PdfDocument();

            PdfPage        page = document.AddPage();
            XGraphics      gfx  = XGraphics.FromPdfPage(page);
            XTextFormatter tf   = new XTextFormatter(gfx);

            Document doc = new Document();
            Section  s   = doc.AddSection();
            Table    receipt;
            Column   c;
            Row      r;

            receipt = s.AddTable();
            receipt.Format.Font.Name = "Arial";
            receipt.Format.Font.Size = new Unit(12, UnitType.Point);
            receipt.Borders.Width    = 0;
            receipt.Style            = "Table";
            receipt.BottomPadding    = new Unit(10, UnitType.Point);

            c = receipt.AddColumn(new Unit(60, UnitType.Point));
            c = receipt.AddColumn(new Unit(125, UnitType.Point));
            c.Format.Alignment = ParagraphAlignment.Right;
            c = receipt.AddColumn(new Unit(225, UnitType.Point));
            c.Format.Alignment = ParagraphAlignment.Left;
            c = receipt.AddColumn(new Unit(60, UnitType.Point));
            c.Format.Alignment = ParagraphAlignment.Right;

            r = receipt.AddRow();
            r.BottomPadding             = 0;
            r.Cells[2].MergeRight       = 1;
            r.Cells[2].Format.Font.Size = new Unit(7, UnitType.Point);
            r.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            r.Cells[2].AddParagraph(string.Format("Gerado em: {0}", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")));

            r = receipt.AddRow();
            r.Borders.Top.Width            = 1;
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.TopPadding = new Unit(10, UnitType.Point);
            var krav_maga_moema_logo = r.Cells[0].AddImage(AppDomain.CurrentDomain.BaseDirectory + "logo_krav_maga_moema.jpg");

            krav_maga_moema_logo.Height          = new Unit(40, UnitType.Point);
            krav_maga_moema_logo.LockAspectRatio = true;

            var krav_maga_sa_logo = r.Cells[3].AddImage(AppDomain.CurrentDomain.BaseDirectory + "logo_kravmaga.png");

            krav_maga_sa_logo.Height          = new Unit(40, UnitType.Point);
            krav_maga_sa_logo.LockAspectRatio = true;

            r.Format.Font.Bold             = true;
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Format.Alignment             = ParagraphAlignment.Center;
            r.Format.Font.Size             = new Unit(15, UnitType.Point);
            r.Cells[1].MergeRight          = 1;
            r.Cells[1].AddParagraph("RECIBO DE PAGAMENTO");

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Nome do Aluno:");
            r.Cells[2].MergeRight = 1;
            r.Cells[2].AddParagraph(receiptInfo.StudentName.ToUpper());

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Valor do Pagamento:");
            r.Cells[2].AddParagraph(receiptInfo.PaymentValue.ToString("R$ 0,0.00"));

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Data do Pagamento:");
            r.Cells[2].AddParagraph(receiptInfo.PaymentDate.ToString("dd/MM/yyyy"));

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Tipo do Pagamento:");
            r.Cells[2].AddParagraph(receiptInfo.PaymentType.ToUpper());
            r.Borders.Bottom.Width = 1;

            MigraDoc.Rendering.DocumentRenderer docRender = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRender.PrepareDocument();

            docRender.RenderObject(gfx, XUnit.FromPoint(50), XUnit.FromPoint(30), XUnit.FromPoint(470), receipt);

            document.Save(filepath);
        }
コード例 #4
0
        //Se houverem dúvidas, há duas páginas de exemplo oficial do PDFSHarp após esse método.
        protected void ReportPage1(PdfDocument document)
        {
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            gfx.MUH = PdfFontEncoding.Unicode;

            // You always need a MigraDoc document for rendering.
            Document doc = new Document();

            Section sec = doc.AddSection();

            Paragraph image = sec.AddParagraph();

            image.Format.Alignment = ParagraphAlignment.Right;
            Image imagem = image.AddImage("logo.png");

            imagem.Height          = "1.5cm";
            imagem.LockAspectRatio = true;

            Paragraph para1 = sec.AddParagraph();

            para1.Format.Alignment  = ParagraphAlignment.Center;
            para1.Format.Font.Name  = "Arial";
            para1.Format.Font.Size  = 14;
            para1.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            para1.AddFormattedText("RELATÓRIO FINAL DA AVALIAÇÃO DE EXEMPLO DE USO DO MIGRADOC", TextFormat.Bold);
            para1.Format.Borders.Distance = "5pt";

            // Tabela da Fase I
            Table table1 = sec.AddTable();

            table1.Style                  = "Table";
            table1.Format.Font.Size       = 9;
            table1.Borders.Color          = MigraDoc.DocumentObjectModel.Color.FromRgb(100, 100, 100);
            table1.Borders.Width          = 0.5;
            table1.Borders.Left.Width     = 0.5;
            table1.Borders.Right.Width    = 0.5;
            table1.Rows.LeftIndent        = 0;
            table1.BottomPadding          = Unit.FromCentimeter(0.1);
            table1.TopPadding             = Unit.FromCentimeter(0.1);
            table1.LeftPadding            = Unit.FromCentimeter(0.2);
            table1.RightPadding           = Unit.FromCentimeter(0.2);
            table1.Rows.Alignment         = RowAlignment.Left;
            table1.Rows.VerticalAlignment = VerticalAlignment.Top;

            // Before you can add a row, you must define the columns
            Column column = table1.AddColumn("4.25cm");

            column = table1.AddColumn("4.25cm");
            column = table1.AddColumn("4.25cm");
            column = table1.AddColumn("4.25cm");

            // Create the header of the table
            Row row = table1.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("I - IDENTIFICAÇÃO DO FUNCIONÁRIO");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table1.AddRow();
            row.Cells[0].AddParagraph("Nome");
            row.Cells[0].AddParagraph(this.Model.Nome);
            row.Cells[0].MergeRight = 1;
            row.Cells[2].AddParagraph("Cargo");
            row.Cells[2].AddParagraph(this.Model.Cargo);
            row.Cells[3].AddParagraph("Matrícula");
            row.Cells[3].AddParagraph(this.Model.Matricula);

            row = table1.AddRow();
            row.Cells[0].AddParagraph("Filial");
            row.Cells[0].AddParagraph(this.Model.Filial);
            row.Cells[0].MergeRight = 1;
            row.Cells[2].AddParagraph("Setor");
            row.Cells[2].AddParagraph(this.Model.Setor);
            row.Cells[3].AddParagraph("Data Admissão");
            row.Cells[3].AddParagraph(this.Model.DataAdmissao);

            row = table1.AddRow();
            row.Cells[0].AddParagraph(" ");
            row.Cells[0].MergeRight = 3;
            row.Borders.Visible     = false;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("II - RESULTADO FINAL");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("ETAPA");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeDown         = 1;
            row.Cells[1].AddParagraph("PERÍODO");
            row.Cells[1].Format.Font.Bold  = false;
            row.Cells[1].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[1].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[1].MergeRight        = 1;
            row.Cells[3].AddParagraph("RESULTADO DA AVALIAÇÃO (RA)");
            row.Cells[3].Format.Font.Bold  = false;
            row.Cells[3].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[3].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[3].MergeDown         = 1;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[1].AddParagraph("DATA INÍCIO");
            row.Cells[1].Format.Font.Bold  = false;
            row.Cells[1].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[1].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[2].AddParagraph("DATA FIM");
            row.Cells[2].Format.Font.Bold  = false;
            row.Cells[2].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[2].VerticalAlignment = VerticalAlignment.Center;

            foreach (var item in this.Model.ResultadosAvaliacao)
            {
                row = table1.AddRow();
                row.Cells[0].AddParagraph(item.NomeEtapa);
                row.Cells[1].AddParagraph(item.DataInicioEtapa);
                row.Cells[1].Format.Alignment = ParagraphAlignment.Center;
                row.Cells[2].AddParagraph(item.DataFimEtapa);
                row.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                row.Cells[3].AddParagraph(item.ResultadoEtapa);
                row.Cells[3].Format.Alignment = ParagraphAlignment.Right;
            }

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("RESULTADO FINAL = [(RAE1) + (RAE2) + (RAE3) + (RAE4)]/4");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 2;
            row.Cells[3].AddParagraph(this.Model.ResultadoFinal);
            row.Cells[3].Format.Font.Bold  = false;
            row.Cells[3].Format.Alignment  = ParagraphAlignment.Right;
            row.Cells[3].VerticalAlignment = VerticalAlignment.Center;

            row = table1.AddRow();
            row.Cells[0].AddParagraph(" ");
            row.Cells[0].MergeRight = 3;
            row.Borders.Visible     = false;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("III - CONCLUSÃO");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table1.AddRow();
            row.Format.Alignment = ParagraphAlignment.Justify;
            row.Cells[0].AddParagraph("ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " +
                                      "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " +
                                      "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " +
                                      "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet.");
            row.Cells[0].AddParagraph(" ");
            row.Cells[0].AddParagraph((this.Model.Conclusao ? "APTO" : "INAPTO") + " a ser efetivado no serviço público.");
            row.Cells[0].MergeRight = 3;

            row = table1.AddRow();
            row.Cells[0].AddParagraph(" ");
            row.Cells[0].MergeRight = 3;
            row.Borders.Visible     = false;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("IV - MEMBROS AVALIADORES");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("NOME");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 1;
            row.Cells[2].AddParagraph("MATRÍCULA");
            row.Cells[2].Format.Font.Bold  = false;
            row.Cells[2].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[2].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[3].AddParagraph("ASSINATURA");
            row.Cells[3].Format.Font.Bold  = false;
            row.Cells[3].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[3].VerticalAlignment = VerticalAlignment.Center;

            foreach (var item in this.Model.MembrosComissao)
            {
                row = table1.AddRow();
                row.Cells[0].AddParagraph(item.NomeMembroComissao);
                row.Cells[0].MergeRight = 1;
                row.Cells[2].AddParagraph(item.MatriculaMembroComissao);
                row.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                row.Cells[3].AddParagraph(" ");
            }

            row = table1.AddRow();
            row.Cells[0].AddParagraph(" ");
            row.Cells[0].MergeRight = 3;
            row.Borders.Visible     = false;

            row = table1.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200);
            row.Cells[0].AddParagraph("V - DE ACORDO GERENTE");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table1.AddRow();
            row.Cells[0].AddParagraph("DE ACORDO.");
            row.Cells[0].AddParagraph("AO RH, PARA PROVIDÊNCIAS.");
            row.Cells[0].AddParagraph(" ");
            row.Cells[0].Format.Borders.Bottom.Color = MigraDoc.DocumentObjectModel.Color.FromRgb(255, 255, 255);
            row.Cells[0].MergeRight = 3;

            row = table1.AddRow();
            row.Cells[0].AddParagraph("_______________________________");
            row.Cells[0].AddParagraph("Data");
            row.Cells[0].Format.Alignment           = ParagraphAlignment.Center;
            row.Cells[0].Format.Borders.Top.Color   = MigraDoc.DocumentObjectModel.Color.FromRgb(255, 255, 255);
            row.Cells[0].Format.Borders.Right.Color = MigraDoc.DocumentObjectModel.Color.FromRgb(255, 255, 255);
            row.Cells[0].MergeRight = 1;
            row.Cells[2].AddParagraph("_______________________________");
            row.Cells[2].AddParagraph("Assinatura");
            row.Cells[2].Format.Alignment          = ParagraphAlignment.Center;
            row.Cells[0].Format.Borders.Top.Color  = MigraDoc.DocumentObjectModel.Color.FromRgb(255, 255, 255);
            row.Cells[0].Format.Borders.Left.Color = MigraDoc.DocumentObjectModel.Color.FromRgb(255, 255, 255);
            row.Cells[2].MergeRight = 1;


            table1.SetEdge(0, 0, 3, 3, Edge.Box, BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Color.FromRgb(200, 200, 200));

            // Create footer
            Paragraph paragraph = sec.Footers.Primary.AddParagraph();

            paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            paragraph.AddText("_____________________________ \n");
            paragraph.AddText("Av. XYZ, 23 - CEP 60.000-000 \n");
            paragraph.AddText("Fortaleza, Ceará, Brasil \n");
            paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            paragraph.AddText("(85) 0101.0101 - FAX: (85) 3232.3232");
            paragraph.Format.Font.Size = 8;
            paragraph.Format.Alignment = ParagraphAlignment.Center;

            // Render the paragraph. You can render tables or shapes the same way.
            MigraDoc.Rendering.DocumentRenderer docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(2), XUnit.FromCentimeter(1.5), "17cm", image);
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(2), XUnit.FromCentimeter(3), "17cm", para1);
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(2), XUnit.FromCentimeter(5), "17cm", table1);
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(2), XUnit.FromCentimeter(27.5), "17cm", paragraph);
        }
コード例 #5
0
        public override PdfDocument ToPdf()
        {
            //http://www.pdfsharp.net/wiki/Unicode-sample.ashx
            // Create new document
            var document = new PdfDocument();

            var pdfString = "eXPRS Plan of Care - Services Delivered Report Form\n\n" +
                            "Timesheet ID: " + Id + "\n" +
                            "Status of Timesheet: " + Status + "\n" +
                            "Customer Name: " + ClientName + "\n" +
                            "Prime: " + ClientPrime + "\n" +
                            "Provider Name: " + ProviderName + "\n" +
                            "Provider Num: " + ProviderId + "\n" +
                            "CM Organization: Multnomah Case Management\n" +
                            "Form Type: " + FormType + "\n\n" +
                            "Service Goal: " + ServiceGoal + "\n\n" +
                            "Progress Notes: " + ProgressNotes + "\n\n" +
                            "Submitted on: " + Submitted + "\n";

            // Set font encoding to unicode
            var options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            var font = new XFont("Times New Roman", 12, XFontStyle.Regular, options);


            var page = document.AddPage();
            var gfx  = XGraphics.FromPdfPage(page);
            var tf   = new XTextFormatter(gfx)
            {
                Alignment = XParagraphAlignment.Left
            };

            tf.DrawString(pdfString, font, XBrushes.Black,
                          new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft);

            // TABLE
            var doc     = new Document();
            var section = doc.AddSection();
            var table   = section.AddTable();

            table.Style               = "Table";
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;

            // Before you can add a row, you must define the columns
            var column = table.AddColumn("2.5cm");

            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn("2.5cm");
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn("2.5cm");
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn("8cm");
            column.Format.Alignment = ParagraphAlignment.Center;

            // Create the header of the table
            var row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = Colors.LightGreen;
            row.Cells[0].AddParagraph("Date");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].AddParagraph("Total Miles for Date");
            row.Cells[1].Format.Alignment = ParagraphAlignment.Center;
            row.Cells[2].AddParagraph("Group? Yes/No");
            row.Cells[2].Format.Alignment = ParagraphAlignment.Center;
            row.Cells[3].AddParagraph("Purpose of Trip/Service Goal");
            row.Cells[3].Format.Alignment = ParagraphAlignment.Center;

            double totalMiles = 0;

            foreach (var entry in MileageEntries)
            {
                row = table.AddRow();
                row.HeadingFormat    = true;
                row.Format.Alignment = ParagraphAlignment.Center;
                row.Format.Font.Bold = true;
                row.Cells[0].AddParagraph(entry.Date.ToShortDateString());
                row.Cells[0].Format.Alignment = ParagraphAlignment.Center;
                row.Cells[1].AddParagraph(entry.Miles.ToString(CultureInfo.CurrentCulture));
                row.Cells[1].Format.Alignment = ParagraphAlignment.Center;
                totalMiles += entry.Miles;
                row.Cells[2].AddParagraph(entry.Group ? "Yes" : "No");
                row.Cells[2].Format.Alignment = ParagraphAlignment.Center;
                row.Cells[3].AddParagraph(entry.PurposeOfTrip);
                row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
            }

            row = table.AddRow();
            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Cells[0].AddParagraph("Total");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            row.Cells[1].AddParagraph(totalMiles + " Miles");
            row.Cells[1].MergeRight       = 2;
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            table.SetEdge(0, 0, 4, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);

            // Create a renderer and prepare (=layout) the document
            var docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc);

            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(13), "12cm", table);

            //END OF TABLE

            // TODO: Adding images takes far too long. It takes about ~0.7s per image
            // This means download ~1,600 PDFs with 2 images each takes ~45 minutes just to render : (
            // Make this faster
            //This code section will add new pages with images.
            foreach (var uri in UriList)
            {
                using var wc       = new WebClient();
                using var objImage = XImage.FromStream(new MemoryStream(wc.DownloadData(uri)));
                //do stuff with the image
                var newPage = document.AddPage();
                var gfx2    = XGraphics.FromPdfPage(newPage);
                gfx2.DrawImage(objImage, 0, 0, newPage.Width, newPage.Height);
            }
            return(document);
        }