React-pdf: 带有注释层的响应式 PDF

创建于 2020-05-19  ·  4评论  ·  资料来源: wojtekmaj/react-pdf

  • [x] 我已阅读 README 中的文档
  • [x] 我已经检查了示例测试套件以查看现实生活中的基本实现
  • [x] 我已经检查过这个问题是否还没有被问过

我想要达到什么目标?

我希望 PDF 文档随着屏幕尺寸的缩小而缩小,这样在移动设备上一切都看起来不错,同时仍然保持可点击链接的注释层。

描述我尝试过的解决方案

我有与这个未解决的问题几乎相同的问题: https :

我没有看到任何适用于我的设置的东西,我是否缺少使注释层也响应的东西?

我目前的代码:
_pdf.css:_

.react-pdf__Document {
   display: flex !important;
   justify-content: center !important;
}

.react-pdf__Page__canvas, .react-pdf__Page__annotations {
   max-width: 100% !important;
   height: auto !important;
}

.pdf-container {
   background-color: lightgray;
   padding: 1% 0 10px 0;
}

<strong i="22">@media</strong> screen and (min-width: 901px) and (max-width: 1600px) {
   .pdf-container {
      padding: 5% 0 10px 0;
   }
  }

  <strong i="23">@media</strong> screen and (min-width: 701px) and (max-width: 900px) {
   .pdf-container {
      padding: 10% 0 10px 0;
   }
  }

  <strong i="24">@media</strong> screen and (max-width: 700px) {
   .pdf-container {
      padding: 20% 0 10px 0;
   }
  }

_文章组件:_

 <React.Fragment>
    <div className="pdf-container">
        <Document
            file={this.props.article.pdfUrl}
            onLoadSuccess={this.onDocumentLoadSuccess}
        >
            <Page pageNumber={pageNumber} />
        </Document>
        <Grid fluid className="s-padding-t">
            <Row center="xs">
                <Col xs={12} sm={4} className="s-padding-b">
                    <button
                        type="button"
                        className="s-btn"
                        disabled={pageNumber <= 1}
                        onClick={this.previousPage}
                        >
                        <i className="fa fa-chevron-left"></i> Previous
                    </button>
                </Col>
                <Col xs={12} sm={4} className="s-padding-b">
                    <span>Page {pageNumber || (numPages ? 1 : '--')} of {numPages || '--'}</span>
                </Col>
                <Col xs={12} sm={4} className="s-padding-b">
                    <button
                        type="button"
                        className="s-btn"
                        disabled={pageNumber >= numPages}
                        onClick={this.nextPage}
                        >
                        Next <i className="fa fa-chevron-right"></i>
                    </button>
                </Col>
            </Row>
        </Grid>
    </div>
</React.Fragment>

环境

  • 浏览器(如果适用)[例如 Chrome 57、Firefox 59]:Chrome 57
  • React-PDF 版本:^4.1.0
  • 反应版本:^16.13.1

最有用的评论

不要摆弄css,只需像这样设置页面宽度:

<div ref={documentWrapperRef}>
  <Document file="some_url">
    <Page
      width={documentWrapperRef.current?.getBoundingClientRect().width || undefined}
    />
  </Document>
</div>

所有4条评论

不要摆弄css,只需像这样设置页面宽度:

<div ref={documentWrapperRef}>
  <Document file="some_url">
    <Page
      width={documentWrapperRef.current?.getBoundingClientRect().width || undefined}
    />
  </Document>
</div>

@oldboyxx在 documentWrapperRef 上使用例如

当我使用此修复程序时,我遇到了一个新问题,每次更改页面时,周围的内容都会闪烁或移动!!! 任何的想法?

固定宽度时如何添加放大/缩小功能?

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

Solitaryo picture Solitaryo  ·  5评论

webguru103 picture webguru103  ·  3评论

joepio picture joepio  ·  3评论

theHasanas picture theHasanas  ·  5评论

lorenzos picture lorenzos  ·  5评论