Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How can I open a pdf file for viewing in VS? I'm guessing I need a third party dll so any recommendations are welcome.

 

I tried searching the forum for "pdf" but the word is too short :(

  • 3 weeks later...
Posted
Are you looking for a PDF viewer for your application or a PDF viewer for the VS IDE?

For my own application.

 

Google is often a better place to start a search like this.

I know there's tons of alternatives on the Internet, but I was hoping someone here would know which is the best.

  • 4 months later...
Posted (edited)

Hi Joe, Jumpy,

 

Good news. The Free Adobe Reader Version 10x has reinstated the AcroPDF.dll ActiveX

 

Use ChooseItems and under COM select the above. If it does not show path to:

C:\Program Files\Common Files\Adobe\Acrobat\ActiveX\AcroPDF.dll

 

Tons of good stuff in the control. LoadFile, Viewing, Printing, Etc...

The only thing it does not do is create or edit PDF's directly. If you choose to show the toolbar it has a button that links to the web site that can create PDFs for you.

 

(See Attached Picture)

Edited by Gruff
  • 3 weeks later...
Posted

Sample: Merging images and pdfs to a single pdf.

 

 

Thank you for the tip. This library works really well.

 

I scrathed up a small sample code that merges any image files or existing pdf files to a single pdf. I hope it helps someone to get started with the PDF#-library.

 

   Public Sub CreatePDF(ByVal DesnationFilePath As String, _
           ByVal SourceFiles As List(Of String), _
           ByVal CropArea As Rectangle)

       'Create a new PDF document
       Dim OutputDoc As PdfSharp.Pdf.PdfDocument = New PdfSharp.Pdf.PdfDocument
       OutputDoc.Info.Title = "Created with PDFsharp"

       'Add one image or PDF at a time
       For PageNumber As Integer = 0 To SourceFiles.Count - 1
           Dim SourceFilePath As String = SourceFiles(PageNumber)
           If LCase(IO.Path.GetExtension(SourceFilePath)) = ".pdf" Then
               AddPdf(OutputDoc, SourceFilePath, CropArea)
           Else 'Must be a picture
               AddPicture(OutputDoc, SourceFilePath, CropArea)
           End If
       Next

       'Save
       OutputDoc.Save(DesnationFilePath)

   End Sub

   Private Sub AddPicture(ByRef OutputDoc As PdfSharp.Pdf.PdfDocument, ByVal ImgPath As String, ByVal CropArea As Rectangle)

       'Create an empty page
       Dim page As PdfSharp.Pdf.PdfPage = OutputDoc.AddPage()

       'Draw image
       Dim gfx As PdfSharp.Drawing.XGraphics = PdfSharp.Drawing.XGraphics.FromPdfPage(page)
       Dim image As PdfSharp.Drawing.XImage
       If CropArea = Nothing Then
           Dim SourceImg As System.Drawing.Bitmap = Bitmap.FromFile(ImgPath)
           image = PdfSharp.Drawing.XImage.FromGdiPlusImage(SourceImg)
       Else
           Dim OriginalImage As Bitmap = Bitmap.FromFile(ImgPath)
           Dim CroppedImage As Image = OriginalImage.Clone(CropArea, OriginalImage.PixelFormat)
           image = PdfSharp.Drawing.XImage.FromGdiPlusImage(CroppedImage)
       End If
       page.Height = (image.PixelHeight * 0.0025) * 72.0 * 400.0 / image.VerticalResolution
       page.Width = (image.PixelWidth * 0.0025) * 72.0 * 400.0 / image.HorizontalResolution
       gfx.DrawImage(image, 0, 0)

   End Sub

   Private Sub AddPdf(ByRef OutputDoc As PdfSharp.Pdf.PdfDocument, ByVal PdfPath As String, ByVal CropArea As Rectangle)

       'Add one page at a time
       Dim InputDoc As PdfSharp.Pdf.PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open(PdfPath, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import)
       For i As Integer = 0 To InputDoc.PageCount - 1
           OutputDoc.AddPage(InputDoc.Pages(i))
       Next

   End Sub

  • 2 months later...
Posted

Also the way I did it was adding a webbrowser and in the navigate option yust enter the path and filename..

 

webbrowser1.navigate = "C:\Users\Luis\Desktop\1.pdf"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...