Objective-C:从NSAttributedString中的RTF文件中检索非标准属性

时间:2016-06-23 18:25:38

标签: objective-c cocoa nsattributedstring rtf appkit

我试图从RTF文件创建一个属性字符串对象,如下所示:

NSMutableAttributedString *rtfString = [[NSMutableAttributedString alloc] initWithURL:url options:@{} documentAttributes:NULL error:&error];

问题在于对于带有嵌入图像的RTF文件(参见下面的示例),在阅读过程中忽略了与图像相关的控制字和数据(据我所知),因此它们不作为属性或附件出现在属性字符串。

我的问题:如何使用RTF文件中的自定义/非标准属性填充NSAttributedString对象的属性?具体来说,我希望能够检索有关嵌入图像的信息,包括其相关的十六进制数据和字符串中的位置。获得此信息后,应该很容易将每个图像添加为属性字符串的附件。

注意:我知道NSAttributedString可以使用RTFD格式处理图像和附件,但是不能将RTF转换为RTFD,因为我无法控制输入文件。

带有图像的RTF文件示例:

{\rtf1
some text before \line
{\pict\jpegblip
FFD8FFE000104A46494600010101004800480000FFDB004300191113161310191614161C1B191E253E29252222254C373A2D3E5A505F5E595057566470907A64
6A886C56577DAA7E889499A1A2A16178B0BDAF9CBB909EA19AFFDB0043011B1C1C252125492929499A6757679A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A
9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9A9AFFC0001108004D006403011100021101031101FFC400190000020301000000000000
000000000000010200030405FFC4002E100002010203060601050100000000000001020003111221310413415152912261627181A132234243C1D1E1FFC40018
01010101010100000000000000000000000001020304FFC4002511010100020202030000070000000000000001021103211231415171041322324261D1FFDA00
0C03010002110311003F007C0BD23B4E8D0E05E91DA412C9D23B428597A07685D54183A476841C2BD23B42A605E91DA0428BD23B4214A2F48ED014AAF48ED2A0
155E91DA002ABC8768145655C5A0D394237C2949BC8BA1442EE141009E2663933F0C6E5A6F19B5AA4A1349C5984CE39CCE794769D7447B13E35F91373FD3396B
E61701D50DFCB8CBB62E1F401F8112B037BC0060298429940308A2B7E43DA11B8E92351152E2F26DD3C562D30C0F2109F88D4CD501598EF13F16E63919E5CB1B
C596F1F55DF1CA59D96E540DE0057830D3FE4EB8F24CBF56C029C54CE9B73B8FD21B1C9C7CC7E25D5F6464619A9B8976CDC3E898F9CAC0DE0298429845158F88
7B40DCDA42883600904807300DAE263396CB31F6ED8D93DAE0DB3B3D92A321E96245E793CB9F1EB2EDD27E19EE84781B2D2EF94D4B739AF26A485BD32AD53030
2D93A83600CE731CE65E16FAF54EFD11569630AA2AA13A78C58CE995E5C26ED9AFC37BEC30A1254AD4C40E777B4D4BC966E5859019513334EA8F3DE4BAE4FB86
A42D5A48956D76B150733720CD71679653759CFC6CED8F6AAC367650016BEA4709D76E171ED13684A9C73E52CBB66CB0F79514562310F684746D710A08D66CF3
1C4495B941D72B300441DC0467A7953720749CC4E79716397B8E9392FCF6BA9D65B115295AE332998ED3CF9F1673BC6EDD265E5EA81A2C56F4996A21E5FE4D63
FC44F59CD3371EFE8BBC23C3555881A752FF00B2F87F971D6B7AF6BE9AE3CB1074199B6BF22633E5B26ACD55B74CF54A956AACD9EB6FEA77C278C92267239C7F
326A1272CEDA09BDCDF6F3D975B667C02A1C02E38CAE76D45DA2A02421CBCE368956B96605945EDAF38DABB62694196F98D614A1AD91EC645946C0E86C79185E
AA7894F10617B87425C6EC1B31CD0F9F29E6E5C7C2F9FC7CBB619EFD8AD5A9FC803A8EA1FDC5E1C6CDE1746F57562C0D4B740A3EE9EAD88C47503CE79F7979FF
0054F291AB2ED936B77A7501AF4FC00101D742C74BF30277C2E37FB2A5F4CB4D9372EAC7F50F3E53B6BB72B6698F6820B5C5BDE571AA16A14BF9F38D22EC4A40
26C2F1A5D5AED89D01810807585294B7E26410315C8C69A99582703712A79C9675A6B1B37B58D48ED02E1954E8E2FF00627926578B78DEFEBFE3B7D33ED15519
99FF008D4587B09DB8B1F1C7BF6C677BD3254DBAA50744501D0E669B66233E397BF54FE6DDB1D427166709D6DC26E7A71CBBA537FDCBF2B2EE33655245DAC339
596B6A192D9869DA65DEE36751D713A390C037854810D8EB2042838650A4653E7F12592B78F2658FA67DAEA108A29D2B906E40E4234972DB0229AB5D98E5737B
7299612A8235B91E70955A54606DCE34B2ADA7858E3B69136D492F65A8016B9835B76C4E8C0C030242A4012006148CA0E708C9B56CED52CC96B8F8264B12ED81
83AB61A80AF999349B406CEA105C716B6A64D2AD202F846435875935D2B739C8B5D7DF7A7EE75711DF7A7EE04DF7A7EE04DF7A7EE04DF7A7EE00DF7A7EE400D6
F4FDC281ADE9FB8086AFA7EE023D456521D030E46118F1056200384682F335AC6765C77CCF192B78DF923367A48B6BFFD9
}
\line some text after
}

0 个答案:

没有答案