Change Text Color

I want to change the background color of all the texts in the PDF, is there a way to do this?(in python)

@sedaozdmiir To change text font properties in Aspose.Words you can use Font class and it’s properties.

But you have mentioned that you need to achieve this in PDF document. Please note only .NET and Python versions of Aspose.Words supports loading PDF documents and upon loading fixed page PDF document structure is converted to flow document model, that might lead to document layout inaccuracies.

Could you please specify, which of Aspose products do you use to process PDF documents - Aspose.Words or Aspose.PDF?

I am using the aspose.words library. When I upload a pdf I want to change the background of all its posts. But I don’t want to change the background of the Page, let’s draw attention to this.

@sedaozdmiir You can loop through all Run nodes in your document and change their background or highlight color. Please see the following code for more information:

Document doc = new Document(@"C:\Temp\in.docx");

doc.GetChildNodes(NodeType.Run, true).Cast<Run>().ToList()
    .ForEach(r => { r.Font.HighlightColor = Color.Yellow; });

doc.Save(@"C:\Temp\out.docx");

thank you for everthing but one more questions to you.
Why am I getting KeyError: Aspose.Words error?

@sedaozdmiir Could you please elaborate how to reproduce such error? Please provide you code or a simple application that will demonstrate the problem. We will check the issue and provide you more information.

Traceback (most recent call last):

  File "c:\Users\PC_3879\Desktop\denme\deneme.py", line 2, in <module>
    import aspose.words as aw
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 640, in _load_backward_compatible
KeyError: 'aspose.words'

code:

PDF1.save("f1.docx", aw.SaveFormat.DOCX)

PDF2.save("f2.docx", aw.SaveFormat.DOCX)

# Load converted Word documents

DOC1 = aw.Document("f1.docx")

DOC2 = aw.Document("f2.docx")
DOC1.compare(PDF2, "user", date.today())
DOC1.save("compared.pdf")

@sedaozdmiir It looks like aspose.words module is not installed. Please make sure it is properly installed in your environment:
https://docs.aspose.com/words/python-net/installation/

seems to be installed now

Requirement already satisfied: aspose-words in c:\users\pc_3879\appdata\local\programs\python\python310\lib\site-packages (23.3.0)

@sedaozdmiir Unfortunately, I cannot reproduce the problem on my side. Probably, you have the same problem as here or similar:
https://stackoverflow.com/questions/53855836/keyerror-frozen-importlib-bootstrap-error-on-second-library-import-in-spyder

this is in the code you wrote, in the .Cast.ToList() part
+‘aspose.words.Node’ object has no attribute ‘ToList’
+‘aspose.words.Node’ object has no attribute ‘Cast’
i am getting errors

@sedaozdmiir The provided code is in C#, since Aspose.Words for .NET is the main version and initially you did not specify which language you use. Here is code in Python:

import aspose.words as aw
import aspose.pydrawing as pydraw

runs = doc.get_child_nodes(aw.NodeType.RUN, True)
for node in runs:
    r = node.as_run()
    r.font.highlight_color = pydraw.Color.yellow 

doc.save("C:\\Temp\\out.docx");

how can i delete revisions first and then add them again(in python)

how to change the text background color of revisions ?

@sedaozdmiir You cannot delete or insert revisions, you can either accept revisions using RevisionCollection.accept_all() method or reject revisions using RevisionCollection.reject_all() method. Also, you can accept/reject individual revisions in the document using the appropriate methods of Revision class.
There is no way to add revision manually, however, you can track changes made the the document programmatically:

doc = aw.Document();
builder = aw.DocumentBuilder(doc)

# Insert some content.
builder.write("Hello, ")

# Start tracking revisions.
doc.start_track_revisions("Author Name")

builder.write("World!!!")

# Start tracking revisions.
doc.stop_track_revisions()

doc.save("C:\\Temp\\out.docx");

Please see our documentation to learn more about working with revisions.

@sedaozdmiir

If you render your output document (convert document to fixed page formats like PDF, XPS, Image etc), you can control appearance of revisions using properties of RevisionOptions class.
In case of saving the document to MS Word formats, there is no way to control appearance of revisions, since these setting are set per application and are not stored in the document.