Free Support Forum - aspose.com

Find and replace List of String with tiff images

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

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please attach your input, output and expected documents here for testing? I will investigate the issue and provide you more information.

Best regards,

Hi Andrey,

Here is an archive containing the template document and the generated tiff images,

In the Template Document have string tag like “{OP_Summ_Day,rot=270L}”,the given tiff images need to replace the string.
All string tags need to replace by images.

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you please try calling ReplaceEvaluator with isForward set to “false”, and let me know how it goes on your side:

doc.getRange().replace(Pattern.compile("\\{OP_Summ_Day,rot=270L\\}"), new PlaceholderReplacer(), false);

Best regards,

It works.Thanks Andrey.

The issues you have found earlier (filed as 25843) have been fixed in this .NET update and in this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan