Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react-pdf responsive

import React from 'react';
import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer';

const styles = StyleSheet.create({
  section: {
    width: 200,
    '@media max-width: 400': {
      width: 300,
    },
    '@media orientation: landscape': {
      width: 400,
    },
  }
});

const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
    </Page>
  </Document>
);
Comment

react-pdf responsive

ResumePage.js

import React, { Component } from 'react';

import { Document, Page, pdfjs } from 'react-pdf/dist/entry.webpack';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

import './ResumePage.css';
import 'react-pdf/dist/Page/AnnotationLayer.css';

import pdfFile from '../../public/SandroResume.pdf';

class ResumePage extends Component {
    state = {
        file: pdfFile,
        numPages: null,
        pageNumber: 1,
    }

    onDocumentLoadSuccess = ({ numPages }) => {
        this.setState({ numPages });
    }

    render() {
        const { file, pageNumber } = this.state;
        return (
            <div id="ResumeContainer">
                <Document className={"PDFDocument"} file={file} onLoadSuccess={this.onDocumentLoadSuccess}>
                    <Page className={"PDFPage PDFPageOne"} pageNumber={pageNumber} renderTextLayer={false} renderInteractiveForms={false} />
                    <Page className={"PDFPage"} pageNumber={pageNumber + 1} renderTextLayer={false} renderInteractiveForms={false} />
                </Document>
            </div>
        );
    }
}

export default ResumePage;

ResumePage.css

#ResumeContainer {
    margin:auto;
    width: 65%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.PDFDocument {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.PDFPage {
    box-shadow: 0 0 8px rgba(0, 0, 0, .5);
}

.PDFPageOne {
    margin-bottom: 25px;
}

.PDFPage > canvas {
    max-width: 100%;
    height: auto !important;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: sentry not working in frontend 
Javascript :: Function for masking the character 
Javascript :: Using a fallback if module loading fails 
Javascript :: javascriot html eqaul to jquery 
Javascript :: Get physical path in javascript 
Javascript :: how we pass 2 args in switch case javascript 
Javascript :: javascript intersection reduce, filter, includes 
Javascript :: typeorm sqlite Using async/await syntax 
Javascript :: typeorm clear cache 
Javascript :: react app environment variables undefined even when starts with REACT_APP_ 
Javascript :: new http version ANGULAR 
Javascript :: after storing array array state is empty 
Javascript :: change style selected text js 
Javascript :: angular optional attribute binding 
Javascript :: Reverse string by using split () method to convert our string into an array 
Javascript :: Classes and constructor functions in ES6 
Javascript :: pass props to svg 
Javascript :: Getting error after I put Async function in useEffect 
Javascript :: Replace all ocourrences in JS 
Javascript :: //testing 
Javascript :: icon with label in react native 
Javascript :: How to get only property names/keys from a nested object 
Javascript :: node app not visible in browser aws ec2 
Javascript :: More generic sort on each condition js 
Javascript :: Refresh a kendo ui widget, when options on AngularJS $scope change 
Javascript :: count selected gridview rows in javascript 
Javascript :: dev console with colored font 
Javascript :: triangle sum of odds numbers formula 
Javascript :: updater function 
Javascript :: remove undefined from object javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =