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 :: comments in js 
Javascript :: axios put request 
Javascript :: javascript sort multi-dimensional array by column 
Javascript :: transaction commit rollback nodejs 
Javascript :: how to get 3rd li using jquery 
Javascript :: redirect using expressjs 
Javascript :: faker js uuid example 
Javascript :: what is vue.js 
Javascript :: filter data from object 
Javascript :: hammerjs 
Javascript :: schema in mongoose 
Javascript :: usestate hook with callback 
Javascript :: bootstrap 4 open tab when opening modal 
Javascript :: javaScript getMonth() Method 
Javascript :: try catch 
Javascript :: write hello world in javaskript 
Javascript :: forece reload without clear cache js 
Javascript :: jquery fedein background color 
Javascript :: how to change object property value in javascript 
Javascript :: async await react stackoverflow 
Javascript :: js array string includes 
Javascript :: next js get query parameters 
Javascript :: js pass data between pages 
Javascript :: server smtp 
Javascript :: get last element in array javascript 
Javascript :: parseint() javascript 
Javascript :: JavaScript Nested Function 
Javascript :: upload bloob javascript 
Javascript :: Enqueuing JavaScript in WordPress 
Javascript :: jquery properly work 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =