Results 1 to 3 of 3

Thread: Embed pdf files into project and reference them

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2011
    Location
    Minneapolis
    Posts
    39

    Embed pdf files into project and reference them

    I have a project and am trying to place about 50 PDF files directly into it and have the code display the files.

    Currently, I have setup a folder structure under the project name, thus

    HTML Code:
    Solution
        enginrev4
            PDF_Outlines
                TS-PL
                    pdf file 1.pdf
                    pdf file 2.pdf
                    .
                    .
                    .
    I have no idea of the syntax to reference this information, or if it is even a good idea, or if there is a better way to do it (please advise). My goal is to get away from having to reference a file on a CD or network, but to include this information within the application.

    Thanks in advance for your direction.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,758

    Re: Embed pdf files into project and reference them

    If you add your pdf files to your application as a resource, you can read them as a byte array, create a temporary file from the array and open it. The code looks something like this....
    vb Code:
    1. 'get a temporary filename
    2.         Dim fName As String = IO.Path.GetTempFileName
    3.  
    4.         fName = IO.Path.ChangeExtension(fName, "pdf")
    5.  
    6.         'write the byte array to a file
    7.         IO.File.WriteAllBytes(fName, My.Resources.myPDF)
    8.  
    9.         'make sure the file exists and open it
    10.         If IO.File.Exists(fName) Then
    11.             Process.Start(fName)
    12.         End If

    How many files are you talking about? I don't know for sure, but I would think that your performance may take a hit if you add too many files or if they are too big.
    kevin

    btw, If you are building an installer, you could include the files in the installer and have them placed in the applications's program data store, or (if they are read only) in the application's start up directory.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: Embed pdf files into project and reference them

    Hello,

    How to extract PDF from resource.
    How to show PDF in Windows forms.
    Now the show code may or may not work, for instance under XP which is where the code was done it works as expected but under Winodws 7 it will be funky.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width