将Rumtime Name命名为Pdf [英] give Rumtime Name to Pdf
本文介绍了将Rumtime Name命名为Pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我正在为我的Windows基础应用程序使用itextsharp dll。
我使用以下代码生成pdf。
我想给TextBox文本名称到我的pdf。
&还有来自文本框文本的密码。
hi
I am using itextsharp dll for my windows base application.
I generate pdf by using following code.
I want to give TextBox Text name to my pdf.
& also password from textbox text.
Document doc = new Document(PageSize._11X17, 5f, 5f, 10f, 0f);
//Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
Paragraph paragraph = new Paragraph(" Image");
imgpath = openFileDialog1.FileName;
// string pdfFilePath = Server.MapPath(".") + "/PDFFiles";
PdfWriter writer = PdfAWriter.GetInstance(doc, new FileStream("C:\\Users\\shrikesh\\Desktop "+textBox2.Text+".pdf", FileMode.Create));
// PdfWriter writer = PdfAWriter.GetInstance(doc, new FileStream(System.IO.Directory.GetCurrentDirectory() + "/Default.pdf", FileMode.Create));
SqlConnection con = new SqlConnection("Data Source=SHRIKESH-PC\\SQLEXPRESS;Initial Catalog=windows;Integrated Security=True");
con.Open();
doc.Open();
textBox1.Text = imgpath;
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imgpath);
jpg.ScaleToFit(140f, 120f);
jpg.SpacingBefore = 10f;
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_CENTER;
//jpg.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraph);
doc.Add(jpg);
//string innnp;
//string output;
//string password;
//PdfReader preresder = new PdfReader(innnp);
//PdfEncryptor.Encrypt(preresder, new FileStream(output, FileMode.Append), PdfWriter.STRENGTH128BITS, password, "", PdfWriter.ALLOW_SCREENREADERS);
doc.Close();
MessageBox.Show("PDF created");
推荐答案
我认为你错过了一个\\ ...
I think you are missing a \\...
PdfWriter writer = PdfAWriter.GetInstance(doc, new FileStream("C:\\Users\\shrikesh\\Desktop\\" + textBox2.Text + ".pdf", FileMode.Create));
参见带下划线的部分。
这篇关于将Rumtime Name命名为Pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文