Skip to content

How to render Image #3154

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

Open
vannamphuc opened this issue Apr 21, 2025 · 0 comments
Open

How to render Image #3154

vannamphuc opened this issue Apr 21, 2025 · 0 comments

Comments

@vannamphuc
Copy link

Why it's just render a 'red' blank block not rendering a Image at this code

import { Document, Page, Text, View, StyleSheet, Image as PDFImg, Font } from '@react-pdf/renderer'

const styles = StyleSheet.create({
image: {
width: 50,
height: 50,
objectFit: 'contain',
backgroundColor: 'red',
}
})
<View style={styles.table}>
        <View style={[styles.tableRow, styles.tableHeader]}>
          <Text style={styles.tableCell}>Image</Text>
          <Text style={styles.tableCell}>STT</Text>
          <Text style={styles.tableCell}>Sản phẩm</Text>
          <Text style={styles.tableCell}>Đơn giá</Text>
          <Text style={styles.tableCell}>SL</Text>
          <Text style={styles.tableCell}>Thành tiền</Text>
        </View>
        {order.orderItems?.map((item, index) => (
          <View key={index} style={styles.tableRow}>
          <PDFImg src='link_to_any_image_in_google' style={styles.image} />
            <Text style={styles.tableCell}>{index + 1}</Text>
            <Text style={styles.tableCell}>{item.productName}</Text>
            <Text style={styles.tableCell}>{formatPriceVnd(item.price)}</Text>
            <Text style={styles.tableCell}>{item.quantity}</Text>
            <Text style={styles.tableCell}>{formatPriceVnd(item.price * item.quantity)}</Text>
          </View>
        ))}
      </View>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant