c# how can i get the value of my printPreviewControl1 print to PDF

Hello guys good afternoon ? How can i get my printpreviewcontrol and display to pdf reader ? The pdf reader only read is document i want my to display my print to the pdf HERE'S THE PICTURE 在这里输入图像描述

Code ` private void button1_Click(object sender, EventArgs e) {

        printPreviewDialog1.Document = printDocument1;
        printPreviewControl1.Document = printPreviewDialog1.Document;
        printPreviewControl1.Show();

    }

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        var itemsString = "";
        foreach (var item in listBox1.Items)
        {
            itemsString += item.ToString();

            if (listBox1.Items.IndexOf(item) != listBox1.Items.Count - 1)
                itemsString += "nt             ";//Seperator
        }
        Bitmap bmp = Properties.Resources.Resibo;
        Image newImage = bmp;
        e.Graphics.DrawImage(newImage, 35, 35, newImage.Width, newImage.Height);
        e.Graphics.DrawString("  Name : " + label3.Text, new Font("Arial", 18, FontStyle.Bold), Brushes.Black, new Point(30, 200));
        e.Graphics.DrawString("  Date : " + label4.Text, new Font("Arial", 18, FontStyle.Bold), Brushes.Black, new Point(30, 250));
        e.Graphics.DrawString("  Requested :   " + itemsString, new Font("Arial", 18, FontStyle.Bold), Brushes.Black, new Point(30, 300));
        e.Graphics.DrawString("  Total : t" + label2.Text, new Font("Arial", 18, FontStyle.Bold), Brushes.Black, new Point(30, 400));
    }

    private void button2_Click(object sender, EventArgs e)
    {

        using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "PDF file|*.pdf", ValidateNames = true })
        {
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                iTextSharp.text.Document doc = new iTextSharp.text.Document();
                try
                {
                    PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                    doc.Open();
                    doc.Add(new iTextSharp.text.Paragraph(printPreviewControl1.Document.DocumentName));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    doc.Close();
                }
            }
        }
    }`
链接地址: http://www.djcxy.com/p/21006.html

上一篇: C#指向变量的指针

下一篇: c#我怎样才能得到我的printPreviewControl1打印到PDF的值