def extract_content_using_field(self, doc):
        """
            Shows how to extract content between a specific field and paragraph in the document using the ExtractContent method.
        """

        # Use a document builder to retrieve the field start of a merge field.
        builder = DocumentBuilder(doc)

        # Pass the first boolean parameter to get the DocumentBuilder to move to the FieldStart of the field.
        # We could also get FieldStarts of a field using GetChildNode method as in the other examples.
        builder.moveToMergeField("Fullname", False, False)

        # The builder cursor should be positioned at the start of the field.
        startField = builder.getCurrentNode()
        endPara = doc.getFirstSection().getChild(NodeType.PARAGRAPH, 5, True)

        # Extract the content between these nodes in the document. Don't include these markers in the extraction.
        extractedNodes = self.extract_contents(startField, endPara, False)

        # Insert the content into a new separate document and save it to disk.
        dstDoc = self.generate_document(doc, extractedNodes)
        
        dstDoc.save(self.dataDir + "TestFile.Fields Out.pdf")
Exemplo n.º 2
0
    def __init__(self):
        dataDir = Settings.dataDir + 'programming_documents/'

        doc = Document(dataDir + "document.doc")

        builder = DocumentBuilder(doc)

        #Shows how to access the current node in a document builder.
        curNode = builder.getCurrentNode()
        curParagraph = builder.getCurrentParagraph()

        # Shows how to move a cursor position to a specified node.
        builder.moveTo(doc.getFirstSection().getBody().getLastParagraph())

        # Shows how to move a cursor position to the beginning or end of a document.
        builder.moveToDocumentEnd()
        builder.writeln("This is the end of the document.")

        builder.moveToDocumentStart()
        builder.writeln("This is the beginning of the document.")

        doc.save(dataDir + "MovingCursor.doc")

        print "Done."