Hello Team
We are using Aspose.Words to convert HTML to RTF documents for English/Spanish/Arabic content. We have a requirement to change the INCLUDEPICTURE definition generated by Aspose to a simple definition.
Definition generated by Aspose:
{\field{\*\fldinst
{\rtlch\af0\alang1\afs21\ltrch\fs21\lang1024\langnp1024\langfe1024\langfenp1024\loch\af0\dbch\af0\hich\f0\cf1 INCLUDEPICTURE }
{\rtlch\af0\alang1\afs21\ltrch\fs21\lang1024\langnp1024\langfe1024\langfenp1024\loch\af0\dbch\af0\hich\f0\cf1 }
{\rtlch\af0\alang1\afs21\ltrch\fs21\lang1024\langnp1024\langfe1024\langfenp1024\loch\af0\dbch\af0\hich\f0\cf1 images/norton-logo.jpg}
{\rtlch\af0\alang1\afs21\ltrch\fs21\lang1024\langnp1024\langfe1024\langfenp1024\loch\af0\dbch\af0\hich\f0\cf1 \\d}
}{\fldrslt}}
Required definition:
{\field
{\*\fldinst INCLUDEPICTURE "images\norton-logo.jpg" \\d}
{\fldrslt}}
Is there some API in Aspose that can achieve this. We have some old EPIC systems that consume these RTF files and cannot understand the INCLUDEPICTURE definition generated by Aspose.
Thanks
Parul
@parul.aggarwal Unfortunately, there is no way to output INCLUDEPICTURE field as it is required by your old consumer app. You can configure RTF output using RtfSaveOptions. In your case ExportCompactSize
and ExportImagesForOldReaders
(enabled by default) might be useful for you.
We already have ExportImagesForOldReaders set to true.
I was looking at setExportCompactSize(booleanvalue)
The documentation says, "Allows to make output RTF documents smaller in size, but if they contain RTL (right-to-left) text, it will not be displayed correctly. Default value is false
"
The main reason we are using Aspose if for RTL language(Arabic) documents. Therefore I don’t think we should use setExportCompactSize() flag.
Is there a safe way to replace the whole image text block with the simplified image definition we want??
@parul.aggarwal Unfortunately, There is no wat to output INCLUDEPICTURE
field in simplified mode in RTF as it is required by tour consumer app.
Probably, as a workaround, you can replace your INCLUDEPICTURE
fields with regular shapes. Aspose.Words imports INCLUDEPICTURE
fields as shapes with linked image data. You can reset link to make the image embedded. Probably in this case your consumer app will be able to handle the images:
Document doc = new Document(@"C:\Temp\in.docx");
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape s in shapes)
{
if (s.HasImage && s.ImageData.IsLink)
{
// NOTE: if SourceFullName is relative, you should get image data yourself.
// In this example it is supposed asolute path to an image is specified.
if (s.ImageData.IsLinkOnly)
s.ImageData.SetImage(s.ImageData.SourceFullName);
s.ImageData.SourceFullName = "";
}
}
doc.Save(@"C:\Temp\out.rtf");
Hello
We need linked images, therefore embedded image option does not work for us. Is there a java Regex pattern that we can use to replace the whole INCLUDEPICTURE definition with the simplified definition that we want.
Could this break the RTF rendering in anyway??
@parul.aggarwal You can try postprocessing the output RTF document and replace INCLUDEPICTURE definition with the simplified definition. But I cannot guaranty that changing internal representation of RTF document will not break it.