Esempio n. 1
0
        public void Generate(List <Factor> factors)
        {
            Document document = new Document();


            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));

            document.Open();
            foreach (var factor in factors)
            {
                Paragraph p = new Paragraph(factor.ToString());
                document.Add(p);
                RomanList romanList = new RomanList(true, 20);
                romanList.IndentationLeft = 15;
                foreach (var detail in factor.FactorDetails)
                {
                    romanList.Add(detail.ToString());
                }
                document.Add(romanList);
            }

            /*iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5);
             *
             * PdfPTable table = new PdfPTable(dt.Columns.Count);
             * PdfPRow row = null;
             * float[] widths = new float[] { 2f, 2f,2f};
             *
             * table.SetWidths(widths);
             *
             * table.WidthPercentage = 100;
             * int iCol = 0;
             * string colname = "";
             * PdfPCell cell = new PdfPCell(new Phrase("Factors"));
             *
             * cell.Colspan = dt.Columns.Count;
             *
             * foreach (DataColumn c in dt.Columns)
             * {
             *
             *  table.AddCell(new Phrase(c.ColumnName, font5));
             * }
             *
             * foreach (DataRow r in dt.Rows)
             * {
             *  if (dt.Rows.Count > 0)
             *  {
             *      table.AddCell(new Phrase(r[0].ToString(), font5));
             *      table.AddCell(new Phrase(r[1].ToString(), font5));
             *      table.AddCell(new Phrase(r[2].ToString(), font5));
             *      table.AddCell(new Phrase(r[3].ToString(), font5));
             *  }
             * }*/
            //document.Add(table);
            document.Close();
        }
Esempio n. 2
0
        public ActionResult Pdf(FormCollection form)
        {
            Document  doc = new Document(new iTextSharp.text.Rectangle(288f, 144f), 10, 10, 10, 10);                 //yeni bir döküman oluşturuyoruz.
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(sinavım.SınavTipi + ".pdf", FileMode.Create)); // dosyamıza bir ad veriyoruz ve yazılabilir hale getiriyoruz.

            doc.SetPageSize(iTextSharp.text.PageSize.A4);                                                            //pdfin ebatlarını belirliyoruz.
            doc.Open();                                                                                              //dosyayla olan bağlantıyı açıyoruz ve böylelikle artık içerisine bir şeyler yazabilir hale getiriyoruz.
            Paragraph paragraf = new Paragraph("Trakya Üniversitesi" + "Bilgisayar Mühendisliği" + sinavım.DersAdi + sinavım.SınavTipi + "Sınavı");

            doc.Add(paragraf);
            RomanList roman = new RomanList(true, 20);

            roman.IndentationLeft = 30f;
            foreach (var item in sinavım.SinavKagıdı)
            {
                if (item.Sorular.Sturu == "Test")
                {
                    roman.Add(item.Sorular.Smetni);
                    roman.Add(item.Cevaplar.A);
                    roman.Add(item.Cevaplar.B);
                    roman.Add(item.Cevaplar.C);
                    roman.Add(item.Cevaplar.D);
                    roman.Add(item.Cevaplar.E);
                }
                else
                {
                    roman.Add(item.Sorular.Smetni);
                }
            }
            List list = new List(List.ORDERED, 40f);

            list.IndentationLeft = 40f;
            list.Add(roman);
            doc.Add(list);
            doc.Close();
            System.Diagnostics.Process.Start(@sinavım.SınavTipi + ".pdf");
            return(View());
        }
