I've come across a challenge in my React PDF project where I am struggling to display the bottom and right margins, as well as the borders, in my reactPDF

I am currently working on creating a PDF using the @react-pdf/renderer library within my React project. Everything seems to be functioning correctly except for an issue with the right and bottom margins not appearing in the PDF. Strangely, the top and left margins are visible without any problems.

Below is the code snippet I am using:

import React from 'react'
import Title from './components/Title'
import { PDFViewer, Page, Document, View } from '@react-pdf/renderer'
import Table from './components/Table'
import Footer from './components/Footer'

const App = () => {
  const tableData = [

    { sno: 2, hsn: 67890, mfg: 'XYZ Corp.' },
    { sno: 2, hsn: 67890, mfg: 'XYZ Corp.' },
  ]
  return (
    <PDFViewer style={{ width: '100%', height: '100vh' }}>
      <Document>
        <Page
          orientation="landscape"
          size="A4"
          style={{
            border: 1,
            margin: 20,
          }}
        >
          <View style={{ border: '1px solid black' }}>
            <Title />
            <Table tableData={tableData} />
            <Footer />
          </View>
        </Page>
      </Document>
    </PDFViewer>
  )
}

export default App

https://i.sstatic.net/Dejea.png

Answer №1

I have implemented margins on all sides in the following manner:

Note: Unfortunately, I cannot share a link because it is private. Instead, I have included a snippet of the code that needs to be modified below.

Step1: Adding styles:

const styles = StyleSheet.create({
  page: {
    flexDirection: "row",
    backgroundColor: "#E4E4E4",
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1,
  },
});

Step2: Applying styles in the View

<Page orientation="landscape" size="A4" style={styles.page}>
  <View style={styles.section}>
    <Title />
    <Table tableData={tableData} />
    <Footer />
  </View>
</Page>;

Please feel free to reach out if you have any further inquiries.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular HTML layout designed for seamless interaction

<div class ="row"> <div class ="col-md-6"> Xyz </div> <div class ="col-md-6"> Abc </div> </div> Using the code above, I can easily create a layout with two columns. Th ...

I seem to be having an issue here - my style sheet just won't load

I am having an issue with my external style sheet named style.css. style.css #topbar { background-color: red; width: 1000px; height: 40px; } body{ background-color: green; } I have tried calling this style.css from the root folder, but it's not ...

Utilize Shopify's API to seamlessly collect email inquiries directly through a custom contact page

Currently, I am facing a challenge in making my contact us page functional within my Shopify app. The link provides guidance on creating a contact page in Shopify, but as I am developing a Shopify app using nextjs, I am struggling to integrate my own co ...

Ways to design each element in React

I'm currently working on a React code that involves CSS for Scrolling functionality. When I try to use props.children.map, I encounter an error saying "TypeError: props.children.map is not a function". Since I am in the process of learning React.js, t ...

What are some ways to optimize the efficiency of handling a sizable JSON object in React Native?

I am currently developing an application using React Native and have encountered significant slowdowns during transitions when loading more data. I am exploring alternative app structuring methods to prevent these performance issues, especially as the JSON ...

I'm using Bootstrap (version 5.3) and when I tried to replicate the features from the examples, I noticed that the background isn't being copied over

I encountered an issue today while working on a website using bootstrap. I was copying features from examples in the bootstrap section, but when I pasted the code into my coding platform, the background appeared transparent and did not display as expected. ...

Tips for resolving the issue of windows resizing due to off-screen elementsplacement:

During the development of a project, I wanted to incorporate an effect into my webpage. To achieve this, I positioned elements off the screen. However, upon running the code, the window resized with scrollbars, causing inconvenience for mobile users Below ...

TS2339 Error: The object 'Navigator' does not contain the property 'clipboard'

In the project I'm working on, there is an error that comes up when trying to copy custom data to the clipboard. It's something I can easily put together. Error TS2339: Property 'clipboard' does not exist on type 'Navigator' ...

When routes are imported, the router does not pay attention to this.props.children, unlike when they are

Welcome My goal is to develop a ReactJS application that is Isomorphic using React-Router and ExpressJS. This project involves creating modules for both the client and server to access specific scripts, such as routes. To achieve modularity, I am utilizin ...

Animate CSS Grid to dynamically fill the viewport on top of current grid elements

Please note that I am specifically seeking vanilla JS solutions, as jQuery is not compatible with this project I have a grid structure that is somewhat complex: body { margin: 0; height: 100vh; text-align: center; } .grid-container { ...

Selecting default options in Material-UI Autocomplete component in real-time - a step-by-step guide!

Is there a way to automatically pre-select the default option in an Autocomplete component once the list of options has finished loading via an AJAX call? Imagine this scenario: when a user visits the page, a list of options is being fetched from the serve ...

The makeStyles feature is currently not functioning properly in the latest version of Next.js with Material UI v5

Currently, I am utilizing nextjs along with material ui in my project "@mui/material": "^5.0.1", "@mui/styles": "^5.0.1", Below is the code snippet of my component structure import { AppBar, Toolbar, Typography, Box ...

Is it necessary to include the Roboto font when using MUI?

After reviewing the Material UI documentation, it appears that users are responsible for loading the Roboto font: Material UI is designed to use the Roboto font by default. You may add it to your project with npm or yarn via Fontsource, or with the Googl ...

Unable to find and load the specified css-font formats (svg, eot, woff, woff2, and ttf) using webpack

Looking to incorporate a unique font into my project: @font-face { font-family: 'bikeshop'; src: url('/src/styles/bikeFont/font/bikeshop.eot?37006833'); src: url('/src/styles/bikeFont/font/bikeshop.eot?37006833#iefix') ...

Adjust the height of the Twitter Widget to be proportionate to the height of its parent div dynamically

I have integrated the Twitter widget into my library management system, but I am facing an issue with its fixed height. Is there a way to make the height dynamic through CSS? Any suggestions on how this can be achieved will be greatly appreciated. Below ...

Foundation: the importance of source order (without using flex grid)

I have a 3-column grid, with content and a sidebar. On small and medium devices each takes up 12 columns. Take a look at the example here: cdpn.io/anon/pen/bqENqG. I am looking to have the sidebar appear after the articles on small and medium devices like ...

Unable to alter the default settings of MUI checkboxes or radio buttons

I have been struggling to customize the appearance of MUI checkboxes and radio buttons in my theme, but so far I have not had any success. components: { ... MuiCheckbox: { styleOverrides: { root: { color: pallette.lightBlack, ...

The module script failed to load due to an unexpected response from the server, which was MIME type of text/jsx instead of a javascript module script

I have recently set up an express server and created an API, as well as installed React using Vite for my frontend. However, when I attempt to connect or load my main HTML file to the server, an error is displayed in the console. This is all new to me as I ...

Looking for a compatible loader to manage this specific file format

I'm in the process of implementing code splitting with server-side rendering using react-loadable. However, I encountered an error when trying to use import statement. I've looked at other posts for solutions but nothing seems to work for me. ...

Is there a solution to the error message "RangeError [ERR_SOCKET_BAD_PORT]: Port must be >= 0 and < 65536. NaN received." that I can implement?

After updating my system to Windows 11, I encountered an error when starting my react.js app using "npm start" and nodemon in the terminal. The error message displayed was "RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received N ...