Skip to content

Commit e33ec81

Browse files
updated content extraction and manipulation examples
1 parent 7e86ccf commit e33ec81

File tree

3 files changed

+0
-51
lines changed
  • content/english/python-net/content-extraction-and-manipulation

3 files changed

+0
-51
lines changed

content/english/python-net/content-extraction-and-manipulation/document-content-extraction/_index.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ for paragraph in doc.get_child_nodes(doc.is_paragraph, True):
4444
text += paragraph.get_text()
4545
```
4646

47-
## Extracting Images
48-
49-
To extract images from the document:
50-
51-
```python
52-
for shape in doc.get_child_nodes(doc.is_shape, True):
53-
if shape.has_image:
54-
image = shape.image_data.to_bytes()
55-
with open("image.png", "wb") as f:
56-
f.write(image)
57-
```
58-
5947
## Managing Formatting
6048

6149
Preserving formatting during extraction:

content/english/python-net/content-extraction-and-manipulation/extract-modify-document-content/_index.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ for para in doc.get_child_nodes(asposewords.NodeType.PARAGRAPH, True):
4040
print(text)
4141
```
4242

43-
## Modifying Text
44-
45-
You can modify text by directly setting the text of runs or paragraphs:
46-
47-
```python
48-
for para in doc.get_child_nodes(asposewords.NodeType.PARAGRAPH, True):
49-
if "old_text" in para.get_text():
50-
para.get_runs().get(0).set_text("new_text")
51-
```
52-
5343
## Working with Formatting
5444

5545
Aspose.Words allows you to work with formatting styles:

content/english/python-net/content-extraction-and-manipulation/remove-content-documents/_index.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ for paragraph in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True):
5151
paragraph.get_range().replace(text_to_remove, replacement, False, False)
5252
```
5353

54-
## Replacing Text
55-
56-
Sometimes, you might want to replace certain text with new content. Here's an example of how to do it:
57-
58-
```python
59-
text_to_replace = "old text"
60-
new_text = "new text"
61-
62-
for paragraph in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True):
63-
if text_to_replace in paragraph.get_text():
64-
paragraph.get_range().replace(text_to_replace, new_text, False, False)
65-
```
66-
6754
## Removing Images
6855

6956
If you need to remove images from the document, you can use a similar approach. First, identify the images and then remove them:
@@ -94,22 +81,6 @@ for section in doc.sections:
9481
doc.remove_child(section)
9582
```
9683

97-
## Find and Replace with Regex
98-
99-
Regular expressions offer a powerful way to find and replace content:
100-
101-
```python
102-
import re
103-
104-
pattern = r"\b\d{4}\b" # Example: Replace four-digit numbers
105-
replacement = "****"
106-
107-
for paragraph in doc.get_child_nodes(aw.NodeType.PARAGRAPH, True):
108-
text = paragraph.get_text()
109-
new_text = re.sub(pattern, replacement, text)
110-
paragraph.get_range().text = new_text
111-
```
112-
11384
## Extracting Specific Content
11485

11586
Sometimes, you might need to extract specific content from a document:

0 commit comments

Comments
 (0)