Skip to content
Discussion options

You must be logged in to vote

This snippet also works ... at least with your example PDF:

>>> doc=fitz.open("cl600.demo.pdf")
>>> page=doc[0]
>>> page.clean_contents() # enforce standard painting syntax
>>> cont_xref = page.get_contents()[0] # we only have 1 of those now
>>> # read an modify the paint commands
>>> lines = doc.xref_stream(cont_xref).splitlines()
>>> # walk through lines and replace each width value
>>> for i in range(len(lines)):
	if lines[i].endswith(b" w"):  # command to set line width!
		lines[i] = b"0.02 w"

		
>>> # write back modified paint commands
>>> doc.update_stream(cont_xref, b"\n".join(lines))
>>> # now either make a pixmap of modified page ...
>>> pix=page.get_pixmap(dpi=300)
>>> pix.save("…

Replies: 6 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@cpwan
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@cpwan
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@cpwan
Comment options

Answer selected by cpwan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants