Export Pages document to Rtfd


I’m trying to drive Pages to export documents as Rtf or Rtfd ones.
When the documents aren’t embedding graphic objects they are exported as xx.rtf but when graphic objects are embedded, I can’t find the required syntax.

Here is a quick and dirty script which I use to make tests.

set p2d to "" & (path to desktop folder)

set chemin_de_Pages to p2d & "text_and_table.pages"
my export_to_rtf(chemin_de_Pages)

set chemin_de_Pages to p2d & "with_graphics.pages"
my export_to_rtf(chemin_de_Pages)

on export_to_rtf(chemin_de_Pages)
	if chemin_de_Pages ends with ":" then
		set off7 to 2
		set off7 to 1
	end if
	tell application "Pages"
		open chemin_de_Pages as alias
		tell document 1
			set nbg to count of every graphic
			set nbt to count of every table
		end tell
		if (nbg - nbt) > 0 then
			set xType to "SLDocumentTypeRichTextBundle"
			set p_xport to (text 1 thru -off7 of chemin_de_Pages) & ".rtfd"
			set xType to "SLDocumentTypeRichText"
			set p_xport to (text 1 thru -off7 of chemin_de_Pages) & ".rtf"
		end if
			save front document as xType in p_xport
		on error errMsg number errNbr
			display dialog errMsg & return & "number #" & errNbr
		end try
		close front document saving no
	end tell -- Pages
end export_to_rtf

When the doc embed graphics, the export to rtfd fails with the error :

error “The document cannot be exported to the "Document RTF avec pièces jointes (RTFD)" format.” number -50

At this time, I am forced to use GUIscripting to achieve the goal.

Yvan KOENIG (VALLAURIS, France) mardi 1 février 2011 20:56:38

Hello Nigel Garvey

no idea about this question ?

Yvan KOENIG (VALLAURIS, France) lundi 14 février 2011 13:57:41

Bon soir, Yvan Koenig. :wink:

I’m flattered that you think I’ll know the answer to this, but I wasn’t able to come up with a non-GUI solution when I looked at it the other day. In fact, even manually exporting a letter from Pages to RTFD produced a bad result, with the letterhead and another graphic being shown at the end instead of at the beginning! :confused:

Thanks Nigel.

The export was so awful that I was wondering if I had something wrong in my system and given that hoped that there was a neat answer.

Yvan KOENIG (VALLAURIS, France) mardi 15 février 2011 10:44:50