Basic Questions

  • There are so many questions, I don't know where to begin.

    How to save WPRichText contents to a RTF file and retain the embedded images?

    Why are some images encoded in hex and others in ASCII extended chars?

    How to insert an image into WPRichText? InsertGraphicDialog is not enough?

    Could you please *explain* the basics of working with RTF and embedded images.

    I've already spent 4 hours searching for answers on Google and on this website and now it is time to consider a career change. Very few programmers can teach well, it seems.

    • Offizieller Beitrag

    Hello,

    Q: How to save WPRichText contents to a RTF file and retain the embedded images?

    A: Normally all images will be saved to RTF. Using the property WriteObjectMode you can control how they are saved. The setting wobRTF should be used.

    Q: Why are some images encoded in hex and others in ASCII extended chars?

    A: If saving was selected as "binary" full 8 bit are used. Otherwise HEC encoding is used. Binary is default. In case the images are saved using wobWPTools (WriteObjectMode) they are stored as ASCII. This should not happen for BMP, EMF, JPEG and PNG. They all can be saved binary.

    Q: How to insert an image into WPRichText? InsertGraphicDialog is not enough?

    A: Actually it is - this is how it is declared:

    function InsertGraphicDialog(
    filter: string = '';
    InsertLink: Boolean = FALSE;
    ObjectModes: TWPTextObjModes = []
    path : string = ''
    ): TWPObject;

    Internally the method used code like this:

    var newimage : TWPObject;
    InsertedObj: TWPTextObj;

    newimage := WPLoadObjectFromFile(WPRichText, FileName, InsertLink);
    InsertedObj := WPRichText.TextObjects.Insert(newimage );

    Now it uses InsertedObj to modify the properties of the new image. (You can examine the code in WPCtrRich.pas. This unit contains lots of usful code which serve as example)

    Could you please *explain* the basics of working with RTF and embedded images.

    Please check out the unit wpobj_image.pas. Without this unit there is no image support. It is also the link to JPEG and PNG and GIF support. The latter 2 require 3rdparty libraries.

    Using the formatstrings, this is the string which can be passed to the LoadFromFile and similar IO methods You can control the output.

    This string makes it possible to deactivate the images at savetime (-noimages) or force the writing as ASCITT code (-nobinary)


    If something is unclear please let me know.

    Julian

  • I work in a company that uses your product. Imagine this scenario, there is an rtf that gets produced from a WPTools component. This rtf is then wrapped with other info to create a .pit file (not old Mac archive) which is used in some email system. Usually, the rtf can be extracted from the pit file with a simple copy and paste operation, but sometimes the rtf causes errors when opened in Word or WordPad. Sometimes we get "out of memory" messages, other time the image is completely missing from the rtf. Basically, the rtf is corrupted during the process.

    I want to make sure that the images are encoded using standard text characters (no extended ASCII > ord(127)). Is there a way to do that? How?

    Appreciate the help.