2013-06-18 64 views
3

將文件從MSword轉換爲PDF抽取後,出現錯誤未找到PDF標頭簽名。錯誤找不到PDF標頭簽名

public void Extract_inputpdf() 
{ 
    text_input_File = string.Empty; 

    StringBuilder sb_inputpdf = new StringBuilder(); 
    PdfReader reader_inputPdf = new PdfReader(path); //read PDF 
    for (int i = 0; i <=reader_inputPdf.NumberOfPages ; i++) 
    { 
     TextWithFont_inputPdf inputpdf = new TextWithFont_inputPdf(); 

     text_input_File = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(reader_inputPdf, i, inputpdf); 

     sb_inputpdf.Append(text_input_File); 

     input_pdf = sb_inputpdf.ToString(); 
    } 

    reader_inputPdf.Close(); 
    clear(); 
} 

誰能告訴我怎麼解決this.Thanku

// word to pdf 
if (Extentsion_path == ".doc" || Extentsion_path == ".docx") 
{ 
    uploadFInput.SaveAs(targetPathip); 
    string wordFileName = targetPathip; 
    _Word.Visible = false; 
    _Word.ScreenUpdating = false; 

    // Cast as Object for word Open method 
    filename = (object)wordFileName; 

    // Use the dummy value as a placeholder for optional arguments 

    Microsoft.Office.Interop.Word.Document doc = _Word.Documents.Open(ref filename, ref _MissingValue, 
     ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, 
     ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, 
     ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue); 
    doc.Activate(); 

    object outputFileName = pdfFileName = Path.ChangeExtension(wordFileName, "pdf"); 
    object fileFormat = WdSaveFormat.wdFormatPDF; 

    // Save document into PDF Format 
    doc.SaveAs(ref outputFileName, ref fileFormat, ref _MissingValue, ref _MissingValue, 
     ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, 
     ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, 
     ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue); 

    // Close the Word document, but leave the Word application open. 
    // doc has to be cast to type _Document so that it will find the 
    // correct Close method. 
    object saveChanges = WdSaveOptions.wdDoNotSaveChanges; 
    ((_Document)doc).Close(ref saveChanges, ref _MissingValue, ref _MissingValue); 
    doc = null; 

    // word has to be cast to type _Application so that it will find 
    // the correct Quit method. 
    ((_Application)_Word).Quit(ref _MissingValue, ref _MissingValue, ref _MissingValue); 

    _Word = null; 

    //uploadFInput.SaveAs(pdfFileName); 
    // = targetPathip; 
    uploadFInput.SaveAs(pdfFileName); 
    LblFleip.Text = pdfFileName; 
} 
else 
{ 
    uploadFInput.SaveAs(targetPathip); 
    LblFleip.Text = targetPathip; 
} 
+1

那麼您是從Microsoft Word保存/導出爲PDF還是現在您正在嘗試閱讀PDF?哪條線給你錯誤?我可以發現的一件事是,iText中的頁碼以'1'開始,而不是'0',因此請嘗試將'for'循環從'1'開始。 –

+0

我給PDf加了詞。讀取時出錯PdfReader reader_inputPdf = new PdfReader(path); //閱讀PDF – pdp

+0

用於測試目的我正在測試相同的PDF很多次我得到類型不匹配的錯誤。 (來自HRESULT的異常:0x80020005(DISP_E_TYPEMISMATCH)) – pdp

回答

2

您可以在記事本中打開PDF文件,並首先檢查簽名的存在。

相關問題