how to insert/embed a gif-file in a rtf-file?

MS WORD

    Sponsored Links

    Next

  • 1. alignment problem
    im making a phone number list and want to use €from the name to the number. unfortunately, not all the names are the same length so im having trouble getting the €€line to end at the same spot for each number. example: Jane Smith€€€€€€€€€€€€€€€ 123-4567 John Doe€€€€€€€€€€€€€€€€€ 765-4321
  • 2. Font characteristic
    What font characteristic do you have when there is a word and a line crossed through it?
  • 3. word 2003 themes
    once you have applied a theme are you able to change the picture?
  • 4. The Dictionary
    We have a Department that deals with State oversite offices, and the rules are quite stringent. They also have quite a selection of terminology that must be employed within a "properly" formatted document. Thus we are constantly adding words to the (custom) dictionary. In Word 2003, how can I set up a dictionary for them that is shared so that all the words not found in the standard dictionary need only be added once, by one individual. We do have many shares available to accomplish this, if possible.
  • 5. jumping in word 2003
    what can you use to quickly jump to a specific location in a document?

how to insert/embed a gif-file in a rtf-file?

Postby dpe2001go » Sat, 03 Apr 2004 22:05:10 GMT

Hi there,

We have a program that generates a rtf-file (some 1.500 pages...) and
all of them should be signed. Problem: I'm not able to link/embed
(using insert | field) the signature-file (let's say: sign.gif), the
program works with its own templates (rtf), and I've been searching
and trying some things but after inserting, the filesize increases up
to 1,5 mb, and that's something that piece of software obviously
doesn't like. (the original 'template'/rtf is about 39 kb)

Is there a way to include/embed/... that boring sign.gif into the
rtf-file?

All tips are welcome, as long as I don't have to copy-paste for a
thousand times!

K.reg...
D

RE: how to insert/embed a gif-file in a rtf-file?

Postby U2FjaGlu » Tue, 22 Jun 2004 10:46:02 GMT

ry following C# code to embed the image in an rtf doc, tell me if it works.

/// <summary>
/// Allows the x and y coordinates of metafile to be adjusted independently
/// </summary>
private const int MM_ANISOTROPIC = 8;


/// <summary>
/// Use the EmfToWmfBits function in the GDI+ specification to convert a
/// Enhanced Metafile to a Windows Metafile
/// </summary>
/// <param name="_hEmf">
/// A handle to the Enhanced Metafile to be converted
/// </param>
/// <param name="_bufferSize">
/// The size of the buffer used to store the Windows Metafile bits returned
/// </param>
/// <param name="_buffer">
/// An array of bytes used to hold the Windows Metafile bits returned
/// </param>
/// <param name="_mappingMode">
/// The mapping mode of the image. This control uses MM_ANISOTROPIC.
/// </param>
/// <param name="_flags">
/// Flags used to specify the format of the Windows Metafile returned
/// </param>
[DllImportAttribute("gdiplus.dll")]
private static extern uint GdipEmfToWmfBits (IntPtr _hEmf, uint _bufferSize,
byte[] _buffer, int _mappingMode, EmfToWmfBitsFlags _flags);


/// <summary>
/// Wraps the image in an Enhanced Metafile by drawing the image onto the
/// graphics context, then converts the Enhanced Metafile to a Windows
/// Metafile, and finally appends the bits of the Windows Metafile in HEX
/// to a string and returns the string.
/// </summary>
/// <param name="_image"></param>
/// <returns>
/// A string containing the bits of a Windows Metafile in HEX
/// </returns>
private string GetRtfImage(Image _image)
{

StringBuilder _rtf = null;

// Used to store the enhanced metafile
MemoryStream _stream = null;

// Used to create the metafile and draw the image
Graphics _graphics = null;

// The enhanced metafile
Metafile _metaFile = null;

// Handle to the device context used to create the metafile
IntPtr _hdc;

try
{
_rtf = new StringBuilder();
_stream = new MemoryStream();

// Get a graphics context from the RichTextBox
using(_graphics = this.CreateGraphics())
{

// Get the device context from the graphics context
_hdc = _graphics.GetHdc();

// Create a new Enhanced Metafile from the device context
_metaFile = new Metafile(_stream, _hdc);

// Release the device context
_graphics.ReleaseHdc(_hdc);
}

// Get a graphics context from the Enhanced Metafile
using(_graphics = Graphics.FromImage(_metaFile))
{

// Draw the image on the Enhanced Metafile
_graphics.DrawImage(_image, new Rectangle(0, 0, _image.Width, _image.Height));

}

// Get the handle of the Enhanced Metafile
IntPtr _hEmf = _metaFile.GetHenhmetafile();

// A call to EmfToWmfBits with a null buffer return the size of the
// buffer need to store the WMF bits. Use this to get the buffer
// size.
uint _bufferSize = GdipEmfToWmfBits(_hEmf, 0, null, MM_ANISOTROPIC,
EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);

// Create an array to hold the bits
byte[] _buffer = new byte[_bufferSize];

// A call to EmfToWmfBits with a valid buffer copies the bits into the
// buffer an returns the number of bits in the WMF.
uint _convertedSize = GdipEmfToWmfBits(_hEmf, _bufferSize, _buffer, MM_ANISOTROPIC, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);


// Append the bits to the RTF string
for(int i = 0; i < _buffer.Length; ++i)
{
_rtf.Append(String.F

Similar Threads:

1.embedded file objects in rtf files

I am trying to save each embedded  file object in a rtf file.  I am able to 
get to the file object  but dont know what else to do since the OLEFormat 
doesn't have a save as method.  How can I go by on saving each file object to 
a directory? The majority of my embedded file objects are pdf file.  Here' s 
my code:

Dim oWord As Word.Application 

Dim oDoc As Word.Document

Dim fl As Word.InlineShape

Dim fr As Word.OLEFormat

oWord = New Word.Application

oWord.Visible = True

oWord.WindowState = WdWindowState.wdWindowStateMinimize

oDoc = oWord.Documents.Open(FileName)

For i = 1 To oDoc.InlineShapes.Count

     fl = oDoc.InlineShapes.Item(i)

     fr = fl.OLEFormat

     fr.open()

Next 

End If

I use the open method just to make sure I reference the file object.

Please help!!!


-- 
Juan E. Garcia

2.RTF and GIF files

When haveing an rtf referencing a gif file (import command) under Windows 2000 / Word 2000 / Sv pack 3, Word doesn't display the gif graphics (and event not print)

When haveing the same under Win2000 / Word 2000 - the graphics are visible in Page Preview and on printouts

Thanks and kind regards
Stephan Gloo
Gloor Informatik

3.Insert RTF File... Disable "Conversion File" window

4.Embedded .jpeg and .gif files

I have a document which required the files to be embedded in the document as 
icons, in Word 2000. I understand that insert-->object is a bad way to go, so 
is there any other way to embed (no I can't link the files, they must be in 
the document), jpegs and gif files into a word 2000 document without their 
size increasing by a factor of 10+? I can embed Word and Pdf files without 
much of an increase in size. Also it seems when I try to embed .gif and .jpeg 
files, word sets the icon as the Word icon, not the jpeg/gif icon.
-- 
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

5.Embedded jpeg and Gif files increasing in size

Recently I tried to embed a .gif and .jpeg into a word document. I need to 
have the files embedded and showing as an icon. The only way I know how to 
embed a picture as an icon is by inserting it as an object. But when I do, 
the file size increases by a factor of 10!!! so a 500k jpeg on a blank Word 
2000 document makes the Word document size 5 megs. I tried this with a PDF, 
and had no such problems. How can I avoid increasing the Word document size 
by 10x, but still keep embedded pictures that look like icons?

-- 
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

6. Smallest RTF file which can import or embed an image

7. MS Word 2000 and inserting .GIF files generated from MS Project 98

8. Can't insert GIF image with "Link to File"



Return to MS WORD

 

Who is online

Users browsing this forum: No registered users and 92 guest