예제 #1
0
        private void SaveToPdf()
        {
            if (groceryListTB.Text == String.Empty)
            {
                MessageBox.Show("No items in grocery list", "Empty List");
                return;
            }

            // Create a Document object to write to the PDF
            using (Document doc = new Document(iTextSharp.text.PageSize.LETTER, 28, 28, 16, 16))
            {
                // Create an instance of PDF Writer, write the doc object to a file using a FileStream
                if (File.Exists("Grocery List.pdf"))
                {
                    File.Delete("Grocery List.pdf");
                }
                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("Grocery List.pdf", FileMode.Create));

                // Use a font that can write Chinese text
                //string fontpath = @"C:\Users\User\source\repos\GroceryListGenerator2\GroceryListGenerator2\";
                BaseFont             customFont = BaseFont.CreateFont("msjh_0.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                iTextSharp.text.Font font       = new iTextSharp.text.Font(customFont, 14);

                // Write the text to the PDF document
                Paragraph listToPrint = new Paragraph(groceryListTB.Text, font);
                doc.Open();
                doc.Add(listToPrint);
            }

            CreatePrintPreview();
            printBttn.Enabled = true;
            printBttn.Visible = true;
            infoBttn.Enabled  = true;
            infoBttn.Visible  = true;
        }
예제 #2
0
        private void BuExport_Click(object sender, EventArgs e)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var enc1252 = Encoding.GetEncoding(1252);

            string ttf = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");
            var baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            var font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);
            var fontParag = new iTextSharp.text.Font(baseFont, 20);
            var fontTitle = new iTextSharp.text.Font(baseFont, 24);

            Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);

            //string pdfFilePath = @"D:/";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string pdfFilePath = saveFileDialog1.FileName + ".pdf";

                var fs = new FileStream(pdfFilePath, FileMode.Create);

                doc.NewPage();
                var writer = PdfWriter.GetInstance(doc, fs);

                doc.Open();
                doc.NewPage();

                using (var stream = new FileStream("Test.pdf", FileMode.Create))
                {
                    PdfWriter.GetInstance(doc, stream);
                    doc.Open();

                    doc.Add(new Paragraph($"{richTB.Text}", font));

                    doc.Close();
                }
            }

            

            MessageBox.Show("Файл сохранен");
        }
