Page 1 of 1

Remove Sdt control block issue

PostPosted: Thu Jun 25, 2015 11:36 am
by todd
Jason,

I'm trying to remove the sdt tag from a document section so the user can copy/paste from word into another document without copying the control block section. To avoid a control block in another control block.
Yes, if you carefully position the copy area you can only get the text or just remove the control block from word. But some users are not that savvy.
I have tried the following;

RemovalHandler rh = new RemovalHandler();
rh.removeSDTs(reportMLPackage, Quantifier.ALL);
reportMLPackage.save(new File(DIR_OUT + "_stripped.docx"));
System.out.println("Saved: " + DIR_OUT + "_stripped.docx");

and

Docx4J.save(wmlPackage, outFile, Docx4J.FLAG_BIND_REMOVE_SDT);

But cannot seen to remove the sdt tag.
I just want the sdt section removed and keep the P,Table.... objects within the sdt block.
I tried just extracting each object from the sdt and adding to a list<Object>
Then
WordprocessingMLPackage output = WordprocessingMLPackage.createPackage();
output.getMainDocumentPart().getContent().addAll(objects);

To create the file but images are not found.

Any ideas, help would be appreciated.

Thanks
Todd

Re: Remove Sdt control block issue

PostPosted: Mon Jul 06, 2015 7:28 pm
by jason
Hi Todd

RemovalHandler only strips OpenDoPE content controls (that is, ones with a tag containing 'od:'), and Docx4J.FLAG_BIND_REMOVE_SDT is just a way of invoking that.

You could do something like you describe to replace the controls with their content; that would be quicker than using XSLT (which RemovalHandler does).

There should not be any problem with image rels, provided you don't move the images between parts (eg main document part to or from a header etc)

cheers .. Jason