Author Topic: Saving PDFs query...  (Read 2172 times)

0 Members and 1 Guest are viewing this topic.

Offline TecNik

  • Jr. Member
  • **
  • Posts: 98
  • Karma: 0
  • Gender: Male
Saving PDFs query...
« on: May 10, 2007, 03:52:24 AM »
Hi there,

I've written a folder action for replacing a range of pages in one pdf doc with pages from another.

All works fine apart from the saving of the new document which seems to be a little intermittent.

Please can someone have a quick look at the 'Save' line and let me know what the problem could be.
I've tried a number of things but as yet no luck.

Thanks in advance,

Nick

Here's the code:-


Code: [Select]
on adding folder items to thefolder after receiving theAddedItem

set thepath to (path to desktop folder from user domain) as string

tell application "Adobe Acrobat 7.0 Professional"
activate

open (thepath & "replace_pages:" & "ipdfmal.pdf") as text
open theAddedItem as text

set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set theAddedItem to last text item of (theAddedItem as text)
set AppleScript's text item delimiters to oldDelims

replace pages document "ipdfmal.pdf" over 1 from document theAddedItem starting with 1 number of pages 25
close document theAddedItem

save document "ipdfmal.pdf" to alias (thepath & "saved_pdf:" & theAddedItem)
end tell
end adding folder items to

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Saving PDFs query...
« Reply #1 on: May 14, 2007, 07:55:34 AM »
Nick, I've had very little sucess with FAS so this is untested advice. When you've opened the files you can reference them by name:

open blah
set docRefA to the name of document 1
open blah
set docRefB to the name of document 2

replace pages document docRefA over 1 from document docRefB starting with 1 number of pages 25

create thumbs docRefA
save docRefA to file (thepath & "saved_pdf:" & docRefB) as string) with linearize

I think your problem is "to alias" an alias is reference to existing file but you are making a new file that does not already exist. I hope I have that right?

Offline TecNik

  • Jr. Member
  • **
  • Posts: 98
  • Karma: 0
  • Gender: Male
Re: Saving PDFs query...
« Reply #2 on: May 14, 2007, 08:33:32 AM »
Hi Mark,

Thanks for the help with the query.

In the end I came up with this which works ok:-

Quote
on adding folder items to thefolder after receiving theAddedItem
   
   set thepath to (path to desktop folder from user domain) as string
   set fileToDelete to theAddedItem
   
   tell application "Adobe Acrobat 7.0 Professional"
      activate
      
      open (thepath & "replace_pages:" & "ipdfmal.pdf") as text
      open theAddedItem as text
      
      set oldDelims to AppleScript's text item delimiters
      set AppleScript's text item delimiters to {":"}
      set theAddedItem to last text item of (theAddedItem as text)
      set AppleScript's text item delimiters to oldDelims
      
      replace pages document "ipdfmal.pdf" over 1 from document theAddedItem starting with 1 number of pages 25
      close document theAddedItem
      
      save document "ipdfmal.pdf" to file (thepath & "archive_pdf:" & theAddedItem)
      close document theAddedItem
   end tell
   
   tell application "Finder"
      delete fileToDelete
   end tell
   
end adding folder items to



Thanks again,

Nick