Save pdf file with user input filename (iTextSharp)

断了今生、忘了曾经 提交于 2019-11-29 11:29:25

I am not an expert of ITextSharp, but I think that your code should be something like this

SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Pdf File |*.pdf";
if (sfd.ShowDialog() == DialogResult.OK)
{
    Document doc = new Document(PageSize.LETTER, bounds.Left, bounds.Right, bounds.Top, bounds.Bottom);
    PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
    doc.Open();
    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance("Image.jpeg");
    doc.Add(image);
    doc.Close();
}

In other words, just pass the FileName string choosen in SaveFileDialog to the PdfWriter.GetInstance method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!