使用iTextSharp和Savedialog创建PDF [英] Creating PDF using iTextSharp and Savedialog

查看:76
本文介绍了使用iTextSharp和Savedialog创建PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Windows C#应用程序中针对按钮的on_click事件编写了以下内容:

I have written the following in a Windows C# application on the on_click event of a button:

using System.IO;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;


Document myDocument = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);

PdfWriter.GetInstance(myDocument, new FileStream("C:\\IngenicoDetails", FileMode.Create));
myDocument.Open();
myDocument.Add(new Paragraph("ID:" + TextBox1.Text));

myDocument.Close(); 



如何使用saveialog指定路径和文件名,而不是对路径和文件名进行硬编码?

Thanx



How can I use a savedialog to specify the path and the filename, instead of hardcoding the Path and Filename?

Thanx

推荐答案

尝试一下:

Try this:

SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "PDF Files|*.pdf";
dlg.FilterIndex = 0;

string  fileName = string.Empty;

if (dlg.ShowDialog() == DialogResult.OK) {
    fileName = dlg.FileName;
}



注意:包括System.IO命名空间;



NOTE: Include the System.IO namespace;


using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;


SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "PDF Files|*.pdf";
dlg.FilterIndex = 0;

string fileName = string.Empty;

if (dlg.ShowDialog() == DialogResult.OK)
{
fileName = dlg.FileName;
           
Document myDocument = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
PdfWriter.GetInstance(myDocument, new FileStream(fileName, FileMode.Create));
myDocument.Open();
myDocument.Add(new Paragraph("ID:" + TextBox1.Text));pre>
myDocument.Close();
}


这篇关于使用iTextSharp和Savedialog创建PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