[英]how to save pdf file in folder without save dialog c# windows application
This is my code for opening a PDF file. 这是我打开PDF文件的代码。 I need this file to be saved to a certain location in my computer eg.:
@"c:\\temp\\"
我需要将此文件保存到计算机中的某个位置,例如:
@"c:\\temp\\"
List<string> pdfFiles = new List<string>();
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.CheckFileExists = true;
openFileDialog.AddExtension = true;
openFileDialog.Multiselect = true;
openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
pdfFiles = new List<string>();
foreach (string fileName in openFileDialog.FileNames)
pdfFiles.Add(fileName);
}
You can use the File.Copy
method to copy the file to its new location. 您可以使用
File.Copy
方法将文件复制到其新位置。
First, obtain the path of the file in the old location and desired new location. 首先,获取文件在旧位置和所需新位置的路径。 Then, apply this method.
然后,应用此方法。
File.Copy(@"C:\old.txt", @"C:\new.txt");
try this 尝试这个
add this Reference file - iTextSharp.text.pdf 添加此参考文件-iTextSharp.text.pdf
string Folderpath ="your path";
using (FileStream stream = new FileStream(Folderpath, FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
// Paragraph k = new Paragraph("Your PDF ");
// pdfDoc.Add(k);
pdfDoc.Close();
stream.Close();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.