Esempio n. 3
0
        //Creating the pdf document using the data from the datagridview
        public static void createPDFDocument(DataGridView d)
        {
            Document  doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
            PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("test.pdf", FileMode.Create));

            doc.Open();
            iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("pic.jpg");
            //png.ScalePercent(200);//sizing
            png.ScaleToFit(50f, 70f);
            png.Border      = iTextSharp.text.Rectangle.BOX;
            png.BorderColor = iTextSharp.text.BaseColor.YELLOW;
            png.BorderWidth = 3;

            //png.SetAbsolutePosition(doc.PageSize.Width - 36f - 72f, doc.PageSize.Width - 40f - 72f);//positioning
            doc.Add(png);

            Paragraph p = new Paragraph("This is my test document");

            doc.Add(p);

            //create and add a list to the pdf file
            List list = new List(List.UNORDERED);

            //other list type: RomanList
            list.IndentationLeft = 30f;
            list.Add("one");
            list.Add("twoo");
            list.Add("three");
            list.Add("four");

            RomanList rl = new RomanList(true, 20);

            rl.Add("one");
            rl.Add("twoo");
            rl.Add("List");
            rl.Add(list);
            rl.Add("four");


            doc.Add(rl);
            PdfPTable t = new PdfPTable(3);

            // The bellow code is for adding a normala table to the pdf
            //PdfPCell cell = new PdfPCell(new Phrase("this is a phare"));
            //cell.Colspan = 3;
            //cell.HorizontalAlignment = 1; // 0-left, 1-centre, 2 right
            //cell.BackgroundColor = new iTextSharp.text.BaseColor(0, 150, 0);
            //t.AddCell(cell);
            //t.AddCell("col 2 row 1");
            //t.AddCell("col 3 row 1");
            //t.AddCell("col 1 row 2");
            //t.AddCell("col 2 row 2");
            //t.AddCell("col 3 row 2");
            //doc.Add(t);

            //loading tha table
            if (d.Columns.Count == 0)
            {
                MessageBox.Show("load the table first stupid, or it will throw an exception and the table will not be loaded");
            }
            else
            {
                PdfPTable ta = new PdfPTable(d.Columns.Count);
                for (int j = 0; j < d.Columns.Count; j++)
                {
                    ta.AddCell(new Phrase(d.Columns[j].HeaderText));
                }
                ta.HeaderRows = 1;

                for (int i = 0; i < d.Columns.Count; i++)
                {
                    for (int k = 0; k < d.Columns.Count; k++)
                    {
                        if (d[k, i].Value != null)
                        {
                            ta.AddCell(new Phrase(d[k, i].Value.ToString()));
                        }
                    }
                }
                doc.Add(ta);
                //Opening the PDF file
                System.Diagnostics.Process.Start("test.pdf");
            }



            doc.Close();
        }
