Multiple shapes into single image

Hi,

Could you please let me know , how to convert set of shapes with text and floating elements into single image.

I have attached a document containing the data. We would like to save it as single image in the document.

We dont want to save the entire page as image. Just the section with shapes as one iamge.

Thank you
AHelloWorld

Hi there,

Thanks for your inquiry. Please use following code example to achieve your requirements. Hope this helps you.

Document document = new Document(MyDir + "Test4.docx");
GroupShape shape = (GroupShape)document.getChild(NodeType.GROUP_SHAPE, 0, true);
ShapeRenderer r = shape.getShapeRenderer();
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
options.getMetafileRenderingOptions().setRenderingMode(MetafileRenderingMode.VECTOR);
r.save(MyDir + "Out.png", options);

Thank you for an update.

New image doesn’t contain the floating shapes.(text box filled with green color)

I have attached an image file, taken as screen shot. Is it possible to achieve the output image similar to the document.
Could you please suggest?

Hi,

Could you please help in resolving the issue.

Thanks

Hi there,

Thanks for your inquiry. We have tested the scenario and have noticed that the text boxes filled with green color do not render in output image. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-14929. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Could you please provide an alternate solution,until the existing issue is resolved.

Is there a way to club all those shape into one shape and then create image for the same.
Any work around available would help us to proceed further.

Thank you.

Hi there,

Thanks for your inquiry. It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-14929) as ‘Not a Bug’.

The text boxes filled with green color are not part of GroupShape. Please add these shapes into GroupShape and use the same code to get the desired output. Please let us know if you have any more queries.

Hi,

I tried adding those shapes to GroupShape, though floating shapes are added to GroupShape, those shapes are not seen when saved as an image.

Also, I tried creating a simple GroupShape and save it as an image, but the saved document doesn’t contain the newly created GroupShape.

I have attached files for above two scenarios.

Could you please guide.

Hi there,

Thanks for your inquiry. Please use following code example to achieve your requirements. Hope this helps you.

The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages. Please use these APIs as shown below to get the height of table.

Following code example does the following:

  1. Import the table node that contains the group shape into empty document.
  2. Get the height of table using Aspose.Words.Layout API.
  3. Set the page’s width and height of new document according to table’s size.
  4. Export the document to image.
Document doc = new Document(MyDir + "Test4.docx");
Document dstDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(dstDoc);

Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);

NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
Node newNode = importer.importNode(table, true);
dstDoc.getFirstSection().getBody().appendChild(newNode);
dstDoc.getFirstSection().getBody().getFirstParagraph().remove();

builder.moveToDocumentStart();
BookmarkStart bStart = builder.startBookmark("Start_BM");
builder.endBookmark("Start_BM");

builder.moveToDocumentEnd();
BookmarkStart bStart2 = builder.startBookmark("End_BM");
builder.endBookmark("End_BM");

LayoutCollector collector = new LayoutCollector(dstDoc);
LayoutEnumerator enumerator = new LayoutEnumerator(dstDoc);

Object renderObject = collector.getEntity(bStart);
enumerator.setCurrent(renderObject);
double startP = enumerator.getRectangle().getY();

renderObject = collector.getEntity(bStart2);
enumerator.setCurrent(renderObject);
double endP = enumerator.getRectangle().getY();

dstDoc.getFirstSection().getPageSetup().setPageHeight(endP - startP);
dstDoc.getFirstSection().getPageSetup().setPageWidth(table.getPreferredWidth().getValue());
dstDoc.getFirstSection().getPageSetup().setLeftMargin(0.0);
dstDoc.getFirstSection().getPageSetup().setRightMargin(0.0);
dstDoc.getFirstSection().getPageSetup().setTopMargin(0.0);
dstDoc.getFirstSection().getPageSetup().setBottomMargin(0.0);

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
options.setPageCount(1);
options.setPageIndex(0);
dstDoc.updatePageLayout();
dstDoc.save(MyDir + "17.2.0.png", options);