简体   繁体   English

如何在没有保存对话框的C#Windows应用程序中将pdf文件保存在文件夹中

[英]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.

相关问题 如何在C#Windows窗体应用程序中将图表保存为带有保存文件对话框的图像 - How to save a chart as Image with Save File Dialog in C# Windows Forms Application 将pdf文件Memorystream保存在文件夹C#中 - Save pdf file Memorystream in folder C# 如何抓取图像并将其保存在文件夹中 [c# windows 应用程序] - How to grab an image and save it in a folder [c# windows application] 在C#Webbrowser控件中保存文件而不保存文件对话框 - save file without save file dialog in c# webbrowser control 如何使用C#将.bak文件保存在特定文件夹中(Windows应用程序) - How to save .bak file in specific folder using C# (windows application) c#如何将IO.Stream保存到MemoryStream并保存到本地文件夹上的PDF文件 - c# how to save IO.Stream to MemoryStream and save to PDF file on local folder 如何将文件保存在Windows应用程序的文件夹中 - How to save file in a folder in windows application 如何在临时文件中保存C#windows应用程序中的用户名? - How to save a username in a C# windows application in a temp file? 如何使用C#Windows应用程序保存文件 - how to Save File using C# Windows Application 将页面下载为pdf文件并保存在C#的本地文件夹中 - to download a page as pdf file and save in a local folder in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM