-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading and writing PDF file damages it #180
Comments
prolly something to do with PIL, looks like the image is loaded BGR instead of RGB |
Hi! I see that your Image is flipped from the usual RGB display pallet to the CMYK display pallet, to change this. to solve this, I know of 1 way that will require you to install OpenCV, a library known to manipulate image data. This is how I turn a BGR image to a RGB image: from borb.toolkit import ImageExtraction
from pprint import pprint
from borb.pdf import PDF
import numpy as np
import cv2
imageExtraction = ImageExtraction()
with open("output.pdf","rb") as file:
document = PDF.loads(file)
assert document is not None
pprint(document.get_page(0)["Resources"])
for key, value in document.get_page(0)["Resources"]["XObject"].items():
image = np.array(value)
open_cv_image = cv2.cvtColor(open_cv_image,cv2.COLOR_BGR2RGB)
OpenCV_imageSize = open_cv_image.shape
print(OpenCV_imageSize)
open_cv_image = cv2.resize(src=open_cv_image, dsize=(300,200))
cv2.imshow("key",open_cv_image)
cv2.waitKey(0)
cv2.destroyAllWindows() I will try to reproduce this issue and come back to you with a working solution in a few days time |
I have did some investigation and Found that the reason why the file was "damaged" was because Borb read the image as an RGB instead of a CMYK image, this can only be fixed by reproducing the PDF with all images set to RGB |
test.pdf:
test2.pdf:
test.pdf
The text was updated successfully, but these errors were encountered: