c#我怎样才能得到我的printPreviewControl1打印到PDF的值
大家下午好吗? 我怎样才能让我的printpreviewcontrol和显示到PDF阅读器? PDF阅读器只读取文档,我希望我的图片显示在这里PDF文件
代码`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/21005.html
上一篇: c# how can i get the value of my printPreviewControl1 print to PDF