Open PDF file in RichTextBox in WPF

Is it possible to open PDF file in RichTextBox?

+1


a source to share


3 answers


You need to use Acrobat Control for ActiveX or at least the Adobe Reader 9 equivalent and use it like



using PdfLib;
namespace WindowsFormsApplication1{
public partial class ViewerForm : Form{
    public ViewerForm()
    {
     InitializeComponent();
     PdfLib.AxAcroPDF axAcroPDF1;
     axAcroPDF1.LoadFile(@"C:\Documents and Settings\jcrowe\Desktop\Medical Gas\_0708170240_001.pdf");
     axAcroPDF1.Show(); }

    private void richTextBox1_TextChanged(object sender, EventArgs e)
    {   } } }

      

+1


a source


The short answer is: No.

Longer answer: No. RichTextBox is for displaying rich text. PDF files can contain anything, including text, but this is not the document model underlying the RichTextBox. Also, WPF doesn't handle PDF natively. There are third party controls, however.



This question also contains some pointers that you might find useful, albeit not using the RichTextBox.

+1


a source


You can write a simple application in a few seconds that contains a WebBrowser control and simply call the navigation method and point it to a URL that points to the desired document.

XAML:

<Grid>
    <WebBrowser x:Name="Browser"/>
</Grid>

      

FROM#:

private void Window1_Loaded(object sender, WindowLoadedArgs args)
{
    Browser.Navigate(new URL("path to document.pdf");
}

      

Note. I am writing from memory, so consider this pseudocode and not something that will work as is.

+1


a source







All Articles