예제 #3
0
        public void MakePdf()
        {
            string str1 = DateTime.Today.ToString("u");
            string str2 = str1.Replace(':', 's');
            string str3 = str2.Replace(',', 'd');
            //    string filname = DateTime.Today.ToString("");
            string        fileNamePrifix = customerNameBox.Text.Trim();
            string        final_fileName = fileNamePrifix + str3;
            string        dirctory       = Path.GetDirectoryName(@"C:\Users\Public\");
            DirectoryInfo df             = new DirectoryInfo(dirctory + @"\voucher\");

            if (df.Exists == false)
            {
                Directory.CreateDirectory(dirctory + @"\voucher\");
            }
            string filePath = df + final_fileName;


            Document  document = new Document(PageSize.A4, 75, 75, 75, 75);
            PdfWriter create   = PdfWriter.GetInstance(document, new FileStream(filePath + ".pdf", FileMode.Create));

            document.Open();

            // Font Entry
            BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            iTextSharp.text.Font hedingfont = new iTextSharp.text.Font(bf, 30, iTextSharp.text.Font.BOLD, BaseColor.BLUE);
            iTextSharp.text.Font smfont     = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            iTextSharp.text.Font thfont     = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            iTextSharp.text.Font tdfont     = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
            iTextSharp.text.Font signfont   = new iTextSharp.text.Font(bf, 11, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            signfont.SetColor(23, 45, 12);



            byte[] image = introduce.loadLogo();
            if (image != null)
            {
                Image logo = Image.GetInstance(image);
                logo.SetAbsolutePosition(40, 700);
                logo.ScaleAbsoluteWidth(70);
                logo.ScaleAbsoluteHeight(70);
                document.Add(logo);
            }



            // Customer Data
            Paragraph Header = new Paragraph();

            Header.Alignment = Element.ALIGN_CENTER;


            IntroduceModel introduction = introduce.GetInformation();

            if (introduction != null)
            {
                string instituteBox = introduction.InstituteName;
                string emailBox     = introduction.Email;
                string addresss     = introduction.Address;
                string web          = introduction.WebSite;
                string mobiles      = introduction.Mobile;
                string ownerName    = introduction.OwnerName;

                Header.Add(new Chunk(instituteBox, hedingfont));
                Header.Add(new Chunk("\n" + addresss, smfont));
                Header.Add(new Chunk("\nCell :" + mobiles + ", \n " + web + " , " + emailBox, smfont));
                document.Add(Header);
            }
            else
            {
                Header.Add(new Chunk("It is Your Institute Name", hedingfont));
                Header.Add(new Chunk("\nSomething Address text will visible here", smfont));
                Header.Add(new Chunk("\nCell : -9087948059830, \n Web: N/A, Email: N/A ", smfont));
                document.Add(Header);
            }

            DottedLineSeparator separator = new DottedLineSeparator();

            separator.LineWidth = 1f;
            Chunk linebreak = new Chunk(separator);

            document.Add(linebreak);


            string    customerName = customerNameBox.Text.Trim();
            string    address      = addressTextBox.Text.Trim();
            string    mobile       = mnumberBox.Text.Trim();
            Paragraph csdata       = new Paragraph();

            csdata.Alignment = Element.ALIGN_LEFT;
            csdata.Add(new Chunk("Customer Name : " + customerName + "\nAddress : " + address + "\nMabile Number : " + mobile + "\n Date : " + DateTime.Now.ToString("dd/MM/yyyy"), smfont));
            document.Add(csdata);
            DottedLineSeparator separator2 = new DottedLineSeparator();

            separator2.LineWidth = 1f;
            Chunk linebreak2 = new Chunk(separator2);

            document.Add(linebreak2);



            //Write the table
            float[]   columnWidths = { 1.5f, 7f, 2.2f, 4f };
            PdfPTable ItemsRecord  = new PdfPTable(columnWidths);

            ItemsRecord.DefaultCell.Column.Alignment = Element.ALIGN_CENTER;
            ItemsRecord.WidthPercentage           = 100;
            ItemsRecord.DefaultCell.PaddingBottom = 4f;
            ItemsRecord.AddCell(new Phrase("Sl", thfont));
            ItemsRecord.AddCell(new Phrase("Product  Description", thfont));
            ItemsRecord.AddCell(new Phrase("Quantity", thfont));
            ItemsRecord.AddCell(new Phrase("Net Price", thfont));
            //table Data
            var totalQuantity = listofStockOut.Sum(x => x.Quantity);
            var totalamount   = listofStockOut.Sum(x => x.Price).ToString(CultureInfo.CreateSpecificCulture("bn-BD"));
            int ci            = 0;
            int lc            = listofStockOut.Count;

            foreach (var items in listofStockOut)
            {
                if (ci <= lc)
                {
                    ci++;
                }
                ItemsRecord.AddCell(new Phrase(ci.ToString(), tdfont));
                ItemsRecord.AddCell(new Phrase(items.CatagoryName + " : " + items.ItemName + " Sl/Mo:" + items.Model, tdfont));
                ItemsRecord.AddCell(new Phrase(items.Quantity.ToString(), tdfont));
                ItemsRecord.AddCell(new Phrase(items.Price.ToString(), tdfont));
            }
            PdfPCell cell = new PdfPCell(new Phrase("Total :  ", tdfont));

            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.Colspan             = 2;
            ItemsRecord.AddCell(cell);
            ItemsRecord.AddCell(new Phrase(totalQuantity.ToString(), tdfont));
            ItemsRecord.AddCell(new Phrase(totalamount, tdfont));
            document.Add(ItemsRecord);
            document.Add(new Chunk("\n\n\n"));



            //Author
            Paragraph prgAuthor = new Paragraph();

            prgAuthor.Alignment       = Element.ALIGN_CENTER;
            prgAuthor.IndentationLeft = 250f;
            prgAuthor.Add(new Chunk("Received by", signfont));
            prgAuthor.Add(new Chunk("\n" + DateTime.Now.ToString("dd/MM/yyyy"), signfont));
            document.Add(prgAuthor);
            document.Add(new Chunk("\n\n\n"));
            DottedLineSeparator separator4 = new DottedLineSeparator();

            separator4.LineWidth = 1f;
            Chunk linebreak4 = new Chunk(separator4);

            document.Add(linebreak4);

            document.Add(new Chunk("\nN:B: \n"));

            DottedLineSeparator separator5 = new DottedLineSeparator();

            separator5.LineWidth = 1f;
            Chunk linebreak5 = new Chunk(separator5);

            document.Add(linebreak5);

            document.Add(new Chunk("\n"));
            document.Close();
            create.Close();
            System.Diagnostics.Process.Start(filePath + ".pdf");
        }
예제 #4
0
        /// <summary>
        /// Funcion que genera el reporte de las funciones isomórficas en PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            //Variables para escribir en el pdf
            PdfWriter writer;
            Document  doc = new Document(PageSize.LETTER);

            //Se llenan la lista de funciones cuando el número de vertices es > 9
            if (g1.lstVertices.Count > 9)
            {
                listaFunciones = PermutadorUtilities.getInstancia().funcionIsomorfica;
            }

            try
            {
                //Path en donde se escribira el archivo
                writer = PdfWriter.GetInstance(doc,
                                               new FileStream(Directory.GetCurrentDirectory() + "\\Funciones de " +
                                                              "Isomorfismo.pdf", FileMode.Create));

                //Autores del archivo
                doc.AddAuthor("Matemática Discreta II");
                doc.AddCreator("Alumnos de Matemática Discreta II");
                doc.Open();

                //Fuente del archivo
                iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(
                    iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.NORMAL
                    , BaseColor.BLACK);
                doc.Add(new Paragraph("Lista de funciones isomórficas - Matemática " +
                                      "Discreta II"));
                doc.Add(Chunk.NEWLINE);

                /* Se escriben todas las funciones isomorficas recorriendo la lista de
                 * funciones con un for. */

                for (int i = 0; i < listaFunciones.Count; i++)
                {
                    doc.Add(new Paragraph("Función Isomórfica No. " + (i + 1)));
                    PdfPTable tblIsomorfismo = new PdfPTable(2);
                    tblIsomorfismo.WidthPercentage = 100;

                    PdfPCell clGrafo1 = new PdfPCell(new Phrase("Grafo 1", _standardFont));
                    clGrafo1.BorderWidth       = 0;
                    clGrafo1.BorderWidthBottom = 0.75f;

                    PdfPCell clGrafo2 = new PdfPCell(new Phrase("Grafo 2", _standardFont));
                    clGrafo2.BorderWidth       = 0;
                    clGrafo2.BorderWidthBottom = 0.75f;

                    tblIsomorfismo.AddCell(clGrafo1);
                    tblIsomorfismo.AddCell(clGrafo2);

                    for (int j = 0; j < listaFunciones[i].V1.Count; j++)
                    {
                        clGrafo1 =
                            new PdfPCell(new Phrase((listaFunciones[i].V1[j].etiqueta).
                                                    ToString(), _standardFont));
                        clGrafo1.BorderWidth = 0;

                        clGrafo2 =
                            new PdfPCell(new Phrase((listaFunciones[i].V2[j].etiqueta).
                                                    ToString().ToLower(),
                                                    _standardFont));
                        clGrafo2.BorderWidth = 0;
                        tblIsomorfismo.AddCell(clGrafo1);
                        tblIsomorfismo.AddCell(clGrafo2);
                    }

                    doc.Add(tblIsomorfismo);
                    doc.Add(new LineSeparator());
                    doc.Add(new LineSeparator());
                    doc.Add(Chunk.NEWLINE);
                }

                //Se cierra el documento y el escribidor.
                doc.Close();
                writer.Close();
                btnGenerarPdf.Enabled = false;
            }
            catch (IOException file)
            {
                //Si se intenta generar un archivo cuando este esta abierto marca error
                MessageBox.Show("Cierre el archivo de isomórfismo que tiene abierto " +
                                "antes de generar uno nuevo.");
            }
            catch (UnauthorizedAccessException sinPermisos)
            {
                MessageBox.Show("Por favor para generar el PDF ejecuta la aplicación " +
                                "como administrador");
            }
        }
        public ActionResult MakePDF(StudentResult studentResult)
        {
            StudentDepartmentViewModel st = _studentManager.GetStudentInfoById(studentResult);

            string regNo      = st.RegistrationNo;
            string name       = st.StudentName;
            string email      = st.StudentEmail;
            string department = st.DepartmentName;

            using (MemoryStream ms = new MemoryStream())
            {
                List <StudentResultViewModel> studentResultViewModels = _studentManager.GetStudentResult(studentResult);
                PdfPTable table = new PdfPTable(3);

                table.WidthPercentage = 100.0f;
                table.AddCell("Course Code");
                table.AddCell("Name");
                table.AddCell("Grade");
                foreach (var viewResult in studentResultViewModels)
                {
                    table.AddCell(viewResult.CourseCode);
                    table.AddCell(viewResult.CourseName);
                    table.AddCell(viewResult.GradeName);
                }



                Document             doc         = new Document(PageSize.A4, 30f, 30f, 10f, 10f);
                iTextSharp.text.Font NormalFont  = FontFactory.GetFont("Arial", 20, BaseColor.BLUE);
                iTextSharp.text.Font HeaderFont  = FontFactory.GetFont("tahoma", 23, BaseColor.ORANGE);
                iTextSharp.text.Font InfoFont    = FontFactory.GetFont("myriadPro", 14, BaseColor.GRAY);
                iTextSharp.text.Font tableHeader = FontFactory.GetFont("arial", 16, BaseColor.BLACK);
                PdfWriter            writer      = PdfWriter.GetInstance(doc, ms);
                doc.Open();
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph("University Course and Result Management System", HeaderFont));
                doc.Add(new Paragraph("                               Student Result", HeaderFont));
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph("Student Information", NormalFont));
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph("Name : " + name, InfoFont));
                doc.Add(new Paragraph("Registration No : " + regNo, InfoFont));
                doc.Add(new Paragraph("Department : " + department, InfoFont));
                doc.Add(new Paragraph("Email : " + email, InfoFont));
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph("Result of all Courses", tableHeader));

                doc.Add(new Paragraph(" "));
                doc.Add(table);
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph(" "));
                doc.Add(new Paragraph("                                                 Prepared By DotNet Learners Team"));

                doc.Close();
                byte[] bytes = ms.ToArray();
                ms.Close();

                //Response.Clear();
                //Response.ContentType = "application/pdf";
                //Response.AddHeader("Content-Disposition", "attachment; filename=Employee.pdf");
                //Response.ContentType = "application/pdf";
                //Response.Buffer = true;
                //Response.Cache.SetCacheability(HttpCacheability.NoCache);
                //Response.BinaryWrite(bytes);
                //Response.End();
                //Response.Close();

                return(File(bytes, "application/pdf", "'" + name + "'.pdf"));
            }
        }
