Setting font style for RTF document

时光毁灭记忆、已成空白 提交于 2019-11-30 17:34:07

问题


Having trouble setting text font style as Times New Roman for this document. I want all the test to be times new roman size 10. I generated a font table that holds the type and its the only type of my document. I want all the text to be times new roman but whenever the doc is generated it says its corrupted for some reason but if I don't set the font style the doc comes out in courier text as default and its not corrupted.

{\fonttbl{\f1\froman\fprq0\fcharset0 Times New Roman;}
\par
Hi <#name#>
\par\par

Welcome to New York \par\par

\b New iPad\'ae App Is Available \b0 \par 
These are all the exciting things you cna do during your stay. \par \par
}

回答1:


You're missing a lot of formatting in your example up there. For example, save a very simple RTF file from Wordpad or another application (Word puts in too much metadata) and see everything that you're missing.

First, Here is the most recent RTF Spec, 1.9.1. This will help you work through anything RTF related.

Second, any RTF document must start with \rtf*N* where N is the RTF Version (currently 1). You're missing this in your example. This is among one of the many reason why it is saying the file is corrupted.

Third, you define something in the font table and then don't use the definition, f1. This is an old spec for RTF, 1.6, but look at how the font table is defined.

There are many other things, but I think that you're using RTF like you would use HTML or something with tags. I would readup on the specification to see how RTF works. Here is a very small RTF document:

    {\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2
{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Tahoma;}}
{\colortbl\red0\green0\blue0;\red255\green255\blue255;}
\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs16\f2\cf0 \cf0\ql
{\f2 {\ltrch This is a test of RTF.}\li0\ri0\sa0\sb0\fi0\ql\par}}}


来源:https://stackoverflow.com/questions/14401902/setting-font-style-for-rtf-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!