• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 76
  • Last Modified:

Convert 1page PDF to JPG and then insert to Excel

I have 1 page PDF files.  I need to convert them to a JPG or PNG file and then insert the image into Excel.  The PDF files are drawings and we want to display them in the Excel file.  After the excel file closes, I can delete the JPG or PNG file.  I haven't been able to get the PDF file to display as an image in Excel, so I'm thinking I need to convert the PDF to a JPG or PNG in order for them to show as an image.  I don't want to use Adobe professional to convert the PDF files.

Unless there is a way to display the 1 page PDF as an image?
0
maverick0728
Asked:
maverick0728
  • 6
  • 5
2 Solutions
 
Rgonzo1971Commented:
HI,

You can copy the pdf already inserted in excel and paste it as image and delete the pdf of the excel

Regards
0
 
maverick0728Author Commented:
Copy and paste of the PDF as a image doesn't work.

I have this code to copy in a PDF, but I receive "This image cannot currently be displayed".
Sub TestInsertPictureInRange()
    InsertPictureInRange "C:\Drawings\test.pdf", _
        Range("A79:J87")
End Sub

Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
    ' inserts a picture and resizes it to fit the TargetCells range
    Dim p As Object, t As Double, l As Double, w As Double, h As Double
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    If Dir(PictureFileName) = "" Then Exit Sub
    ' import picture
    Set p = ActiveSheet.Pictures.Insert(PictureFileName)
    ' determine positions
    With TargetCells
        t = .Top
        l = .Left
        w = .Offset(0, .Columns.Count).Left - .Left
        h = .Offset(.Rows.Count, 0).Top - .Top
    End With
    ' position picture
    With p
        .Top = t
        .Left = l
        .Width = w
        .Height = h
    End With
    Set p = Nothing
End Sub

Open in new window

0
 
Rgonzo1971Commented:
then try

Sub TestInsertPictureInRange()
    InsertPictureInRange "C:\Drawings\test.pdf", _
        Range("A79:J87")
End Sub

Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
    ' inserts a picture and resizes it to fit the TargetCells range
    Dim p As Object, t As Double, l As Double, w As Double, h As Double
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    If Dir(PictureFileName) = "" Then Exit Sub
    ' import picture
    
    Set pdf = ActiveSheet.OLEObjects.Add(Filename:=PictureFileName, Link:=False, DisplayAsIcon:=False)
    pdf.Copy
    pdf.Delete
    Set Rng = TargetCells.Cells(1)
    Rng.Activate
    ActiveSheet.PasteSpecial Format:="Picture (JPEG)", Link:=False, DisplayAsIcon:=False
    
    ' determine positions
    With TargetCells
        t = .Top
        l = .Left
        w = .Offset(0, .Columns.Count).Left - .Left
        h = .Offset(.Rows.Count, 0).Top - .Top
    End With
    ' position picture
    Set s = Selection
    With s
        .Top = t
        .Left = l
        .Width = w
        .Height = h
    End With
    Set s = Nothing
End Sub

Open in new window

1
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
maverick0728Author Commented:
That is better - shows a temporary name of the pdf  temppdf.bmp
I actually want to show an image of the PDF file contents.  Can this be done?
testimage.bmp
0
 
Rgonzo1971Commented:
and what is "c:\Drawings\test.pdf"

shouldn't be an icon since
 DisplayAsIcon:=False
0
 
maverick0728Author Commented:
"c:\Drawings\test.pdf" is a pdf with this image:
testimage.bmp
0
 
Rgonzo1971Commented:
if you run it step by step what is the result at line 14
0
 
maverick0728Author Commented:
line 14 result is:
line14result.bmp
0
 
Rgonzo1971Commented:
Maybe it's due that your default pdf reader is not acrobat?
0
 
maverick0728Author Commented:
Could be.  We are using PDF-XChange.  Can it work with PDF-XChange?
0
 
Rgonzo1971Commented:
No experience with it but maybe by changing temporarily the default program to acrobat reader it could work
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now