예제 #6
0
        //Función que genera el documento Pdf


        public void GenerarDocumento(iTextSharp.text.Document document)
        {
            //se crea un objeto PdfTable con el numero de columnas del


            //dataGridView


            PdfPTable datatable = new PdfPTable(gvGps.ColumnCount);


            //asignamos algunas propiedades para el diseño del pdf

            datatable.DefaultCell.Padding = 3;

            float[] headerwidths = GetTamañoColumnas(gvGps);


            datatable.SetWidths(headerwidths);


            datatable.WidthPercentage = 100;


            datatable.DefaultCell.BorderWidth = 2;


            datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;



            //SE GENERA EL ENCABEZADO DE LA TABLA EN EL PDF


            for (int i = 0; i < gvGps.ColumnCount; i++)
            {
                datatable.AddCell(gvGps.Columns[i].HeaderText);
            }



            datatable.HeaderRows = 1;


            datatable.DefaultCell.BorderWidth = 1;



            //SE GENERA EL CUERPO DEL PDF

            iTextSharp.text.Font fGrilla = new iTextSharp.text.Font();
            fGrilla.Size = 10;
            for (int i = 0; i < gvGps.RowCount; i++)
            {
                for (int j = 0; j < gvGps.ColumnCount; j++)
                {
                    datatable.AddCell(new iTextSharp.text.Paragraph(gvGps[j, i].Value.ToString(), fGrilla));
                }


                datatable.CompleteRow();
            }
            iTextSharp.text.Font fTitulo = new iTextSharp.text.Font();
            fTitulo.Size = 20;

            iTextSharp.text.Font fDescripcion = new iTextSharp.text.Font();
            fDescripcion.Size = 10;

            document.Add(new iTextSharp.text.Paragraph("Cuerpo de Bomberos de Santiago", fTitulo));
            document.Add(new iTextSharp.text.Paragraph("Texto chico", fDescripcion));
            document.Add(new iTextSharp.text.Paragraph(" "));
            document.Add(datatable);


            document.Add(new iTextSharp.text.Paragraph(" "));
            document.Add(new iTextSharp.text.Paragraph("______________________________"));
            document.Add(new iTextSharp.text.Paragraph("     Firma Operadora Nº " + textBox1.Text));
        }