Current filter:
                                You should refresh the page.
                                  • In our usage of your system, we allow the users to create/edit documents and to embed images from an image library that we have, which includes some fairly large images.

                                    Suffice it to say, the RTF/DOCX content can become quite large when including these images.

                                    We wanted to know if there is an equivalent of <img src=""> where we can SHOW the image in the document, but not STORE the image in the document.

                                    This should allow us to load the document pretty quickly and save it efficiently.

                                1 Solution

                                Creation Date Importance Sort by

                                [Updated by Maria]
                                The RTF specification supposes storing document images in the hexadecimal (base64) format. If you want to export only an image Uri (not image bytes), I suggest you insert images in the document using the IncludePicture field. This field inserts the picture retrieved from the specified URI. The \d switch enables you to not store the image in a document file. So, if you create an IncludePicture field and specify the required Uri and \d switch in the field code and export the document to Rtf, only the image URI will persist in the exported document.
                                Note that this field doesn't provide the capability to specify the size that should be applied to the image after retrieving. So, the image is always inserted with its original size.

                                Hello Chaim,
                                Please try the recommendations provided in the How to: Reduce the File Size When Saving a Document Containing Pictures article to reduce the exported document size.
                                Should you have any questions or need further assistance, do not hesitate to contact me again.

                                Show all comments
                                • Chaim Dreilich 01.10.2017

                                  That document has nothing to do with How to Reduce filesize.

                                  That document is about increasing filesize to add compatiblity.

                                  It seems that they put the wrong content in the article. Can you point me to the correct content?

                                • Mariya (DevExpress Support) 01.11.2017

                                  Hello Chaim,
                                  Please accept my apologies for this misunderstanding. Now your task is clear to me. If you want to export only an image Uri (not image bytes), I suggest you insert images in the document using the IncludePicture field. This field inserts the picture retrieved from the specified URI. The \d switch enables you to not store the image in a document file. So, if you create an IncludePicture field and specify the required Uri and \d switch in the field code and export the document to Rtf, only the image URI will persist in the exported document. Please try this approach and let me know if it meets your requirements.

                                • Chaim Dreilich 01.11.2017

                                  I tried this, but it crashes on InsertRtfTText. I also tried subdoc.fields.create. That doesn't crash, but it also doesnt work

                                  [C#]
                                  tc.PrintingRichEditControl.BeforeExport += delegate (object sender, DevExpress.XtraRichEdit.BeforeExportEventArgs e) { RichEditControl rc = sender as RichEditControl; RtfDocumentExporterOptions options = e.Options as RtfDocumentExporterOptions; DocumentImage[] images = new DocumentImage[rc.Document.Images.Count]; rc.Document.Images.CopyTo(images, 0); for (int x = images.Length-1; x >=0; x--) { var img = images[x]; DevExpress.Office.Utils.OfficeImage myImage = img.Image; string imageFileName = e.Options.TargetUri + ".Image" + (x).ToString() + ".jpg"; myImage.NativeImage.Save(imageFileName, ImageFormat.Jpeg); var subDoc = img.Range.BeginUpdateDocument(); //rc.Document.Replace(subDoc.Range, " "); string pictureRTF = "{INCLUDEPICTURE \"" + imageFileName + "\" \\d}"; subDoc.InsertRtfText(subDoc.Range.Start, pictureRTF); img.Range.EndUpdateDocument(subDoc); } options.Compatibility.DuplicateObjectAsMetafile = false;; };
                                • Mariya (DevExpress Support) 01.11.2017

                                  To accomplish this task, you need to delete the old image range using the Document.Delete method and insert a new field. With the current code, the incorrect image Uri is generated. Please try to replace your code as follows:

                                  [C#]
                                  private void richEditControl_BeforeExport(object sender, BeforeExportEventArgs e) { if(e.DocumentFormat == DocumentFormat.Rtf) { RichEditControl control = sender as RichEditControl; Document document = control.Document; int imageCount = document.Images.Count; for(int i=imageCount-1; i>=0; i--) { DevExpress.Office.Utils.OfficeImage myImage = document.Images[i].Image; string imageFileName = (e.Options.TargetUri + ".Image" + (i).ToString() + ".jpg").Replace("\\", @"\\"); myImage.NativeImage.Save(imageFileName, ImageFormat.Jpeg); DocumentPosition pos = document.Images[i].Range.Start; document.Delete(document.Images[i].Range); string code = "INCLUDEPICTURE \"" + imageFileName + "\" \\d"; document.Fields.Create(pos, code); } document.Fields.Update(); } }

                                  Note that images in RichEditControl also will be replaced with the IncludePicture fields. If you do not want to change a document in the RichEditControl, create an instance of RichEditDocumentServer and assign the RichEditControl.RtfText string to the RichEditDocumentServer.RtfText property. After that, replace all images as described above and save the document using the RichEditDocumentServer.SaveDocument method.

                                • Chaim Dreilich 01.11.2017

                                  The images seem to have lost their size/shape. Is there any way to maintain those?

                                • Mariya (DevExpress Support) 01.12.2017

                                  Yes, this behavior occurs because the original images are saved. To resolve this issue, you need to create new images using the actual image size from the document. I've updated the code to demonstrate how to obtain the document image size and create an external image with a similar size. Please review the following snippet:

                                  [C#]
                                  if(e.DocumentFormat == DocumentFormat.Rtf) { RichEditControl control = sender as RichEditControl; Document document = control.Document; int imageCount = document.Images.Count; for(int i=imageCount-1; i>=0; i--) { DevExpress.Office.Utils.OfficeImage myImage = document.Images[i].Image; RectangleF rect = new RectangleF(new PointF(), document.Images[i].Size); SizeF size = Units.DocumentsToPixels(rect, richEditControl.DpiX, richEditControl.DpiY).Size; string imageFileName = (e.Options.TargetUri + ".Image" + (i).ToString() + ".jpg").Replace("\\", @"\\"); Bitmap bitmap = new Bitmap(myImage.NativeImage, size.ToSize()); bitmap.Save(imageFileName, ImageFormat.Jpeg); DocumentPosition pos = document.Images[i].Range.Start; document.Delete(document.Images[i].Range); string code = "INCLUDEPICTURE \"" + imageFileName + "\" \\d"; document.Fields.Create(pos, code); } document.Fields.Update(); }
                                • Chaim Dreilich 01.12.2017

                                  That shrinks down the saved image so that it's the same size as what's shown in the note. This causes us to lose data (which we can't support).

                                  I need to add the full resolution image back into the note and have it rendered in the size that it was rendered in before.

                                • Mariya (DevExpress Support) 01.13.2017

                                  Hello,
                                  The RTF specification supposes storing an image in the hexadecimal (base64) format. So, there is only one way not to store an image in a document - add an image to a document using the INCLUDEPICTURE field. However, this field doesn't provide the capability to specify the size that should be applied to the image after retrieving. So, the image is always inserted with its original size. If you need to review the saved document in MS Word, I'm afraid the only way to keep image size is to update the external image size as described above.

                                  If you operate with these document in your application and don't need to review them in MS Word, you can insert the IncludePicture field using the DocVariable field. You can create a custom document property for each document image and store an image path in this property. After that, create a DocVariable field for each image and pass the corresponding custom property as a field name and actual image size as field arguments. In the CalculateDocumentVariable event, you'll be able to create a temporary RichEditDocumentServer instance, obtain an image Uri from the custom properties collection, and insert the IncludePicture field in the server document. After that, it will be necessary to update the IncludePicture field, obtain the image size from the DocVariable arguments, and assign this size to the image. Note that it's also necessary to lock the field after that by setting the Field.Locked property to true. This RichEditDocumentServer should be assigned to the e.Value argument of the CalculateDocumentVariable event so that its content will be inserted as a field result.
                                  After this modification, the image will not be stored in the exported Rtf document and will be also restored after loading the Rtf document to your application. However, images will not be displayed in MS Word in this case.
                                  Would you please clarify whether you need to display an exported document in MS Word? I look forward to your clarification.

                                • Chaim Dreilich 01.13.2017

                                  Can you give a code sample which shows how to use INCLUDEPICTURE with a DocVariable?

                                • Mariya (DevExpress Support) 01.16.2017

                                  Please refer to the attached project. If you add an image to the document, save this document to Rtf and reopen the saved document, the image size will be applied correctly in the CalculateDocumentVariable event. However, this image will not be shown in MS Word since DocVariable cannot be calculated in this case.