Reading Data From A Graphic/Image File

Hi,
Once data has been read from say an Image file - (i.e PDF) - Placed into a Var & coerced to PDF (using the “read” Cmnd’s"as" Param), does anyone know of a solution to set either an Indesign Rect or a FM container cell, to the contents of that Var?

Whilst this solution doesn’t quite resolve the prob, it gives a basic insight into how image files’ code can be read from 1 obj & written to another:

(* --------File’s Definition:--------
This file demonstrates how to read data from an Image file & write the (extracted) data back to the same or another file of the -
same format. However, any attempt to read data from 1 image file format to another, will fail. For Example: Reading data from -
a PDF file & writing its data to a PICT file will rtn the following errMsg upon attempting to open it: -

“Couldn’t open the file. It may be corrupt or a file format that Preview doesn’t recognize.”

what’s more, the identifier of a newly created file, will by default always be: “text”. To this end, double clicking on it will -
cause it to be opened by “TextEdit”. However, in order for it to be opened by the Preferred Graphic App; either drop the file -
onto the Apps ic icon or use the “open with” Cmnd by right clicking. Thus, in order for the file to be opened by the appropriate -
Graphic App when double clicking on it, it must be resaved by the App in which it has been opened. Furthermore, it may be
Poss to set the file’s identifier with AS by using a resource scripting addition such as: “The Resource IO AppleScript addition” -
Not sure whether it’ll work in OSX. *)

–Permits user to choose file of types: PDF & PICT → Append List to extend scope
set targetFile to (choose file with prompt “Choose a PDF file” of type {"PDF ", “PICT”}) as string

try

-->Basic Reading From doesn't  Req Target File to be Opened for Access
set readFile to read (file targetFile) --as "pdf" - Coercion Optional - Not necessary

(* Allows user to Enter name of file to be written to - Result passed to var: "writeFile" is used by: -
    "open for access" & "close access" Cmnds below & in "on error" handler respectively. *)
set writeFile to (text returned of (display dialog "Enter file Name" default answer "Scrn Snapshot2.pdf") as string)

--> "open for access" Cmnd Rtns refNum to Opened File -- Faster way of referencing a File Opened for Access
--> Note: If file doesn't exist, file obj ref will cause a New file to be Created
set fileNum to open for access file ((path to desktop from user domain as string) & writeFile) with write permission


(* -->Clr Contents of Target File Ahead of Overwriting it - Sometimes Needed; prevents target file corruption & following errMsg"
from being displayed: "Preview is unable to properly display this image. The file may be corrupt. Reason: Can't cache image". *)
--set eof fileNum to 0

--> Writes data read from target file back to target file
write readFile to fileNum

--uses refNum rtned by "open for access" Cmnd
close access fileNum

return targetFile & "'s Execution: Successful"

on error errMsg

(* In the event of an err occuring preceding or on "open for access" Cmnd Ln, a refNum -
    wouldn't have been rtned - Therefore full path to target file is used instead. *)
close access file ((path to desktop from user domain as string) & writeFile)

display dialog errMsg

end try

[quote=“shars”]

Whilst this solution doesn’t quite resolve the prob, it gives a basic insight into how image files’ code can be read from 1 obj & written to another:

(* --------File’s Definition:--------
This file demonstrates how to read data from an Image file & write the (extracted) data back to the same or another file of the -
same format. However, any attempt to read data from 1 image file format to another, will fail. For Example: Reading data from -
a PDF file & writing its data to a PICT file will rtn the following errMsg upon attempting to open it: -

“Couldn’t open the file. It may be corrupt or a file format that Preview doesn’t recognize.”

what’s more, the identifier of a newly created file, will by default always be: “text”. To this end, double clicking on it will -
cause it to be opened by “TextEdit”. However, in order for it to be opened by the Preferred Graphic App; either drop the file -
onto the Apps ic icon or use the “open with” Cmnd by right clicking. Thus, in order for the file to be opened by the appropriate -
Graphic App when double clicking on it, it must be resaved by the App in which it has been opened. Furthermore, it may be
Poss to set the file’s identifier with AS by using a resource scripting addition such as: “The Resource IO AppleScript addition” -
Not sure whether it’ll work in OSX. *)

Permits user to choose file of types: PDF & PICT → Append List to extend scope
settargetFileto (choose filewith prompt "Choose a PDF file" of type {"PDF ", "PICT"}) asstring

try

>Basic Reading From doesn’t Req Target File to be Opened for Access
setreadFiletoread (filetargetFile) –as “pdf” - Coercion Optional - Not necessary

(* Allows user to Enter name of file to be written to - Result passed to var: “writeFile” is used by: -
“open for access” & “close access” Cmnds below & in “on error” handler respectively. *)
setwriteFileto (text returnedof (display dialog "Enter file Name" default answer "Scrn Snapshot2.pdf") asstring)

> “open for access” Cmnd Rtns refNum to Opened File – Faster way of referencing a File Opened for Access
> Note: If file doesn’t exist, file obj ref will cause a New file to be Created
setfileNumtoopen for accessfile ((path todesktopfromuser domainasstring) & writeFile) withwrite permission


(* -->Clr Contents of Target File Ahead of Overwriting it - Sometimes Needed; prevents target file corruption & following errMsg"
from being displayed: “Preview is unable to properly display this image. The file may be corrupt. Reason: Can’t cache image”. *)
set eof fileNum to 0

> Writes data read from target file back to target file
writereadFiletofileNum

uses refNum rtned by “open for access” Cmnd
close accessfileNum

returntargetFile & "'s Execution: Successful"


onerrorerrMsg

(* In the event of an err occuring preceding or on “open for access” Cmnd Ln, a refNum -
wouldn’t have been rtned - Therefore full path to target file is used instead. *)
close accessfile ((path todesktopfromuser domainasstring) & writeFile)

display dialogerrMsg

endtry


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

I USE THIS FOR EXPORT AI DOCS TO JPG AND REGISTER IN FM WITH DOCUMENT NAME

tell application "Finder"
	set targetFolder to "HD:" -- SET THE FOLDER WHERE THE FILE WILL SAVE
	set targetPath to targetFolder as string
	try
		tell application "Adobe Illustrator 10"
			activate
			set user interaction level to never interact
			set documentCount to count documents
			repeat with i from 1 to documentCount
				
				set documentName to name of document 1 as string
				set registro to items 1 thru 11 of documentName as string
				export document 1 to file (targetPath & registro) as JPEG ¬
					with options {class:JPEG export options, quality:50, optimization:false, horizontal scaling:200, vertical scaling:200}
				close document 1 saving no
				set archivo to (targetPath & registro & ".jpg") as string -- THIS IS TEH PATH OF IMAGE
				
				tell application "FileMaker Pro"  
					activate
					
					open " " --YOU HAVE TO SPECIFY THE PATH OF DATABASE IN FM 
					show layout "IMAGENES"
					do script "showall" -- YUO HAVE TO MAKE AN SCRIPT "SHOW ALL" IN FM
	
					show (every record whose cell "Codigo" = registro) --THIS INSTRUCTION FIND A RECORD IN FM WITH THE KEY THAN NAMES LIKE DOCUMENT IN AI,  YOU CAN MAKE A NEW RECORD INSTEAD THAT
					
					set cell "Image" of current record to file archivo -- THIS IS THE CONTAINER CELL, YOU SHOULD TO  HAVE THIS CELL
					
				end tell
			end repeat
		end tell
	on error e
		display dialog e
	end try
end tell