2014-07-20 94 views
0

我的應用程序使用Ghostscript在圖片框中顯示PDF。我使用的PDF是帶有文本圖層的掃描圖像。由Acrobat Pro的OCR功能創建。該OCR功能根據文字的方向自動設置方向。當頁面顯示在圖片框中時,此信息將丟失。它只是以縱向模式顯示每一頁。使用Ghostscript查看PDF的方向

有沒有辦法讓Ghostscript訪問PDF的這個屬性並在圖片框中以正確的方向顯示它?

public Form1() 
    { 
     InitializeComponent(); 
     _viewer = new GhostscriptViewer(); 
     _viewer.DisplaySize += new GhostscriptViewerViewEventHandler(_viewer_DisplaySize); 
     _viewer.DisplayPage += new GhostscriptViewerViewEventHandler(_viewer_DisplayPage); 
     NumberOfPagesToExtract = 1; 
     _viewer.Open("NoFile.pdf", _gsVersion, true); 
    } 

    void _viewer_DisplaySize(object sender, GhostscriptViewerViewEventArgs e) 
    { 
     pictureBox1.Image = e.Image; 
    } 

    void _viewer_DisplayPage(object sender, GhostscriptViewerViewEventArgs e) 
    { 
     pictureBox1.Invalidate(); 
     pictureBox1.Update(); 
     currentPageNumber = _viewer.CurrentPageNumber; 
     LastPageNumber = _viewer.LastPageNumber; 
     lblTotalNmbPages.Text = "/" + LastPageNumber.ToString(); 
     txtCurrentPgNmbr.Text = currentPageNumber.ToString(); 

    } 

打開該文件中的代碼:

private void btnOpenPdfGhostScript_Click(object sender, EventArgs e) 
    { 
     OpenFileDialog ofd = new OpenFileDialog(); 
     ofd.Title = "Open PDF file"; 
     ofd.Filter = "PDF, PS, EPS files|*.pdf;*.ps;*.eps"; 

     if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) 
     { 
      btnCLose_Click(this, null); 
      _viewer.Open(ofd.FileName, _gsVersion, true); 
      currentFilePath = ofd.FileName; 
      currentPageNumber = _viewer.CurrentPageNumber; 
      LastPageNumber = _viewer.LastPageNumber; 
      lblCurrentFIle.Text = ofd.FileName; //System.IO.Path.GetFileName(ofd.FileName); 
      if (backgroundWorker1.IsBusy != true) backgroundWorker1.RunWorkerAsync(); 
     } 
     currentPageNumber = 1; 
     progressBar1.Value = 0; 
    } 
+2

嗨,你使用什麼Ghostscript.NET版本?最新版本(1.1.8)已解決定位問題。 – HABJAN

+1

謝謝HABJAN。升級問題修復後,我正在使用1.1.4。超!!!! –

回答

2

我不確定我是否應該回答自己的問題,但問題是通過更新到版本1.1.8解決的。感謝HABJAN。非常感謝。

1

要做的第一件事情就是直接在命令行中使用Ghostscript的,而不是在應用程序中。主要原因是您可以提供其他人可以使用的GS命令行,進行實驗和評論。

我看不到你的代碼如何調用Ghostscript。

Ghostscript通常應該承認/MediaBox(和可選的/CropBox等)以及頁面的/Rotate屬性。

但沒有示例文件和命令行,我不能給你任何建議。

+0

它在我看來他使用的是Ghostscript庫的託管包裝。命令行參數要麼不適用,要麼被包裝器隱藏。 –