0

My application shows PDFs in a picture box by using Ghostscript. The PDFs I use are scanned images with a text layer. created by the OCR function from Acrobat Pro. This OCR function automatically sets the orientation according to the direction of the text. When the page is displayed in the picture box this information is lost. It just displays every page in portrait mode.

Is there a way for Ghostscript to access this property of the PDF and display it in the correct orientation in the picture box?

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();

    }

The code to open the file:

 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;
    }
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Jan-WIllem
  • 91
  • 13

2 Answers2

2

I'm not sure if I should answer my own questions, but the problem is solved by updating to version 1.1.8. Thanks to HABJAN. Thanks very much.

Jan-WIllem
  • 91
  • 13
1

The first thing to do is to use Ghostscript directly from the command line, rather than in an application. The main reason is that you can then supply a GS command line which other people can use, experiment with and comment on.

I can't see from your code how Ghostscript is invoked.

Ghostscript should, in general, honour the /MediaBox (and optionally /CropBox etc.) as well as the /Rotate attribute of pages.

But without a sample file and command line, I can't give you any suggestions.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
KenS
  • 30,202
  • 3
  • 34
  • 51
  • It looks to me that he's using a managed wrapper around the Ghostscript libraries. Command line arguments either don't apply, or are hidden by the wrapper. – David Crowell Jul 21 '14 at 15:30