When I try to rotate a single page (not the whole document) no pages are rotated.
In my example I try to rotate only the page 2 but both pages are shown without rotation.
import React, { Component } from 'react';
import { Document, Page } from 'react-pdf';
import samplePdf from './sample.pdf';
class PdfViewer extends Component {
render() {
return (
<Document file={samplePdf}>
<Page pageNumber={1} />
<Page pageNumber={2} rotate={90}/>
</Document>
);
}
}
export default PdfViewer;
Checking the code seems that I found where the source of the bug could be. Please see the explanation inline.
File: Document.jsx / Method: renderChildren
...
renderChildren() {
const { children, className, rotate } = this.props;
const { pdf } = this.state;
const { linkService, registerPage, unregisterPage } = this;
const childProps = {
linkService,
registerPage,
unregisterPage,
pdf,
rotate,
};
//
// BUG FIX
//
// At this point childProps.rotate is "undefined" due to it's assigned from <Document> props. When React.cloneElement is called bellow for each page, childProps.rotate is overwriting the rotate prop of the original <Page> so it's allways set to "undefined". My following piece of code seems to fix the issue:
if (typeof(childProps.rotate) === 'undefined'){
delete childProps.rotate;
}
...
Hey @herneli,
thank you for this report! Will fix this soon.
Hey @herneli,
happy to inform that v2.4.2 is out and it includes fix for this issue :) Let me know what you think.
Thank you very much. Good job!!!