wrote:
Quoting Rob Dixon <
[email protected]>:
John wrote:
Rob Dixon wrote:
John wrote:
I want to create a doc file that will contain my text,
fonts, sizes as if i wrote manually.
You can use Win32::OLE drive MSWord itself to generate a document,
but I think that's an awful way to do things. Why not look at
RTF::Generator which will let you create an RTF file which Word
will then read happily.
My apologies, that should have been RTF::Writer.
Have you got any relevant code?
Hi John.
Something like this?
use strict;
use warnings;
use RTF::Writer;
my $rtf = RTF::Writer->new_to_file("demo.rtf");
$rtf->prolog;
$rtf->paragraph(
\'\b', # Bold
\'\ul', # Underline
"Title");
$rtf->paragraph; # Blank First Paragraph
$rtf->paragraph(
"First text paragraph.");
$rtf->paragraph(
"Second text paragraph", \'\line',
"with an explicit line break.");
$rtf->close;
But you'll be better informed by reading the RTF::Writer POD
which includes an RTF primer called RTF::Cookbook.
Your solution is also amazing but where can i define the TrueType fonts for
every single word? Or the size of them, color,...
Hi.
A name would be nice...?
All of the answers are in the module documentation. The code below shows
a lot of the common requirements. Anything else you can fish from the
POD.
Sean, the author of the module, has written O'Reilly's "RTF Pocket Guide"
which I haven't seen but assume is still in print. It will be much more
comprehensive than the RTF::Cookbook POD.
HTH,
Rob
use strict;
use warnings;
use RTF::Writer;
my $rtf = RTF::Writer->new_to_file("demo.rtf");
$rtf->prolog( fonts => ['Times New Roman', 'Courier New'] );
$rtf->print(\'\f0\fs24'); # Default to Font zero (Times) in 12 pt
$rtf->paragraph(
\'\sa120', # 6pt space after paragraph
\'\b', # Bold
\'\ul', # Underline
"Title");
$rtf->paragraph; # Blank First Paragraph
$rtf->paragraph(
\'\sa120',
"First text paragraph.");
$rtf->paragraph(
\'\sa120',
\'\f1', # Font 1 (Courier)
"Second text paragraph in Courier New",
\'\line',
"with an explicit line break.");
$rtf->paragraph(
\'\sa120',
"Third text paragraph reverts to default font zero.");
# Most arguments takes measurements in twips (twentieths of a point)
# so \sa120 is a space-after of 6 points
# Font Size takes measurements of half a point, so \fs16 is 8-point
#
$rtf->paragraph(
\'\sa120',
\'\f1',
\'\fs16', # Font size 8pt
"Fourth text paragraph in Courier New 8pt ",
"with no explicit line break but extended text ",
"to show that automatic line wrapping applies ",
"just as in Word."
);
$rtf->paragraph(
\'\sa120',
"Fifth text paragraph.");
$rtf->close;