• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: PDF to JPG
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PDF to JPG


  • Subject: Re: PDF to JPG
  • From: Shane Stanley <email@hidden>
  • Date: Fri, 27 Feb 2015 14:59:21 +1100

On 27 Feb 2015, at 9:55 am, Stockly, Ed <email@hidden> wrote:

I've got thousands of PDF files that I need to make jpegs from.

The pdf files and their jpgs will live in the same directories, the only
difference in the file name will be the extension.

What is the quickest way to do this?

You could use sips. Or you could use ASObjC, which would probably be quicker still:

use scripting additions
use framework "Foundation"
use framework "AppKit"

on jpegFromPath:imagePath compressFactor:compFactor -- 0.0 = max compression, 1.0 = none
-- build destination path
set pathNSString to current application's NSString's stringWithString:imagePath
set destPath to pathNSString's stringByDeletingPathExtension()'s stringByAppendingPathExtension:"jpg"
-- load the file as an NSImage
set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:imagePath
if theImage = missing value then return false
-- get bitmap as data
set theData to theImage's TIFFRepresentation()
-- make imagerep from data
set newRep to current application's NSBitmapImageRep's imageRepWithData:theData
-- turn the imagerep into JPEG data
set theData to (newRep's representationUsingType:(current application's NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor, NSImageProgressive:false})
-- write it to disk
set theResult to (theData's writeToFile:destPath atomically:true)
return (theResult = 1)
end jpegFromPath:compressFactor:

its jpegFromPath:(POSIX path of (choose file)) compressFactor:1.0

If you're running Yosemite, use it directly; under Mavericks, save it in a Script Library.

The only catch is that NSImages tend to be cached, so you might want to quit your applet every couple of hundred images.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >PDF to JPG (From: "Stockly, Ed" <email@hidden>)

  • Prev by Date: Re: Can copy or paste in dialogs in Adobe InDesign CS6
  • Next by Date: Re: Can copy or paste in dialogs in Adobe InDesign CS6
  • Previous by thread: Re: PDF to JPG
  • Next by thread: A small request wrt list best practices
  • Index(es):
    • Date
    • Thread