Saturday, August 13, 2022

#1 2021-05-28 08:06:42 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1406

Remove Images from a PDF

Is it possible to use ASObjC to remove images from a PDF but to otherwise leave the formatting unchanged? Right now I use a commandline utility called cpdf, but I'd prefer to use ASObjC. A Google search and a review of the PDFDocument documentation didn't disclose anything that would appear to do the job. Thanks.


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#2 2021-05-28 01:38:12 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 163

Re: Remove Images from a PDF

As you've figured out, there is only the PDFDocument class available to us, which is part of the PDFKit Framework.
But having used it a lot in the past, I can't remember they're being anyway of remove images from the documents.
It's a good a option for combining or merging documents, or for reordering and editing text in the pages, but falls short of abilities to manipulate images.

I believe there are a few powerful command line tools for working with PDF Documents, maybe it's worth building an AppleScript front end for controlling these command line tools through "do shell script", or the NSTask class.

Regards Mark

Offline

 

#3 2021-05-28 02:39:07 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1406

Re: Remove Images from a PDF

Thanks Mark. I suspected that was the case but occasionally I'm surprised at the stuff ASObjC can do.

BTW, I had no knowledge of NSTask and did a little research. Just to get the basics down, I wrote and timed the following, which took 0.003 second to run:

Applescript:

set theTool to "/usr/bin/say"
set theTask to current application's NSTask's new()
theTask's setLaunchPath:theTool
theTask's setArguments:{"OK"}
theTask's |launch|()

I then tested the do shell script, which took 0.664 second to run:

Applescript:

do shell script "say ok"

Last edited by peavine (2021-05-28 07:09:17 pm)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#4 2021-05-30 02:35:33 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 961

Re: Remove Images from a PDF

@peavine
I believe its possible to get the attributeString from PDFPage and then you could remove the
page (that has the image) and make a new one with only the attributeString.

I guess it wouldn't work if the the font is embedded inside the PDFPage and maybe will be lost.

PDF format is not prone to be edit but there are tools to do it. In cases their last minute change need to be done before print.

Shane maybe would know more, I have not extract attributeString from a PDFPage before.


if you are the expert, who will you call if its not your imagination.

Offline

 

#5 2021-05-30 07:21:44 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1406

Re: Remove Images from a PDF

Thanks Fredrik71 for the ideas. Right now I use the cpdf command-line utility to remove bitmap images from PDF's and that works OK. I've converted all but two of my PDF scripts to use ASObjC and thought I might reduce that number to one but won't be able to do that.

Last edited by peavine (2021-05-30 08:47:18 am)


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)