使用 React-pdf/renderer 和 Image 旋转我的图像

发布于 2025-01-10 11:20:28 字数 1700 浏览 0 评论 0原文

我使用react-pdf/renderer 创建了一个PDF 文件。一切都很好,但我的形象是侧面的。使用 img 标签时,它会正确显示。我尝试过搜索,发现像 onLoadSuccess 检查旋转属性这样的想法?但我不知道如何使用这个库来做到这一点。

这是我的代码:

<Document>
   <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <View
          style={{
            width: "100%",
            alignContent: "center",
            justifyContent: "center",
            padding: "10pt",
            backgroundColor: "gray",
            color: "white",
            fontSize: "20pt",
            fontWeight: "bold",
            margin: 0,
          }}
        >
          <Text style={{textAlign: "center", marginBottom: "5pt"}}>
            Profile stuff here
          </Text>
          <Text style={{fontSize: "14pt", textAlign: "center"}}>
            More profile stuff
          </Text>
        </View>
        <View
          style={{
            margin: "40pt",
            alignSelf: "center",
            justifyContent: "center",
            display: "flex",
            flexDirection: "row",
            flexWrap: "wrap",
          }}
        >
          {report?.image && (
            <Image
              style={{
                alignSelf: "center",
                margin: "5pt",
                maxWidth: "400pt",
                maxHeight: "400pt",
                width: "auto",
                height: "auto",
                border: 1,
              }}
              src={report.image}
            />
          )}
        </View>
    </View>
  </Page>
</Document>

该图像来自 Firebase,当我在那里查看时可以正确显示。我认为这与以横向或纵向模式拍摄的图像有关,但后来我迷失了。

感谢您的任何建议。

I'm created a PDF file using react-pdf/renderer. Everything is working great, but my image is sideways. When using an img tag it is shown correctly. I've tried searching and I find thoughts like onLoadSuccess check the rotate property? But I don't know how to do that using this library.

Here is my code:

<Document>
   <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <View
          style={{
            width: "100%",
            alignContent: "center",
            justifyContent: "center",
            padding: "10pt",
            backgroundColor: "gray",
            color: "white",
            fontSize: "20pt",
            fontWeight: "bold",
            margin: 0,
          }}
        >
          <Text style={{textAlign: "center", marginBottom: "5pt"}}>
            Profile stuff here
          </Text>
          <Text style={{fontSize: "14pt", textAlign: "center"}}>
            More profile stuff
          </Text>
        </View>
        <View
          style={{
            margin: "40pt",
            alignSelf: "center",
            justifyContent: "center",
            display: "flex",
            flexDirection: "row",
            flexWrap: "wrap",
          }}
        >
          {report?.image && (
            <Image
              style={{
                alignSelf: "center",
                margin: "5pt",
                maxWidth: "400pt",
                maxHeight: "400pt",
                width: "auto",
                height: "auto",
                border: 1,
              }}
              src={report.image}
            />
          )}
        </View>
    </View>
  </Page>
</Document>

The image comes from Firebase and is correctly displayed when I look at it there. I think it has something to do with the image taken in landscape or portrait mode, but then I am lost.

Thank you for any advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文