Automator PDF help please?
I generate a PDF file each day with anywhere from 5-20 pages. I need to use automator (or something similar) to split this large document into a separate document for each page. Then rename each new document by the text on the first line (ie. name). Then consolidate all of these documents into 1 folder and zip it so that I can email it out.
I can split it fine with "PDF to images" and I can automate the consolidation and zip procedure. However, I can't figure out any way to rename each file to the text on the first line which is the person's name. Is this possible? If so, any help with how to do it?
Thank you!!
Hello
You may also try something like the following rubycocoa script. It will split the specified pdf(s) into pages, each of which is named after its first non-empty line, and zip the directory containing the resultant pages. Currently space : / in name is replaced with _.
#!/bin/bash
infile=~/desktop/test/*.pdf
outdir=~/desktop/test/out
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -w <<'EOF' - $infile "$outdir"
# ARGV = pdf [pdf ...] [output_directory]
# * If out_directory is specified and exists, pages of every specified pdf are saved in out_directory and zipped.
# Otherwise, pages of each pdf are saved in directory named after pdf followed by "'s pages" in the same directory as pdf and zipped.
# v0.10
# written by Hiroto, 2014-10
require 'osx/cocoa'
OSX.require_framework 'PDFKit'
include OSX
def usage
$stderr.puts "Usage: #{File.basename($0)} pdf [pdf ...] [output_directory]"
exit 1
end
def quoted_form(s)
# string s : source string
# return string : s's quoted form for use in shell
# * e.g., given s = a'b, quoted form of s = 'a'\''b'
%q['%s'] % s.gsub(/'/) {%q['\'']}
end
def zip_j(d)
d = quoted_form(d)
%x[zip -j #{d}.zip #{d}/*]
end
usage unless ARGV.length > 0
outdir = File.directory?(ARGV.last) ? ARGV.pop : nil
usage unless ARGV.length > 0
ARGV.select { |f| File.file?(f) }.each do |f|
url = NSURL.fileURLWithPath(f)
doc = PDFDocument.alloc.initWithURL(url)
unless doc
$stderr.puts "Not a pdf file: %s" % f
next
end
odir = outdir ? outdir : (f + "'s pages")
Dir.mkdir(odir) unless File.directory?(odir)
(0 .. (doc.pageCount - 1)).each do |i|
page = doc.pageAtIndex(i)
line1 = ''
page.selectionForRange(NSMakeRange(0, page.string.length)).selectionsByLine.each do |q|
line1 = q.string.to_s.
gsub(/^[![:space:]]+|[![:space:]]+\z/, ''). # remove leading and trailing spaces and !
gsub(/[[:space:]:\/]/, '_') # replace space : / with _
break if line1.length > 0
end
line1 = '_' unless line1.length > 0
doc1 = PDFDocument.alloc.initWithData(page.dataRepresentation)
unless doc1.writeToFile(outfile = "#{odir}/#{line1}.pdf")
$stderr.puts "Failed to write page %d of %s to %s" % [i, f, outfile]
end
end
zip_j(odir) unless outdir
end
zip_j(outdir) if outdir
EOF
If you'd like to have this as an Automator Service, you may try something like this:
0) Service input: Services receives selected [PDF files] in [any application].
1) Run AppleScript aciton
code =
on run {argv}
tell application "System Events"
activate
set d to choose folder with prompt "Choose destination folder"
end tell
return argv & d
end run
2) Run Shell Script action
shell = /bin/bash
pass input = as arguments
code =
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -w <<'EOF' - $@"
# ARGV = pdf [pdf ...] [output_directory]
# * If out_directory is specified and exists, pages of every specified pdf are saved in out_directory and zipped.
# Otherwise, pages of each pdf are saved in directory named after pdf followed by "'s pages" in the same directory as pdf and zipped.
# v0.10
# written by Hiroto, 2014-10
require 'osx/cocoa'
OSX.require_framework 'PDFKit'
include OSX
def usage
$stderr.puts "Usage: #{File.basename($0)} pdf [pdf ...] [output_directory]"
exit 1
end
def quoted_form(s)
# string s : source string
# return string : s's quoted form for use in shell
# * e.g., given s = a'b, quoted form of s = 'a'\''b'
%q['%s'] % s.gsub(/'/) {%q['\'']}
end
def zip_j(d)
d = quoted_form(d)
%x[zip -j #{d}.zip #{d}/*]
end
usage unless ARGV.length > 0
outdir = File.directory?(ARGV.last) ? ARGV.pop : nil
usage unless ARGV.length > 0
ARGV.select { |f| File.file?(f) }.each do |f|
url = NSURL.fileURLWithPath(f)
doc = PDFDocument.alloc.initWithURL(url)
unless doc
$stderr.puts "Not a pdf file: %s" % f
next
end
odir = outdir ? outdir : (f + "'s pages")
Dir.mkdir(odir) unless File.directory?(odir)
(0 .. (doc.pageCount - 1)).each do |i|
page = doc.pageAtIndex(i)
line1 = ''
page.selectionForRange(NSMakeRange(0, page.string.length)).selectionsByLine.each do |q|
line1 = q.string.to_s.
gsub(/^[![:space:]]+|[![:space:]]+\z/, ''). # remove leading and trailing spaces and !
gsub(/[[:space:]:\/]/, '_') # replace space : / with _
break if line1.length > 0
end
line1 = '_' unless line1.length > 0
doc1 = PDFDocument.alloc.initWithData(page.dataRepresentation)
unless doc1.writeToFile(outfile = "#{odir}/#{line1}.pdf")
$stderr.puts "Failed to write page %d of %s to %s" % [i, f, outfile]
end
end
zip_j(odir) unless outdir
end
zip_j(outdir) if outdir
EOF
Resulting workflow will look something like this:
Tested under OS X 10.6.8.
Good luck,
H
Similar Messages
-
Flash 8 file upload .doc & .pdf help, please
I've been working with the file upload sample that came with
Flash 8 as well
as other sources to help me figure this one out... like:
http://www.flash-db.com/Tutorials/upload/index.php
Everything I seem to find out about file uploading with Flash
specifically
deals with images, but I need to upload .doc & .pdf files
to attach to an
email as part of an employment application process for a site
that is built
with Flash.
The back-end script is a simple ColdFusion file that I've
tested (and works
fine with a static HTML test page):
<cffile action="upload"
destination = "ServerAddressHERE"
accept = "image/jpg, application/msword, application/pdf"
fileField = "Form.resumeFile"
nameConflict = "Overwrite">
The Flash example script that comes with Flash 8 has been
modified as
follows:
System.security.allowDomain(" FQDN_here");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();
// When the user selects a file, the onSelect() method is
called, and
// passed a reference to the FileReference object.
listener.onSelect = function(selectedFile:FileReference):Void
// Update the TextArea to notify the user that Flash is
attempting to
// upload the image.
statusArea.text += "Attempting to upload " +
selectedFile.name + "\n";
// sample code provided by Flash
selectedFile.upload("
http://www.helpexamples.com/flash/file_io/uploadFile.php");
// my modification here (I have tried absolute references as
well):
selectedFile.upload("upfile.cfm");
listener.onOpen = function(selectedFile:FileReference):Void {
statusArea.text += "Opening " + selectedFile.name + "\n";
// Once the file has uploaded, the onComplete() method is
called.
listener.onComplete =
function(selectedFile:FileReference):Void {
// Notify the user that Flash is starting to download the
image.
statusArea.text += "Downloading " + selectedFile.name + " to
player\n";
// this part is irrelevant to my needs and I've worked with
and without it
imagesCb.addItem(selectedFile.name);
imagesCb.selectedIndex = imagesCb.length - 1;
downloadImage();
var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);
uploadBtn.addEventListener("click", uploadImage);
// this part is irrelevant to my needs and I've worked with
and without it
imagesCb.addEventListener("change", downloadImage);
imagePane.addEventListener("complete", imageDownloaded);
function imageDownloaded(event:Object):Void {
if(event.total == -1) {
imagePane.contentPath = "Message";
// this part is where I added the extensions I need:
function uploadImage(event:Object):Void {
imageFile.browse([{description: "Image Files", extension:
"*.jpg;*.gif;*.png;*.doc;*.pdf,"}]);
ANY ideas would be sincerely appreciated... even if it's just
to confirm
that the Flash file upload process ONLY works with image
files.... Thank you
ALL in advance for ANY help I can get. :-)Did you ever get your issue with the F12, publish preview,
not loading your browser? I have just upgraded from MX 2004 to 8
and now have this issue.
T Peluso
[email protected] -
Restricted font - unable to save basic pdf - help please
HI I have been trying to save PDF and ai file with PDF compatibility. I used the ai font brand new era outline G98 , and it shows me message that the font could not be embeded, and safe with PDF because of licensing restrictions....??? What do I do? I am not an expert in illustrator.
The font in question is set to not allow embedding in PDF. You might want to let the designer (Graham Meade) know that is a problem for many users.
Additionally, be aware that the standard license for this "free" (no charge) font says "This font can be used for personal use only. Businesses or companies must gain permission for use."
Contact info:
[email protected]
http://skyscraper.fortunecity.com/windows/3/gemfont.htm -
I can no longer open pdf files when clicking on a link such as: shown in troubleshooting info.
It used to work on earlier version when I had XP, now I'm Win7Pro and using version 5.0.1 The links work fine with Internet Explorer. Help, please.Type in '''about:plugins''' into the location bar and press "Enter", at the the top is a line for plug-ins test pointing to [http://www.mozilla.com/plugincheck/ mozilla.com/plugincheck/]
You should have Version: 10.1.0.534 for adobe acrobat but you have two older versions instead. If the one does not replace both you may have to disable the really old one, or remove through the control panel. -
I am trying to open PDF files from safari, but when I click on them they open in a separate window and the information is encrypted. Any ideas on how to get them to open them in Adobe? Any help please!
The pdf is loading as html code. If you save it, it will download as :
605124.pdf.html
Change the extension to .pdf
And it opens and works perfectly, I just tested it:
Use this link to download it automatically:
http://saladeaula.estacio.br/arquivo.asp?dir=00/1020624/605124.pdf&num_seq=59828 4 -
Hi,
Not able to open PDF or do any changes even if the PDF opens. Run Time Error is shown every time when trying to open PDF. Please helpHi Shilpa ,
Please refer to the following link and see if that helps you out.
https://helpx.adobe.com/acrobat/kb/runtime-error-roaming-profile-workflows.html
Are you trying to access the PDF with Acrobat or Adobe Reader?
Regards
Sukrit Dhingra -
Troubleshooting: Help please. Creating a PDF file from a Photoshop-designed project
I wanted to add personal design elements to my resume so I decided to use Photoshop to add in a logo and a footer. The problem is, when I converted the 3 Photoshop .psd files (3 pages) to .pdf files, the combined file came out to be very big in size. The biggest was 2.88 MB and the smallest that I got it to be without compromising the quality of the text and images was 1.48 MB.
What did I do wrong?
I've seen other .pdf files with more images and more color and definitely more pages and text which were only 300KB in size. How can I make my final .pdf file size small but still retain the quality of the original design from Photoshop?
I've tried merging the layers before saving. I've tried turning the files into .gif files before making the pdf. Into jpegs before making the pdf. Changing the canvas and image sizes in Photoshop into super small which made the final pdf file unreadable and super blurry. I'm at my wit's end.
Details:
.psd image size 8.5 by 11 inches (normal resume size)
colors - black, gray, light blue and light yellow
Images are very minimal, 4 lines total and around 5 circles at the header of the first page and footer of the 3rd page.
Help please!
X-cross-post: Acrobat Forum-XThis is so sad. I read your comments and I said, "Huh?" Haha!
I tried the indexed color option and it did make the final file smaller. Around 600KB. But there's probably another way to make it even smaller like the gazillion-paged pdf file that I mentioned that was only about 300KB.
And by saying a layout program, does that mean like Adobe InDesign? Does that mean that I should just make my graphics in Photoshop and then import using another program and finish the file there?
What other layout programs can I use?
Thank you so much! -
Created PDF form in Acrobat XI Pro, but HELP fields disappear when I save FCDT file to PDF. Please help. Thanks!
I am not aware of a field type "Help" within a PDF form. I do not see it as a form field that can be added in the form edit mode.
Forms Central forms do not support all the features of Acrobat forms.
Are you talking about the "Tool Tips" or a hidden field that only shows when one enters a field and is hidden upon exiting the field. -
Hi - I'm trying to sync iBooks on my Macbook Pro with iBooks running on my iPad. I have some pdf's download from the net I want to share between devices and I can't work out how to sync the two devices. Any help please? I'm running Mavericks
Thanks for your help Brij011 - much appreciated. Apologies as I'm a newbie but I've looked at the info for synching and I appear to have all the switches flicked on my iPad. Does the iPad and iBooks only sync in iCloud for purchases as I appear to be doing something wrong. I could sync ok when books was in iTunes but since migrating to Mavericks I think I'm doing something wrong!!
-
When I download PDFs on my macbook I am given the option of saving them to iCloud and in Preview they are listed under iCloud. How can I then view them on my iOS devices? Help please.
Welcome to the Apple Community.
You can't share preview files to an iOS device. There are several other options for pdf's such as Adobe Reader or iBooks. -
Hello i am rajesh i am having problem while conveting other files into pdf format please help me
i am rajesh i am having problem while converting other files into acrobat format please help me
Hello Rajesh,
I'm sorry to hear you're having trouble. Are you using Acrobat.com to convert your files to PDF? Please let me know where you are having trouble and I will do my best to help you convert your files. For your reference, here is a list of filetypes that can be converted to PDF online with Acrobat.com:
http://kb2.adobe.com/cps/524/cpsid_52456.html#Create%20PDF
Best,
Rebecca -
Hi
I have an issue in InDesign CS6. It has been happening the last couple of days now.
When i export to pdf. regardless of quality instead of being saved as a pdf it is being sent to Photoshop which then saves the file as a psd...
I have updated InDesign to the latest CS6 update which helped the issue yesterday but today the same problem is back. Help please what could be the problem and how do I fix it?
Any advice is very appreciated.
Thanks
SamExportPDF is a subscription service for exporting PDF files into Word and Excel, from Adobe Reader. I suspect you need the InDesign forum, as InDesign is the product here.
-
I can see and download pdfs in Mail, but I can't even see editable pdfs in Mail. Can anyone help please? Thx.
Thx Eric. You've helped! When I tried to copy the words written in my e-mail to show you what I meant, I right clicked to copy, and saw an option to open the attachment, which it did! So I'm sorted thank you. Editable means a form which you can fill in and send back. Thanks again. Stephen
-
Reports on web in PDF format (Please Help)
Hi
I am testing my dev2000 applications on web. I am using Patch5. I have problem while running reports. When ever I am trying to run a report from forms using "RUN_PRODUCT", report is running on server m/c not on client m/c. I need this report to be opened in clients pc in acrobat. On server m/c (Win2000 Server) registry I have set forms60_repformat=PDF. Please help to solve this peoblem.
Thanks in Advance
Syedread the paper on forms and reports integration on the web from
http://otn.oracle.com/products/forms/techlisting.html#internet -
Photos show as pdf's-Help Please!!
All my photo files show up as PDF'S. The icons for all the photos on my hard drive are pdf's. ( the red adobe icon) This includes e-mails of word docs- they also must be opened with adobe reader.. I have to save as-then open with Adobe reader in order to view any photo on my computer. I have unstalled and reinstalled several times but it stays the same. I called adobe but after 40 minutes on hold I will try this. I have win 7. Can anyone help please? Thank you!
this forum is about running the windows operating system on a mac computer
is your question about an issue with the osx version of microsoft Office word ?
Maybe you are looking for
-
im in a weird spot here i can download free games or paid games, or anything i put in a credit card but then it said it was declined and now i cant change it back to "none"
-
Adobe Reader automatic update to 10.5.8 will not load onto my Mac Yosemite. Error message is "Installer: Package name is Adobe Reader XI (11.0.10) Installer: Installing at base path / installer: The install failed (The installer encountered an error
-
IPHOTO LIBRARY FOUND IN TRASH. RESTORED AND ALL PICTURES GONE
I have iphoto 2011 installed on my imac. I had thousands of pictures installed and my imac is relatively new so I did not do a Time Machine backup or copy my photos. Unfortunately my iphoto library was in the trash and when I start iphoto it says 22
-
DB-Adapter 10g: Filtering Detail-Rows in Master-Detail-Relationship
Hi, I'm having a Master-Detail-Table e.g. Departments and Employees. Those are mapped with 1:N FK-Relationship. Using the Oracle SOA-Suite 10.1.3.5 DB-Adapter I'd like to setup a filter returning all Departments and all (e.g.) female Employees. For t
-
Is it in the plans for Vibe Desktop to allow subfolders created on the desktop in a synced folder to be synced to Vibe? Now, the folders have to be created in the Vibe web interface and then the files will be synced. It would be MUCH easier for users