Esempio n. 4
0
        public IActionResult ArquivoMemoria()
        {
            Document     doc    = new Document(PageSize.A4, 100, 70, 100, 70);
            MemoryStream stream = new MemoryStream();
            PdfWriter    pdf    = PdfWriter.GetInstance(doc, stream);

            pdf.CloseStream = false;

            var fonteTitulo     = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16);
            var fonte12         = FontFactory.GetFont(FontFactory.HELVETICA, 12);
            var fonte12Bold     = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
            var fonte12Azul     = FontFactory.GetFont(FontFactory.HELVETICA, 12, BaseColor.Blue);
            var fonte20Vermelho = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 20, BaseColor.Red);

            TwoColumnHeaderFooter cabecalhoRodape = new TwoColumnHeaderFooter();

            pdf.PageEvent               = cabecalhoRodape;
            cabecalhoRodape.Title       = "AULA SOBRE iTEXTSHARP";
            cabecalhoRodape.HeaderLeft  = "UNOESTE";
            cabecalhoRodape.HeaderRight = "FIPP";
            cabecalhoRodape.HeaderFont  = fonte20Vermelho;

            doc.Open();


            Paragraph linhaBranco = new Paragraph(" ");

            Uri   urlImagemUnoeste = new Uri("http://www.unoeste.br/Content/imagens/imgpadrao.jpg");
            Image imgUnoeste       = Image.GetInstance(urlImagemUnoeste);

            imgUnoeste.ScalePercent(30);
            //Para acessibilidade
            //Ainda não preparado para o .net core (itextsharp)
            //var c = new Chunk(imgUnoeste, 0, -24);
            //c.setAccessibleAttribute(PdfName.Alt, new PdfString("Logo da Unoeste"));

            string caminhoImgFusca = _env.WebRootPath + "\\imagens\\fusca.jpg";
            Image  imgFusca        = Image.GetInstance(caminhoImgFusca);

            imgFusca.ScaleAbsoluteWidth(50);
            imgFusca.ScaleAbsoluteHeight(32);
            imgFusca.SetAbsolutePosition(doc.PageSize.Width - 100,
                                         doc.PageSize.Height - 50);

            Paragraph pTitulo1 = new Paragraph("UNOESTE - Universidade do Oeste Paulista", fonteTitulo);

            doc.Add(pTitulo1);

            Paragraph pTitulo2 = new Paragraph("FIPP - Faculdade de Informática de Presidente Prudente", fonteTitulo);

            doc.Add(pTitulo2);

            doc.Add(imgUnoeste);

            for (int i = 1; i <= 10; i++)
            {
                Paragraph p = new Paragraph("Conteúdo da linha: " + i, fonte12);
                doc.Add(p);
            }

            doc.Add(linhaBranco);

            doc.Add(imgFusca);


            Phrase frase = new Phrase();

            frase.Add(new Chunk("Olá ", fonte12));
            frase.Add(new Chunk("FULANO DE TAL ", fonte12Azul));
            frase.Add(new Chunk("hoje é segunda-feira", fonte12Bold));
            doc.Add(frase);



            PdfPTable tabela = new PdfPTable(3);

            tabela.WidthPercentage = 100;

            PdfPCell celulaTitulo = new PdfPCell(new Phrase("TÍTULO DA TABELA", fonte12Bold));

            celulaTitulo.Colspan             = 3;
            celulaTitulo.HorizontalAlignment = 1;
            celulaTitulo.BackgroundColor     = new BaseColor(System.Drawing.Color.FloralWhite);
            celulaTitulo.MinimumHeight       = 35;

            tabela.AddCell(celulaTitulo);

            tabela.AddCell("Linha 1 x Coluna 1");
            tabela.AddCell("Linha 1 x Coluna 2");
            tabela.AddCell("Linha 1 x Coluna 3");

            tabela.AddCell("Linha 2 x Coluna 1");
            tabela.AddCell(imgUnoeste);
            tabela.AddCell("Linha 2 x Coluna 3");

            tabela.AddCell(celulaTitulo);

            tabela.AddCell("Linha 3 x Coluna 1");
            tabela.AddCell("Linha 3 x Coluna 2");
            tabela.AddCell("Linha 3 x Coluna 3");

            doc.Add(tabela);


            doc.NewPage();

            List lista1 = new List(List.LOWERCASE);

            lista1.Add("Fusca");
            lista1.Add("Passat Pointer");
            lista1.Add("SP2");
            lista1.Add("Variant");
            lista1.Add("Brasilia");

            doc.Add(linhaBranco);
            doc.Add(lista1);

            List lista2 = new List(List.ALPHABETICAL, true);

            lista2.Add("Fusca");
            lista2.Add("Passat Pointer");
            lista2.Add("SP2");
            lista2.Add("Variant");
            lista2.Add("Brasilia");

            doc.Add(linhaBranco);
            doc.Add(lista2);

            List lista3 = new List(List.UNORDERED);

            lista3.Add("Fusca");
            lista3.Add("Passat Pointer");
            lista3.Add("SP2");
            lista3.Add("Variant");
            lista3.Add("Brasilia");

            doc.Add(linhaBranco);
            doc.Add(lista3);

            List lista4 = new List(List.ORDERED, 15);

            lista4.Add("Fusca");
            lista4.Add("Passat Pointer");
            lista4.Add(lista3);
            lista4.Add("SP2");
            lista4.Add("Variant");
            lista4.Add("Brasilia");

            doc.Add(linhaBranco);
            doc.Add(lista4);

            RomanList lista5 = new RomanList(true, 15);

            lista5.Add("Fusca");
            lista5.Add("Passat Pointer");
            lista5.Add("SP2");
            lista5.Add(lista4);
            lista5.Add("Variant");
            lista5.Add("Brasilia");

            doc.Add(linhaBranco);
            doc.Add(lista5);

            doc.Close();
            stream.Flush();
            stream.Position = 0;

            return(File(stream, "application/pdf", "Contrato-Memoria.pdf"));
        }
