生活随笔
收集整理的這篇文章主要介紹了
使用.NET 将PDF转成Word
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用Solid Framework可以很方便的已編程方式將PDF轉換成Word文件格式
首先準備一套Solid Framework
在Visual Studio中建立一個項目并引用SolidFramework.dll
添加命名空間 SolidFramework
using SolidFramework;
using SolidFramework.Configuration;
using SolidFramework.Converters;
using SolidFramework.Converters.Plumbing;
前期準備, 設置路徑個許可證
string directoryName
= Path
.GetDirectoryName(Assembly
.GetExecutingAssembly().Location
);
char directorySeparatorChar
= Path
.DirectorySeparatorChar
;
string str
= string.Concat(directoryName
, directorySeparatorChar
.ToString(), "SolidFramework");Installer
.NativePlatformDirectory
= str
;
Installer
.ForceUnpack
= false;
License
.Import("Solid Framework", "xxxx", "xxx", "xxxxxxxxxxxxxxx", "NOCALL");
初始化SolidFrame Pdf Converter
pdfToWordConverter
.AddSourceFile(path
);
pdfToWordConverter
.ReconstructionMode
= option
.C_ReconstructionMode
;
pdfToWordConverter
.DetectTables
= option
.Table_Detection
;
pdfToWordConverter
.OutputType
= WordDocumentType
.DocX
;
pdfToWordConverter
.HeaderAndFooterMode
= option
.C_HeaderAndFooterMode
;
pdfToWordConverter
.ImageAnchoringMode
=option
.C_ImageAnchoringMode
;
pdfToWordConverter
.OverwriteMode
= SolidFramework
.Plumbing
.OverwriteMode
.ForceOverwrite
;
pdfToWordConverter
.KeepCharacterSpacing
= false;
FileInfo fileInfo
= new FileInfo(path
);
pdfToWordConverter
.TextRecoveryType
= option
.Recognize_Text
;
pdfToWordConverter
.OutputDirectory
= fileInfo
.DirectoryName
;
pdfToWordConverter
.SupportRightToLeftWritingDirection
= true;
pdfToWordConverter
.DetectLists
= true;
pdfToWordConverter
.DetectStyles
= true;
pdfToWordConverter
.DetectToc
= true;
pdfToWordConverter
.MarkupAnnotConversionType
= MarkupAnnotConversionType
.Never
;
pdfToWordConverter
.TextRecoveryNseType
= TextRecoveryNSE
.Never
;
OCR識別引擎, 這里使用內置引擎
pdfToWordConverter
.TextRecoveryEngine
= TextRecoveryEngine
.SolidOCR
;
一切就緒開始轉換
pdfToWordConverter
.Convert();
ConversionStatus status
= pdfToWordConverter
.Results
[0].Status
;
關于ConversionStatus
ConversionStatus 定義了多種轉換狀態IO錯誤密碼錯誤等
public enum ConversionStatus{Success
= 0,Canceled
= 1,InternalError
= 2,Unknown
= 200,Fail
= 3,BadData
= 5,IOError
= 6,IOFileLocked
= 7,NotEnoughMemory
= 9,FileHasCopyProtection
= 10,InvalidPagesRange
= 8,UnsupportedEncryptionHandler
= 11,MissingCertificate
= 12,OCRCanceled
= 13,NoTablesToExtract
= 0xF,NoImagesToExtract
= 0x10,NoBppConversion
= 150,NoGrayscale
= 151,PSDUnsupportedMode
= 152,PdfAError
= 20,PdfAFatalError
= 21,CanceledExists
= 14,WrongPassword
= 0x1F,NoUserNoOwner
= 0x20,NoUserOwner
= 33,UserNoOwner
= 34,UserOwner
= 35,InvalidLicense
= 36,AlreadyLoaded
= 30,UnavailableAction
= 4}
關于輸出格式
pdfToWordConverter.OutputType = WordDocumentType.DocX;
可以是Doc或Docx
執行后
就可以將PDF轉換成Word了
總結
以上是生活随笔為你收集整理的使用.NET 将PDF转成Word的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。