How to save images and RTF, Word compatible

  • Using WPTools 7.07 with XE2.

    After searching in this forum, I can not figure out how to save an RTF text file with inserted images, and that the saved file could be opened using Word or WordPad (If it is possible).

    As a starting point, I am using the demo project 5_Mini_Delphi5_Editor, where I made sure that WriteObjectMode was wobRTF.
    I wrote down some text, and using the toolbar buttons, I inserted a small bitmap, and then saved the RTF in a file on disk.

    With wobRTF or wobRTFNoBinary, the bitmap is not saved in the file.
    With wobStandard, wobStandardAndRTF, wobStandardNoBinary, the bitmap is saved, and I can load it again using the demo project.
    None of those formats apears to be compatible with Word or WordPad.
    Also if I select all the text and image, copy and paste in Word, the image is not pasted.

    It is possible to get Word/WordPad compatibility ?

    • Offizieller Beitrag

    Hi,

    wobRTF is compatible to Word. WordPad has problems with jpegblib and pngblibs, the last time I checked.

    You can open the RTF in a ANSI viewer to see whats actually in there.

    But if you use custom objects, they cannot be saved as standard images. If you use InsertGraphicDialog for example, a standard image should be inserted.´

    Julian

  • Hello Julian,

    As mentioned before, I am using the demo project 5_Mini_Delphi5_Editor, and I made sure that WriteObjectMode is wobRTF.

    Then, I inserted a small bitmap (150x179) using the "Insert image" button present in the toolbar.

    Then I saved the document to file, using the "Close" button present in the toolbar.

    Looking at the file, its size is 691 Bytes, and it does not contain the image.

    If I open the saved file with NotePad, i can see a reference to "\pict" at the end, but not the bytes with the image.

    {\rtf1\ansi\deff0\uc1\ansicpg1252\deftab720{\fonttbl{\f0\fnil\fcharset1 Arial;}{\f1\fnil\fcharset2 Wingdings;}{\f2\fnil\fcharset2 Symbol;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;}\wpprheadfoot1\paperw12240\paperh15840\margl1880\margr1880\margt1440\margb1440\headery720\footery720\endnhere\sectdefaultcl{\*\generator WPTools_7.000;}{\plain\f0\fs22{\pict}\par
    }}

    Does the 5_Mini_Delphi5_Editor use InsertGraphicDialog on its internals ?

  • Hello Julian,

    As you can see in the rtf of my last reply, there is not any indication of compressed data, only I can see some small portion of code related to images at the end of the rtf file, like {\pict}\par.

    In my program, I use wobRTF and WPRichText1.SaveToFile(msFileName); which uses InsertGraphicDialog, but with the same result as mentioned.

    So, and going into the million dollar question, what code must I use to save a document that contains a small bmp to an RTF file, and get some kind of Word compatibility when loading the saved file, or doing a copy from WPRichText and pasting to Word.

  • Hello Julian

    Demo project WPMiniEditor.dproj (5_Mini_Delphi5_Editor) has practically no code, not to say that TextObject.ObjRef.Compress is not present in any part of this demo.

    If I scan text in the WPTools\XE2 or WPTools\Source folders, also there is not any presence of TextObject.ObjRef.Compress, unless in the WPOBJ_Image file, where this code is only part of a comment at the top of the file.

    Either way, compressed or not compressed, the file generated with wobRTF does not contain any image as seen in the rtf file pasted in one of my replies.

  • Using XE2 on a Dell Windows 7 Pro 32 bits.
    The function WPToolsVersion indicates that my version is 7.07.
    Demo project WPMiniEditor.dproj (5_Mini_Delphi5_Editor) does not include WPDefActions7 in the uses clause. In WPDefActions7, I can see included wpobj_image.pas in the uses clause, in practically all other modules there is not a reference to this module.

    • Offizieller Beitrag

    wpobj_image.pas is always used for image support, loading and saving. I would check out this unit and see what happens there. There are some compiler switches which change the behaviour.


    I would recommend to download a the setup from the protected site. This is what happened since V7.07.


    4.4.2014 - WPTools 7.11'
    - Ignore empty formula fields in WPTblCalc unit
    - fix problem with footnotes and margin mirror
    * HTML writer will not save span and font tags around <a> tags anymore
    + ViewOptions: wpShowParNames - this will paint the name on the left side of a paragraph
    (flag was there since wptools 4 but not used in V5 and V6)

    25.3.2014 - WPTools 7.10'
    + FormatOptionesEx2: wpfIgnorePropertyNumberStart
    * optimized JPEG export to PDF

    13.3.2014 - WPTools 7.10
    - DeleteTrailingSpace ignored the EmptyFieldsToo parameter. (was always expected to be true)
    - fixed 3 possible issues with compatibility to 64 bit
    * added some code to RTF reader to recover after inserted (garbage) RTF header codes
    - certain paragraph attributes were not read correctly from RTF after a table
    - Lines between cells were missing under certain circumstances
    - hyphenated words were sometimes printed with character overlap
    - fix problem in TWPToolbar and zoom combobox

    17.1.2014 - WPTools 7.09
    * improve compatibility with Delphi XE5
    - fix problem with fonsize combo in TWPToolbar when property ButtonHeight is 0
    - when GPP support was active BMPOs were not saved to RTF
    - if ViewOptions wpCenterPaintPages was used, the horizontal scrollbar was always visible
    - assigning a style did not reset the numberstyle of a paragraph or style


    13.12.2013 - WPTools 7.08.01'
    - wpOnlySelectInSameCell Code broke use with "CreateDynamic"

    10.12.2013 - WPTools 7.08.01
    + use format string "RTF-ParAsNewLine" to let the RTF reader convert \par to \line. This is useful when using TParagraph.LoadFromFile.
    - in seldom cases Reformat was not called after deleting a selection which caused an AV in the paint procedure
    - When WPBRD_DRAW_Finish was used, the top padding was even applied when the previous cell was also bordered.

    3.12.2013 - WPTools 7.08
    + EditOptionsEx2 wpOnlySelectInSameCell allows only selection inside same cell or whole table
    + added PrintParameter.PrintHeaderFooter settings: wprOnlyOnOddPages, wprOnlyOnEvenPages
    + TParagraph.CreateCopyList has new mode flag: wpParCopyStyles
    * improved selection code for cell selection.
    Works better when merged cells are used.
    - when deleting a column the next column was not always resized correctly.
    - Undo for DeleteColumn did not preserve style
    - in WPTools Premium Edition Report templates were displayed incorrectly


    17.11.2013 - WPTools 7.07.1
    + usually otline numbering works on a complete section. With FormatOptionsEx2 wpfRestartOutlineNumbersAfterRegularText it
    will now be restarted after text which was not numbered. (Compatibility to HTML browser)
    * HTML writer will not write margins in <li> elements due to compile symbol NOMARGINS_IN_LIST
    - HTML reader created wrong paragraph nesting with some HTML files
    - WPPremium: Footnotes were moved in X direction
    + WPPremium: added function InputTextbox to simplify Textbox creation
    - WPPreviewDlg property ZoomMode was ignored
    - RTF reader added the name "HYPERLINK" to hyperlink start objects
    - if a moveable image does not fit on the page a new paragraph will be created
    - when colored text was selected the first non selected character will be painted in paragraph color