Hi there,
I am using the examples found on your forums to insert a document (nodetype = paragraph) into a main document. I do this via insertAfter. But everytime insertDocument is executed then the insertion starts with a blank line. I tried to delete these blank lines, but unfortunate until know all our attempts did not succeed.
For example: We have tried to setup parentPara.getParagraphFormat().setSpaceBefore(0); This did not work.
part of our code
public void fieldMerging(FieldMergingArgs e) throws Exception {
if (this.documentBuilder == null)
this.documentBuilder = new DocumentBuilder(e.getDocument());
if (this.macroButton.getSoort().equals(“B”)) {
if (log.isDebugEnabled()) {
log.debug("Behandelen Bouwsteen: " + e.getFieldValue());
}
Document subDoc = new Document((String) e.getFieldValue());
execute(this.opdrachtbestandWrapper, subDoc, null);
insertDocument(getParagraaf(e.getDocumentFieldName()), subDoc);
// Met log.debug(subDoc.toString(SaveFormat.TEXT)); kan de inhoud van een document eenvoudig zichtbaar
// gemaakt worden.
}
if (this.macroButton.getSoort().equals(“P”)) {
String bodyBlok = (String) e.getFieldValue();
if (log.isDebugEnabled()) {
log.debug("Behandelen Paragraaf: " + e.getFieldValue());
}
Node insertBodyblok = getParagraaf(e.getDocumentFieldName());
Document joinDoc = new Document();
for (String blok = this.opdrachtbestandWrapper.getFirstBlok(bodyBlok); blok != null; blok =
this.opdrachtbestandWrapper.getNextBlok(bodyBlok)) {
Document subDoc = createDocument(blok);
execute(this.opdrachtbestandWrapper, subDoc, this.opdrachtbestandWrapper.getBodyBlok());
joinDoc.appendDocument(subDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
}
insertDocument(insertBodyblok, joinDoc);
if (e.getFieldValue() == null) {
this.documentBuilder.moveToMergeField(e.getFieldName());
// Nothing to do for this field.
}
}
}
protected void insertDocument(Node aNode, Document srcDoc) throws Exception {
Node insertAfterNode = aNode;
if ((insertAfterNode.getNodeType() != NodeType.PARAGRAPH) && (insertAfterNode.getNodeType() != NodeType.TABLE))
throw new IllegalArgumentException(“The destination node should be either a paragraph or table.”);
// We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.getParentNode();
// This object will be translating styles and lists during the import.
NodeImporter importer =
new NodeImporter(srcDoc, insertAfterNode.getDocument(), ImportFormatMode.KEEP_SOURCE_FORMATTING);
// Loop through all secintions in the source document.
for (Section srcSection : srcDoc.getSections()) {
// Loop through all block level nodes (paragraphs and tables) in the
// body of the section.
for (Node srcNode : (Iterable<Node>) srcSection.getBody()) {
// Let's skip the node if it is a last empty paragraph in a
// section.
if (srcNode.getNodeType() == (NodeType.PARAGRAPH)) {
Paragraph paragraph = (Paragraph) srcNode;
if (paragraph.isEndOfSection() && !paragraph.hasChildNodes())
continue;
}
// This creates a clone of the node, suitable for insertion into
// the destination document.
Node newNode = importer.importNode(srcNode, true);
// Insert new node after the reference node.
dstStory.insertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
private Paragraph getParagraaf(String name) {
NodeCollection starts = this.sjabloon.getChildNodes(NodeType.FIELD_START, true);
for (FieldStart start : (Iterable<FieldStart>) starts) {
if (start.getFieldType() == FieldType.FIELD_MACRO_BUTTON) {
Paragraph parentPara = (Paragraph) start.getAncestor(NodeType.PARAGRAPH);
parentPara.getParagraphFormat().setSpaceBefore(0);
String testP = parentPara.getText();
if (testP.indexOf(name) > 0) {
try {
start.getField().remove();
} catch (Exception e) {
// ARGUMENTATIE: onderliggend wordt door Aspose een @link(Exception} gegooid. Hier kunnen
// we niets aan veranderen, maar we willen in dit geval wel verder gaan.
log.warn("Fout bij ophalen paragraaf", e);
}
return parentPara;
}
}
}
return null;
}
Hopefully you can help me with this problem
kind regards
Marcel van Olffen