1. 程式人生 > 其它 >C# pdf轉word

C# pdf轉word

//首先 安裝spire.pdf 的get包

//該方法只能轉換10頁的pdf文件


/// <summary>
///
/// </summary>
/// <param name="originalPath">檔案路徑</param>
/// <param name="newPath">新檔案放置路徑</param>
/// <param name="fileName">新檔名稱</param>
/// <returns></returns>
public static int pdfword(string originalPath, string newPath, string fileName)
{
try
{
int Result = 0;
if (originalPath != null || originalPath != "" || newPath != null || newPath != "")
{
PdfDocument doc = new PdfDocument();
using (doc)
{
string[] pathWordTrim = originalPath.Split('.');

if (pathWordTrim[1].Contains("pdf") || pathWordTrim[1].Contains("PDF"))
{
doc.LoadFromFile(originalPath);
doc.SaveToFile(newPath + fileName + ".DOCX", FileFormat.DOCX);

Result = 1;
}
}
}

return Result;
}
catch
{
int Result = 0;

return Result;
}
}