Hi,
We are evaluating the Aspose words for Java in order to incorporate in our application.
we were purchased the product of Aspose words for Java,I came across few problems while evaluating.
I am trying to replace a list of string with image using ReplaceEvaluator . It can replace only 2 or 3 times with image,remaining string will not replacing properly and i am getting an exception
Ex;
The String value can be {OP_Summ_Day,rot=270L} ,available in template more than 10 times or more
The sample code is
public int replace(Object sender, ReplaceEvaluatorArgs e) throws Exception
{
String filedir = DocsConstants.* getimgloc * () + DocsConstants.* getimgfoldername * ();
String file = filedir + "/" + DocsConstants.* getimgfoldername * ();
DocumentBuilder builder = new DocumentBuilder((Document)e.getMatchNode().getDocument());
// Get match node to replace
Node currentNode = e.getMatchNode();
builder.moveTo(currentNode);
int iRot = 0;
String strRot = null;
String strNext = null;
builder.moveTo(currentNode);
builder.getParagraphFormat().setLeftIndent(0);
builder.getPageSetup().setLeftMargin(ConvertUtil.* inchToPoint * (0.75));
builder.getPageSetup().setRightMargin(ConvertUtil.* inchToPoint * (0.75));
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
// read the rotation parameter
strNext = e.getMatch().group(1);
if (strNext != null)
{
int len = strNext.length();
strRot = strNext.substring(0, len - 1);
iRot = Integer.* parseInt * (strRot);
}
// Find number of images in the "filedir" folder
int noofimgs = new File(filedir).listFiles().length;
String filename3 = null;
builder.insertBreak(BreakType.LINE_BREAK);
for (int i = 0; i < noofimgs; i++)
{
// save page caputres to file.
filename3 = file + i + ".tiff";
File ft = new File(filename3);
if (!ft.exists())
{
return 0;
}
BufferedImage rasterImage = javax.imageio.ImageIO.* read * (ft);
Shape shape = builder.insertImage(rasterImage, 500, 550);
// Rotate the image
shape.setRotation(iRot);
shape.setRelativeHorizontalPosition(-50);
shape.setVerticalAlignment(-50);
builder.clearRunAttrs();
builder.writeln();
filename3 = null;
}
e.setReplacement("");
return ReplaceAction.REPLACE;
}
Thanks
Noorullah