Open PDF file in RichTextBox in WPF

江枫思渺然 提交于 2019-12-08 07:40:53

问题


Can I open a PDF file in RichTextBox?


回答1:


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.




回答2:


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)
    {   } } }



回答3:


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.



来源:https://stackoverflow.com/questions/876749/open-pdf-file-in-richtextbox-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!