在iOS中创建RTF,DOC或DOCX [英] Creating RTF , DOC , or DOCX in iOS

查看:99
本文介绍了在iOS中创建RTF,DOC或DOCX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用iOS应用创建以下文件类型之一:RTF,DOC或DOCX.用户应该能够写文本,还可以添加图像.UI的构建不是问题,仅是文件的创建.

I want to create one of the following filetypes with an iOS-App: RTF, DOC or DOCX. The user should be able to write text and also add images to it. The building of the UI isn´t the problem, only the creating of the File.

是否有最佳实践来做到这一点?!

Are there any best practice to do this?!

第三方框架是一个选项,但我想自己做.

3rd Party Frameworks are an option, but i would like to do it myself.

谢谢

推荐答案

我可以为您提供docx文件(RTF文件更容易,doc文件与docx完全相同,但组织性较差)

I can help you for docx files (RTF files are easier and doc files are quite the same as docx but less well organised)

我认为您最好的办法是从在文本编辑器中打开docx文件开始.您首先需要解压缩文件.

I think the best you could do is to start by opening a docx file into a text editor. You have first to unzip the file.

您将拥有以下文件夹

>_rels
>customXML
>docProps
>word:
    >_rels:
         document.xml.rels //this document tells word where the images are situated
    >media  //Here are the images
    >theme
    >document.xml //Here is the actual content of the file
    >header1.xml //Here is the content of your header
>[Content_Types].xml

要插入一些文本,请查看document.xml文件.

To insert some text, have a look at the document.xml file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<w:body>
....
</w:body>
</w:document>

Docx对段落使用< w:p> 标记.对于具有一种格式的文本块,它使用< w:r> .它对实际文本使用< w:t>

Docx uses <w:p> tags for paragraphs. It uses <w:r> for blocks of texts that have one format. It uses <w:t> for the actual text

这将产生一个简单的Hello world

This will produce a simple Hello world

<w:p w:rsidP="00CA7135" w:rsidR="00137C91" w:rsidRDefault="00137C91">
    <w:r>
        <w:t>Hello world</w:t>
    </w:r>
</w:p>

对于图像,您将需要添加更多信息:

For images, you will have to put more information:

            <w:p w:rsidP="00CA7135" w:rsidR="00B12C70" w:rsidRDefault="00B12C70">
                <w:r>
                    <w:rPr>
                        <w:noProof/>
                        <w:lang w:eastAsia="fr-FR"/>
                    </w:rPr>
                    <w:drawing>
                        <wp:inline distB="0" distL="0" distR="0" distT="0" wp14:anchorId="7CC0BC42" wp14:editId="09031C8D">
                            <wp:extent cx="866775" cy="1323975"/>
                            <wp:effectExtent b="9525" l="0" r="9525" t="0"/>
                            <wp:docPr id="13" name="Image 13"/>
                            <wp:cNvGraphicFramePr>
                                <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
                            </wp:cNvGraphicFramePr>
                            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                                <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                                    <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                                        <pic:nvPicPr>
                                            <pic:cNvPr id="0" name=""/>
                                            <pic:cNvPicPr/>
                                        </pic:nvPicPr>
                                        <pic:blipFill>
                                            <a:blip r:embed="rId15"/>
                                            <a:stretch>
                                                <a:fillRect/>
                                            </a:stretch>
                                        </pic:blipFill>
                                        <pic:spPr>
                                            <a:xfrm>
                                                <a:off x="0" y="0"/>
                                                <a:ext cx="866775" cy="1323975"/>
                                            </a:xfrm>
                                            <a:prstGeom prst="rect">
                                                <a:avLst/>
                                            </a:prstGeom>
                                        </pic:spPr>
                                    </pic:pic>
                                </a:graphicData>
                            </a:graphic>
                        </wp:inline>
                    </w:drawing>
                </w:r>
            </w:p>

此标记内的ID(13):< wp:docPr id ="13" name =图像13"/> 必须是唯一的.然后,Word将查看document.xml.rels以查看图像的存储位置.

The id (13) inside this tag: <wp:docPr id="13" name="Image 13"/> must be unique. Word wil then look at the document.xml.rels to see where the image is stored.

Document.xml.rels:

Document.xml.rels:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId8" Target="endnotes.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"/>
    <Relationship Id="rId13" Target="media/image5.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId18" Target="media/image10.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId26" Target="header3.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"/>
    <Relationship Id="rId3" Target="styles.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"/>
    <Relationship Id="rId21" Target="media/image13.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId7" Target="footnotes.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"/>
    <Relationship Id="rId12" Target="media/image4.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId17" Target="media/image9.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId25" Target="footer1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"/>
    <Relationship Id="rId2" Target="numbering.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"/>
    <Relationship Id="rId16" Target="media/image8.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId20" Target="media/image12.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId1" Target="../customXml/item1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"/>
    <Relationship Id="rId6" Target="webSettings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"/>
    <Relationship Id="rId11" Target="media/image3.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId24" Target="header2.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"/>
    <Relationship Id="rId5" Target="settings.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"/>
    <Relationship Id="rId15" Target="media/image7.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId23" Target="header1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"/>
    <Relationship Id="rId28" Target="theme/theme1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"/>
    <Relationship Id="rId10" Target="media/image2.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId19" Target="media/image11.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId4" Target="stylesWithEffects.xml" Type="http://schemas.microsoft.com/office/2007/relationships/stylesWithEffects"/>
    <Relationship Id="rId9" Target="media/image1.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId14" Target="media/image6.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId22" Target="media/image14.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>
    <Relationship Id="rId27" Target="fontTable.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"/>
</Relationships>

如您所见,使用此标记,ID为13的图像位于Target属性中.

as you can see, with this tag, the image with id 13 is locafted at the Target attribute.

<Relationship Id="rId13" Target="media/image5.png" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"/>

这篇关于在iOS中创建RTF,DOC或DOCX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