Hello, I am trying to make my code for coloring and merging pdfs. I need it for some project. I reused part of the code from Board2Pdf plugin but only possible color is white or black. If I change color, it show only white page. PDFs are generated from KiCAD 7.0.6. I am using pymupdf library and with plugin it works but my code does not. @albin you will be probably most helpful. There is my code.
def colorize_pdf_fitz(inputFile, color):
try:
with fitz.open(inputFile) as doc:
xref_number = doc[0].get_contents()
stream_bytes = doc.xref_stream(xref_number[0])
new_color_RG = bytes(str('125 125 0 ') + 'RG', 'ascii')
new_color_rg = bytes(str('125 125 0 ') + 'rg', 'ascii')
stream_bytes = re.sub(b'0.0.0.RG', new_color_RG, stream_bytes)
stream_bytes = re.sub(b'0.0.0.rg', new_color_rg, stream_bytes)
print(stream_bytes)
doc.update_stream(xref_number[0], stream_bytes)
doc.save("out.pdf", clean=True)
except:
print("An exception occurred")
return True
![screen|690x453](upload://wNOZ1O7Lmh0Sq0MMM9UOs2nstmK.png)