none
Viewing PDF document in Panel control. RRS feed

  • Question

  • Is there a simple way to view only the content of a PDF in a Panel. 

    Nothing complicated, Just a simple easy to use peas of code. 

    Saturday, May 13, 2017 8:47 PM

All replies

  • Hi, 

    Be aware that driving a car with an automatic gearbox and a cruise control is not complicated for those who drive those. 

    However, you are visiting a forum of those who build those. 

    And yes, if yo want to view to something as a consumer, then try Wall Mart of a likewise store. 

    https://www.walmart.com


    Success
    Cor

    Saturday, May 13, 2017 9:05 PM
  • I know you are mush more intelligent than I am, But this is beyond cryptic. 
    Saturday, May 13, 2017 10:22 PM
  • Is there a simple way to view only the content of a PDF in a Panel. 

    Nothing complicated, Just a simple easy to use peas of code. 

    There is no reason for assuming that this is simple.  Why are you using PDF?  There is data formats that are much more suitable for what you want to do.
    Saturday, May 13, 2017 11:05 PM
  • Hi Acamar.

    Thanks for asking. 

    Some documents will have text only, most will have pictures in as well as text. 

    This documents will be loaded on flash drive from time to time to be printed at a print-shop. 

    Document printing is cheaper than Picture printing even when there is a picture in the document. 

    Files like .jpeg will be printed as pictures, while .pdf is seen as documents. 

    Your suggestions is welcome.  

    Sunday, May 14, 2017 6:51 PM
  • Some documents will have text only, most will have pictures in as well as text. 

    If you are dealing with documents in .Net that include pictures and formatted text then the supported format is RTF.   You can replace a Panel with a RichTextBox.
    https://msdn.microsoft.com/en-us/library/s2t5aae7%28v=vs.110%29.aspx

    Sunday, May 14, 2017 9:24 PM
  • Hi VB Novice,

    A quick hack for this would be to use a WebBrowser control (assuming the client has Adobe Reader installed) and navigate it to the PDF file you want to display.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 15, 2017 7:22 AM
    Moderator
  • Hi Cherry. 

    I have being experimenting with a Web browser, it seems to be the best option for what I intend to do.

    I have a problem with the scrollbar and little toolbox that shows up on the screen. Can you help getting rid of this. It will be greatly appreciated.   

    Monday, May 15, 2017 10:19 AM
  • I tried using the SetParent API function call with a Panel control but could not get it to work with Acrobat Reader. Another option is to use the Acrobat Reader ActiveX component. Only requires a single line of code:

    https://www.thoughtco.com/display-a-pdf-with-vbnet-3424227

    Edit: This solution looks interesting too, although I haven't tried it:

    https://www.codeproject.com/Articles/37458/PDF-Viewer-Control-Without-Acrobat-Reader-Installe


    Paul ~~~~ Microsoft MVP (Visual Basic)


    Monday, May 15, 2017 12:21 PM
  • Monday, May 15, 2017 7:02 PM
  • Hi VB Novice,

    I put one Button and WebBrowser Control in the Form, you can refer to the code below.

    Please note that I use Internet Explorer to open a local .PDF file it uses Adobe Reader in some fashion to display the .PDF file, With regard to the WebBrowser control it appears to do the same thing. So that you could need to install some tool to open PDF, like Adobe Reader.

    Imports System.IO
    
    Public Class PDF
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim myStream As Stream = Nothing
            OpenFileDialog1.InitialDirectory = "D:\"
            OpenFileDialog1.Filter = ".PDF files (*.PDF)|*.PDF"
            OpenFileDialog1.FilterIndex = 2
            OpenFileDialog1.Title = ".PDF files"
            OpenFileDialog1.Multiselect = False
            OpenFileDialog1.RestoreDirectory = True
    
            If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Try
                    myStream = OpenFileDialog1.OpenFile()
                    If (myStream IsNot Nothing) Then
                        WebBrowser1.Navigate(OpenFileDialog1.FileName)
                    End If
                Catch Ex As Exception
                    MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
                Finally
                    ' Check this again, since we need to make sure we didn't throw an exception on open.
                    If (myStream IsNot Nothing) Then
                        myStream.Close()
                    End If
                End Try
            End If
    
        End Sub
    
        Private Sub PDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            WebBrowser1.Anchor = CType(AnchorStyles.Bottom + AnchorStyles.Left + AnchorStyles.Right + AnchorStyles.Top, AnchorStyles)
        End Sub
    
       End Class

    Hope it is helpful to you.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, May 16, 2017 7:06 AM
    Moderator
  • Hi Cherry. 

    I have being experimenting with a Web browser, it seems to be the best option for what I intend to do.

    I have a problem with the scrollbar and little toolbox that shows up on the screen. Can you help getting rid of this. It will be greatly appreciated.   

    That is what I meant with my first reply. 

    Then you replied to Acamar, 

    Hi Acamar.

    Thanks for asking. 

    Some documents will have text only, most will have pictures in as well as text. 

    This documents will be loaded on flash drive from time to time to be printed at a print-shop. 

    Document printing is cheaper than Picture printing even when there is a picture in the document. 

    Files like .jpeg will be printed as pictures, while .pdf is seen as documents. 

    Your suggestions is welcome.  

    And then I thought I can maybe help. But now I'm again completely flabbergasted. What has a webbrowser to do with taking an image to a printshop on a flashdrive?

    If you have a problem, then try to tell others what your problem is, and not what your solution is. 


    Success
    Cor


    Tuesday, May 16, 2017 8:21 AM
  • Cor. 

    Humble apologize if it seemed like I ignored you, your and every one else's help and advice is most valuable to me.  Acamar's advice, using .rtf and replacing the Panel with a RichTextBox might be what I am looking for, it makes things much easier.  

    Once I have this first stem done I will try and do some code for printing to .pdf (For mobile printing purposes, sorry for the confusion Cor.)

    The end user that I am planing this app. for is not very computer literate. 

    She is going to create documents in MS Word and save it as .docx.  

    So I need the app. to check for new .docx files then convert them to .rtf

    Even if you can help with writing an macro for MS Word that I can put in template .docx it will be 100%

    Tuesday, May 16, 2017 7:16 PM
  • She is going to create documents in MS Word and save it as .docx.  

    That seems to be more complex than is required.   MS Word can save documents direct to RTF - no coding is required.  But it's still not clear why you are creating PDF - it is a proprietary format that is quite difficult to work with.  If you really need PDF then it can be created direct from WORD.  

    Tuesday, May 16, 2017 8:55 PM