Closed scottrhoyt closed 9 years ago
I too am having issues with the orientation of the image made from a PDF using this library. @scottrhoyt , where did you put the modifications to correct this ?
@scottrhoyt thanks for raising this. Can you submit your fix as a pull request? I'd like to see your code ;-)
I submitted a pull request with the code changes I made for orientation/scale. Didn't test extensively, but it solved the issues for me.
Thanks. I shall test it. Can you send me some examples PDFs where the rotation and scaling is wrong?
I'm done with the project that I was working on when I came across this, so I don't have access to the original files. However, I believe I identified the problem as stemming from when PDFs are rotated using the \Rotate
tag in the PDF instead of being saved with new dimensions/orientation. This is most often seen not with a PDF vector image workflow, but instead with PDF documents where one or more pages in the document was rotated using this tag. We came across this when performing rotations in Acrobat. The transform function I used takes into account the \Rotate
tag. I created a sample image that I believe should replicate this behavior here:
https://dl.dropboxusercontent.com/u/18408411/QuestionMark.pdf
I needed to remember to clean the project in between tests because of the default caching to disk.
Issue fixed by #38
I tested it and it does indeed sort things out for the rotation, but I think the width and the height are the wrong way around. At least when I try it with my PDFs it seems to be the case. Same goes for the question mark. Its wider than the PDF suggests, and the only thing I can think of is that its got the dimensions the wrong way around.
Hi. I think that the last parameter of CGPDFPageGetDrawingTransform()
in renderIntoContext:
should be set to YES
.
Can you see if that works?
@skela thanks for this.
@mindbrix np, i love yer work, happy to try and help ;)
Anyway, I tried setting the last parameter to YES for renderInContext as you suggested, and yes that did fix that issue, but introduced another one.
Basically now the Image has large areas of unused space, meaning its probably still got the dimensions the wrong way around. My gut feeling is there is probably a better fix than that.
@skela what PDF are you using to test?
@mindbrix can I send it to you privately? Its a file provided by a client, don't want everybody to have it.
nigel@mindbrix.co.uk
@mindbrix thanks mate, will send it to you now.
@mindbrix ok, should be in your inbox any second now.
@skela I have created a branch at https://github.com/mindbrix/UIImage-PDF/tree/fixTransforms
This should fix your issues. Can you please test and let me know.
@mindbrix I've tried the changes in that branch, its still got quite a bit of an empty space caused by the dimensions being the wrong way around. I'll send you the comparative results in an email so you can see what I mean.
@skela interesting, as I now have code to handle that.
@mindbrix , for the record I'm using your [UIImage originalSizeImageWithPDFURL:(NSURL*)URL] ? category method.
just sent the email, should be with you any second ;)
@skela I've merged the changes. Thanks for your invaluable help ;-)
@mindbrix awesome, cheers!
Thank you for the great category! I am using it to display pdf document pages as images in my app.
Firstly, I encountered an issue where some images are being rendered with a different than intended rotation. I believe I tracked this down to the /Rotate tag in the pdf not being honored while rendering. I came across the function,
CGPDFPageGetDrawingTransform
, that I used to replace the scaling and translating transforms in PDFView.m. This seems to have solved the problem.Secondly, the resulting images that are being rendered are of low quality when displayed. They are of the intended size (taking into account screen scale), but perhaps the screen scale is not being taken into account somewhere? I noticed there was no reference to scale in the PDFView.m functions (including implied in the
size
parameter)... though you are passing in a context that has been scaled by the screen scale factor. Is this enough to ensure the PDFs are rendered at the proper size? Any other thoughts on what may be the issue?