Solved

Convert 1page PDF to JPG and then insert to Excel

Posted on 2016-07-25
11
65 Views
Last Modified: 2016-07-25
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
Comment
Question by:maverick0728
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41727592
HI,

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

Regards
0
 

Author Comment

by:maverick0728
ID: 41727610
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
 
LVL 51

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 41727627
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:maverick0728
ID: 41727665
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
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41727678
and what is "c:\Drawings\test.pdf"

shouldn't be an icon since
 DisplayAsIcon:=False
0
 

Author Comment

by:maverick0728
ID: 41727692
"c:\Drawings\test.pdf" is a pdf with this image:
testimage.bmp
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41727694
if you run it step by step what is the result at line 14
0
 

Author Comment

by:maverick0728
ID: 41727702
line 14 result is:
line14result.bmp
0
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41727723
Maybe it's due that your default pdf reader is not acrobat?
0
 

Author Comment

by:maverick0728
ID: 41727775
Could be.  We are using PDF-XChange.  Can it work with PDF-XChange?
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41727923
No experience with it but maybe by changing temporarily the default program to acrobat reader it could work
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question