Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript - Extract data from fdf file

I'm a newbie in AppleScript. I tried to read fdf file and find the comments in the file.

FDF File


%FDF-1.2
%‚„œ”
1 0 obj
<</FDF<</Annots[2 0 R 3 0 R 4 0 R 5 0 R 6 0 R 7 0 R 8 0 R 9 0 R]/F(/Untitled 1_2/Users/gmuniandy/Desktop/stylecheck/BoldTest2 2.pdf)/ID[<3D0C838BAEE04E3CB82F7182A96AF453><786E2F2D97524ECFB3BDA2BA97E84FF0>]/UF(/Untitled 1_2/Users/gmuniandy/Desktop/stylecheck/BoldTest2 2.pdf)>>/Type/Catalog>>
endobj
2 0 obj
<</C[1.0 0.0 0.0]/Contents(Change this to Hi World)/CreationDate(D:20140120160021+08'00')/F 4/M(D:20140120160044+08'00')/NM(5975f48e-1e02-4e43-b94d-bd07af2a8573)/Page 0/Popup 3 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:9.0.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.0pt;text-align:left;color:#000000;font-we\
ight:normal;font-style:normal">Change this to Hi World</span></p></body>)/RD[0.5 0.5 0.5 0.5]/Rect[146.562 777.358 300.252 814.244]/Subj(Rectangle)/Subtype/Square/T(gmuniandy)/Type/Annot>>
endobj
3 0 obj
<</F 28/Open false/Page 0/Parent 2 0 R/Rect[595.28 693.744 775.28 813.744]/Subtype/Popup/Type/Annot>>
endobj
4 0 obj
<</C[1.0 0.0 0.0]/Contents(stroke to strike)/CreationDate(D:20140120160117+08'00')/F 4/M(D:20140120160133+08'00')/NM(a2855894-82c2-b142-b765-2a8ae52e1b14)/Page 0/Popup 5 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:9.0.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.0pt;text-align:left;color:#000000;font-we\
ight:normal;font-style:normal">stroke to strike</span></p></body>)/RD[0.5 0.5 0.5 0.5]/Rect[296.438 591.596 376.246 626.371]/Subj(Rectangle)/Subtype/Square/T(gmuniandy)/Type/Annot>>
endobj
5 0 obj
<</F 28/Open false/Page 0/Parent 4 0 R/Rect[595.28 505.871 775.28 625.871]/Subtype/Popup/Type/Annot>>
endobj
6 0 obj
<</C[1.0 0.0 0.0]/Contents(bold it)/CreationDate(D:20140120160106+08'00')/F 4/M(D:20140120160111+08'00')/NM(59711a0e-4d5f-0a47-ad6a-ec88f848d577)/Page 0/Popup 7 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:9.0.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.0pt;text-align:left;color:#000000;font-we\
ight:normal;font-style:normal">bold it</span></p></body>)/RD[0.5 0.5 0.5 0.5]/Rect[249.997 635.926 320.658 689.699]/Subj(Rectangle)/Subtype/Square/T(gmuniandy)/Type/Annot>>
endobj
7 0 obj
<</F 28/Open false/Page 0/Parent 6 0 R/Rect[595.28 569.199 775.28 689.199]/Subtype/Popup/Type/Annot>>
endobj
8 0 obj
<</C[1.0 0.0 0.0]/Contents(not bold)/CreationDate(D:20140120160051+08'00')/F 4/M(D:20140120160059+08'00')/NM(c8271566-7ca6-5c40-92b3-df3c7f926f19)/Page 0/Popup 9 0 R/RC(<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:9.0.0" xfa:spec="2.0.2" ><p dir="ltr"><span dir="ltr" style="font-size:10.0pt;text-align:left;color:#000000;font-we\
ight:normal;font-style:normal">not bold</span></p></body>)/RD[0.5 0.5 0.5 0.5]/Rect[293.623 699.958 350.211 744.583]/Subj(Rectangle)/Subtype/Square/T(gmuniandy)/Type/Annot>>
endobj
9 0 obj
<</F 28/Open false/Page 0/Parent 8 0 R/Rect[595.28 624.083 775.28 744.083]/Subtype/Popup/Type/Annot>>
endobj
trailer
<</Root 1 0 R>>
%%EOF

I managed to read the file by doing this.

set the_file to choose file
set the_text to (do shell script "cat " & quoted form of (POSIX path of the_file))
set the clipboard to the_text

Is the anywhere i can extract only the highlighted value. The one in red color. Please advice.

Posted on Jan 20, 2014 7:49 PM

Reply
3 replies
Sort By: 

Jan 20, 2014 9:46 PM in response to tauruzian

I'm not sure I understand your question.


If you want to read the file, you can do that directly (via read file...) without the need to use a shell command.


Secondly, the 'highlighted value... in red' is the cat command itself, which is in no way related to the contents of the file.

So what content of the FDF file are you trying to extract?

Reply

Jan 20, 2014 9:54 PM in response to Camelot

Thanks for the reply Camelot. The highlighted in red in FDF file not cat. I dont know why my highlighted values gone. BTW, in my FDF file i need to fetch my contents like "

Change this to Hi World
","
stroke to strike
","
bold it
",and "
not bold
". These are the values i need to fetch from fdf file.

Reply

Jan 21, 2014 5:25 PM in response to tauruzian

Managed to do this using Split:



--set the_file to choose file

set shape to {}

set contentvalue to {}

set coordinates to {}

set the_file to "/Users/gmuniandy/Desktop/stylecheck/testfdf2.fdf"

set the_text to (do shell script "cat " & quoted form of (POSIX path of the_file))


--- Get Contents

set tmp to my splitString(the_text, "<</C[1.0 0.0 0.0]/Contents(")

repeat with message in tmp

set tmp1 to my splitString(message, ")/CreationDate")

repeat with message1 in tmp1

if message1 starts with "%FDF" then

else

if message1 starts with "(D" then

if message1 contains "Rectangle" then


--display dialog "Rectangle"

set end of shape to "Rectangle"


end if

else

set messageContents to text of (message1 as string)


-- put in the list

set end of contentvalue to messageContents


--display dialog messageContents

end if

end if

end repeat

end repeat



-- Get shape


set tmps to my splitString(the_text, "/Rect[")

repeat with messages in tmps

set tmp1s to my splitString(messages, "]/Subj")

repeat with message1s in tmp1s

if message1s starts with "%FDF" then

else

if message1s starts with "(Rectangle)" then

else

if message1s contains "CreationDate" then

else

if message1s contains "EOF" then

else

set messageContentss to text of (message1s as string)


-- put in the list


--display dialog messageContentss

set end of coordinates to messageContentss

end if

end if

end if

end if

end repeat

end repeat


repeat with i from 1 to count of contentvalue

set contValue to itemi of contentvalue

set shapesValue to itemi of shape

set coorValue to itemi of coordinates

display dialog {contValue & " " & shapesValue & " " & coorValue}

end repeat



to splitString(aString, delimiter)

set retVal to {}

set prevDelimiter to AppleScript's text item delimiters

logdelimiter

set AppleScript's text item delimiters to {delimiter}

set retVal to every text item of aString

set AppleScript's text item delimiters to prevDelimiter

return retVal

end splitString

Reply

Applescript - Extract data from fdf file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.