Esempio n. 5
0
        // ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document())
            {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                var SQL =
                    @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c
FROM film_country c, film_movie_country mc
WHERE c.id = mc.country_id
GROUP BY mc.country_id, country ORDER BY c DESC";
                // Create a list for the countries
                List list = new RomanList();
                // loop over the countries
                using (var c = AdoDB.Provider.CreateConnection())
                {
                    c.ConnectionString = AdoDB.CS;
                    using (DbCommand cmd = c.CreateCommand())
                    {
                        cmd.CommandText = SQL;
                        c.Open();
                        using (var r = cmd.ExecuteReader())
                        {
                            while (r.Read())
                            {
                                // create a list item for the country
                                ListItem item = new ListItem(
                                    string.Format("{0}: {1} movies",
                                                  r["country"].ToString(), r["c"].ToString()
                                                  )
                                    );
                                // Create a list for the movies
                                List movielist = new GreekList();
                                movielist.Lowercase = List.LOWERCASE;
                                // Loop over the movies
                                foreach (Movie movie in
                                         PojoFactory.GetMovies(r["country_id"].ToString())
                                         )
                                {
                                    ListItem movieitem = new ListItem(movie.MovieTitle);
                                    // Create a list for the directors
                                    List directorlist = new ZapfDingbatsNumberList(0);
                                    // Loop over the directors
                                    foreach (Director director in movie.Directors)
                                    {
                                        directorlist.Add(String.Format("{0}, {1}",
                                                                       director.Name, director.GivenName
                                                                       ));
                                    }
                                    movieitem.Add(directorlist);
                                    movielist.Add(movieitem);
                                }
                                item.Add(movielist);
                                list.Add(item);
                            }
                            document.Add(list);
                        }
                    }
                }
            }
        }
        public void NestedListAtTheEndOfAnotherNestedList()
        {
            String pdfFile = "nestedListAtTheEndOfAnotherNestedList.pdf";
            // step 1
            Document document = new Document();

            // step 2
            PdfWriter.GetInstance(document, File.Create(DEST_FOLDER + pdfFile));
            // step 3
            document.Open();
            // step 4
            PdfPTable table = new PdfPTable(1);
            PdfPCell  cell  = new PdfPCell();

            cell.BackgroundColor = BaseColor.ORANGE;

            RomanList romanlist = new RomanList(true, 20);

            romanlist.IndentationLeft = 10f;
            romanlist.Add("One");
            romanlist.Add("Two");
            romanlist.Add("Three");

            RomanList romanlist2 = new RomanList(true, 20);

            romanlist2.IndentationLeft = 10f;
            romanlist2.Add("One");
            romanlist2.Add("Two");
            romanlist2.Add("Three");

            romanlist.Add(romanlist2);
            //romanlist.add("Four");

            List list = new List(List.ORDERED, 20f);

            list.SetListSymbol("\u2022");
            list.IndentationLeft = 20f;
            list.Add("One");
            list.Add("Two");
            list.Add("Three");
            list.Add("Four");
            list.Add("Roman List");
            list.Add(romanlist);

            list.Add("Five");
            list.Add("Six");

            cell.AddElement(list);
            table.AddCell(cell);
            document.Add(table);
            // step 5
            document.Close();

            CompareTool compareTool = new CompareTool();
            String      error       = compareTool.CompareByContent(DEST_FOLDER + pdfFile, SOURCE_FOLDER + pdfFile, DEST_FOLDER, "diff_");

            if (error != null)
            {
                Assert.Fail(error);
            }
        }