Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

next js generate pdf complete

import * as React from "react";
import Image from "next/image";
import dynamic from "next/dynamic";
const GeneratePDF = dynamic(()=>import("./../src/components/GeneratePDF"),{ssr:false});
const app =()=>{
        const ref = React.useRef();

        return(<div className="main">
        <div className="content" ref={ref}>
        <h1>Hello PDF</h1>
        <img id="image" src="/images/image_header.jpg" width="300" height="200"/>
        <p id="text">
            Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quisquam animi, molestiae quaerat assumenda neque culpa ab aliquam facilis eos nesciunt! Voluptatibus eligendi vero amet dolorem omnis provident beatae nihil earum!
            Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ea, est. Magni animi fugit voluptates mollitia officia libero in. Voluptatibus nisi assumenda accusamus deserunt sunt quidem in, ab perspiciatis ad rem.
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Nihil accusantium reprehenderit, quasi dolorum deserunt, nisi dolores quae officiis odio vel natus! Pariatur enim culpa velit consequatur sapiente natus dicta alias!
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur, asperiores error laudantium corporis sunt earum incidunt expedita quo quidem delectus fugiat facilis quia impedit sit magni quibusdam ipsam reiciendis quaerat!
        </p>
        </div>
        <GeneratePDF html={ref}/>
        </div>);
}

export default app;
Comment

next js generate pdf

import React from "react";
import { jsPDF,HTMLOptionImage } from "jspdf";
import { toPng,toCanvas } from "html-to-image";
type props = {

  html?: React.MutableRefObject<HTMLDivElement>;

};

const GeneratePdf: React.FC<props> = ({ html }) => {
  const generatePdf = () => {
      const doc = new jsPDF();

      let split=doc.splitTextToSize(document.getElementById("text").innerText,200);
      let image = document.getElementById("image").getAttribute('src');
      doc.text(document.querySelector(".content > h1").innerHTML,75,5);
      doc.addImage(image,70,7,60,60);
      doc.text(split,5,75);
      doc.output("dataurlnewwindow");  

  };

  const generateImage=async ()=>{
    const image = await toPng(html.current,{quality:0.95});
    const doc = new jsPDF();

      doc.addImage(image,'JPEG',5,22,200,160);
      doc.save();


  }
  return (

    <div className="button-container">
        <button onClick={generateImage}>
        Get PDF using image
      </button>
      <button onClick={generatePdf}>
        Get PDF as text
      </button>
    </div>

  );
};

export default GeneratePdf;
Comment

PREVIOUS NEXT
Code Example
Javascript :: a function that returns a string javascript 
Javascript :: react native choose simulator 
Javascript :: useQuery by click 
Javascript :: jquery has class 
Javascript :: Vue Chartjs label false 
Javascript :: stop execution javascript 
Javascript :: Laravel react 404 routes 
Javascript :: console 
Javascript :: event.target.name in setstate 
Javascript :: copy array of object in js 
Javascript :: setinterval 
Javascript :: toast notification angular bootstrap 8 
Javascript :: useformik checkbox multiselect 
Javascript :: Removing borderline of input in react 
Javascript :: angularjs - controllerAs 
Javascript :: detect localstorage limit 
Javascript :: nest js crons 
Javascript :: jest cross origin localhost fobbiden 
Javascript :: react set initial state without constructor 
Javascript :: react setstate concat string 
Javascript :: nodejs: create model by mongoose package 
Javascript :: webpack.config.js 
Javascript :: openstreetmap api example javascript 
Javascript :: jquery select 
Javascript :: vue method 
Javascript :: js variable to string 
Javascript :: how to add jquery to an html css and javascript project 
Javascript :: moment get month day 
Javascript :: delete array 
Javascript :: spam system discord.js 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =