Can I open a PDF file in RichTextBox?
+1
A:
Short answer: No.
Longer answer: No. A RichTextBox is for displaying rich text. PDFs can contain anything including text, but that's not the document model underlying the RichTextBox. Besides, WPF does not handle PDF natively. There are third-party controls, however.
This question also has some pointers which may be of use to you, albeit not using a RichTextBox.
Joey
2009-05-18 08:56:00
A:
You need to use the Acrobat Control for ActiveX or at least the Adobe Reader 9 equivalent and use as
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)
{ } } }
Sauron
2009-05-26 09:11:47
+1
A:
You can write a simple app in a few seconds containing a WebBrowser control, and just call the navigate method and give it a URL pointing to the document you want.
XAML:
<Grid>
<WebBrowser x:Name="Browser"/>
</Grid>
C#:
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 rather than something that will work as-is.
IanGilham
2009-05-26 09:23:19