티스토리 뷰

private void button_pdf_Click(object sender, EventArgs e)

        {

            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();



            PdfPTable table = new PdfPTable(dataGridView1.Columns.Count);


// 한글출력하는 부분 ////////////////////////////////////////////////////

            //    string batangttf = System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), @"Fonts\BareunBatangB.ttf");

            string batangttf = System.IO.Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), @"Fonts\HYGSRB.ttf");

            BaseFont batangBase = BaseFont.CreateFont(batangttf, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            var batang = new iTextSharp.text.Font(batangBase, 12F);

/////////////////////////////////////////////////////////////////////////////////////////////////////


            for(int j=0;j<dataGridView1.Columns.Count;j++)

            {

                table.AddCell(new Phrase(dataGridView1.Columns[j].HeaderText,batang));

            }


            table.HeaderRows = 1;


            for (int i=0; i<dataGridView1.Rows.Count;i++)

            {

                for(int k=0; k<dataGridView1.Columns.Count;k++)

                {

                    if(dataGridView1[k,i].Value != null)

                    {

                        table.AddCell(new Phrase(dataGridView1[k, i].Value.ToString()));


                    }

                }

            }


            doc.Add(table);


            doc.Close();

            



        }



프린트페이지띄우기


   Bitmap bmp;

        private void button_pdf_Click(object sender, EventArgs e)

        {

            int height = dataGridView1.Height;

            dataGridView1.Height  = dataGridView1.RowTemplate.Height = 2;

            bmp = new Bitmap(dataGridView1.Width, dataGridView1.Height);

            dataGridView1.DrawToBitmap(bmp, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));

            dataGridView1.Height = height;

            printPreviewDialog1.ShowDialog();

        }


        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            e.Graphics.DrawImage(bmp, 0, 0);

        }

    }



댓글
최근에 달린 댓글
글 보관함
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글