Thank you…
I tried upgrading to 17.9, but our issue is not resolved.
More details of our issue,below are the contents of our word template:
Order with with below comments:
<Order_Comment>
[Start:Data1]this is property with code <Sub_property_Code> with imageImage:O13a_08[End:Data1]
While parsing above template we process the content between [Start:Data1] and [End:Data1] as paragraph , below is the code snippet for this:
regex = Pattern.quote(LEFT_BRACKET + START_SUB + aMergeCode + RIGHT_BRACKET) + "(.*)" + Pattern.quote(LEFT_BRACKET + END_SUB + aMergeCode + RIGHT_BRACKET);
regexPattern = Pattern.compile(regex, Pattern.DOTALL);
replace(aTemplateDocument, regexPattern, new ReplaceParagraphEvaluator<DATATYPE>(aSubReport, subReportDS));
in ReplaceParagraphEvaluator we handle paragraph using below snippet:
public int replacing(final ReplacingArgs aArgs) throws PnAsposeException
{
Run run = (Run) aArgs.getMatchNode();
Font aFont = run.getFont();
Paragraph paragraph = run.getParentParagraph();
String mergeCode = null;
while (this.dataSource.hasNext())
{
this.dataSource.getNext(); // ignore result...
try
{
final List<IReportElement> reportElements = this.subReport.getReportElements();
Node node = paragraph.deepClone(true);
boolean hasAtleastOneElement = false;
for (IReportElement reportElement : reportElements)
{
if (reportElement != null)
{
final IElementProperties properties = reportElement.getProperties();
mergeCode = ((IMergeCode) properties).getMergeCode();
this.dataSource.getBaseValueFor(reportElement);
final Object displayValue = this.dataSource.getDisplayValueFor(reportElement);
final Class<?> valueType = this.dataSource.getDataTypeFor(reportElement);
String content = AbstractMailMergeFillManager.applyMask(reportElement, displayValue, valueType);
content = PnAsposeFacade.replaceCRandCRLFwithLineBreakChar(content);
hasAtleastOneElement = hasAtleastOneElement || ((content != null) && !content.isEmpty());
// Get the merge code from the report element and create a regex pattern of it
String regex = "\\<" + mergeCode + "\\>";
Pattern regexPattern = Pattern.compile(regex);
try
{
if (mergeCode.toUpperCase().startsWith(PnAsposeFacade.IMAGE_PREFIX))
{
FindReplaceOptions findReplaceOption = new FindReplaceOptions(FindReplaceDirection.FORWARD, new ReplaceTagsByImageEvaluator(content));
node.getRange().replace(regexPattern, "", findReplaceOption);
}
else
{
FindReplaceOptions findReplaceOption = new FindReplaceOptions(FindReplaceDirection.FORWARD, new ReplaceTagsByTextEvaluator(content));
node.getRange().replace(regexPattern, "", findReplaceOption);
}
}
catch (Exception ex)
{
throw new PnAsposeException(ex);
}
}
}
if (hasAtleastOneElement)
{
// PLA-2231, White rows in word doc.
// Do not add the paragraph which is empty.
paragraph.getParentNode().insertBefore(node, paragraph);
}
}
catch (Exception ex)
{
throw new PnAsposeException(ex);
}
}
try
{
paragraph.remove();
aArgs.setReplacement("");
}
catch (Exception ex)
{
throw new PnAsposeException(ex);
}
return ReplaceAction.REPLACE;
}
In paragraph we are trying to replace placeholder with image, as per documentation paragraph can only have Run and Shape. I guess we need to add image as Shape, I tried adding as shape, but for shape I need to specify width and Height, which we dont want.
Can you please provide an example to replace specific text in paragraph with image.