Giter Site home page Giter Site logo

Comments (9)

Tushar-Yadav-TCPL avatar Tushar-Yadav-TCPL commented on August 15, 2024 1

I am also facing same issue.

from react-to-pdf.

oliversentact avatar oliversentact commented on August 15, 2024 1

@Amaka202 Unfortunately I was not. Due to time constraints I had to pivot to another library instead of taking a ton of time to figure this issue out. I used react-pdf https://react-pdf.org/ instead, which was workable. I don't like react-pdf because it doesn't let you use anything but its own component library, which is super inconvenient and consumes a lot more time than using any old JSX, but with that said it really is a powerful library

from react-to-pdf.

ivmarcos avatar ivmarcos commented on August 15, 2024 1

Not sure if that matters now due to the time elapsed, sorry, but on V1 maybe using the imageTimeout option from htm2canvas might be a way out.

import generatePDF, { Options } from 'react-to-pdf'

const options: Options = {
   filename: 'test.pdf',
   overrides: {
       canvas: {
           imageTimeout: 10000
      }
   }
}

const Component = () => {
   const targetRef = useRef();
   return (
      <div>
         <button onClick={() => generatePDF(targetRef, options)}>Download PDF</button>
         <div ref={targetRef}>
            Content to be included in the PDF
         </div>
      </div>
   )
}

from react-to-pdf.

oliversentact avatar oliversentact commented on August 15, 2024

The title is confusing and there is no information but I am having this same problem.

I am including an image in an <img /> tag that displays well in my component. Then when I click the download button, the layout still holds but there is no image, just empty space.

Are we able to include images in our PDFs?

from react-to-pdf.

crscaballero avatar crscaballero commented on August 15, 2024

The title is confusing and there is no information but I am having this same problem.

I am including an image in an <img /> tag that displays well in my component. Then when I click the download button, the layout still holds but there is no image, just empty space.

Are we able to include images in our PDFs?

I'm having the same problem

from react-to-pdf.

SinaSaintZero avatar SinaSaintZero commented on August 15, 2024

Same issue

from react-to-pdf.

Amaka202 avatar Amaka202 commented on August 15, 2024

hello, @SinaSaintZero @Tushar-Yadav-TCPL @crscaballero @oliverterrell @itsshajad I am currently experiencing this and wanted to know if any of you were able to find a solution? 🙂

from react-to-pdf.

abdullahqureshi5050 avatar abdullahqureshi5050 commented on August 15, 2024

This is how I fixed it. If your image is from a remote URL it will not show. First allow CORS (if working with different hosted backend and frontend). Then covert your remote url to local url at frontend side. This issue occurs as remote URL takes time to process and pdf is generated before the image is fetched. So you have to make sure the image is loaded before converting to pdf.

 async function fetchImage() {
            const imageUrl = 'https://i.imgur.com/7obGLSR.jpeg';
            if (!imageUrl || imageUrl.length === 0) return;
            try {
                const response = await fetch(imageUrl);

                if (!response.ok) {
                    throw new Error(
                        `Image fetch failed with status: ${response.status}`,
                    );
                }

                const blob = await response.blob();
                const blogToLocalURL = URL.createObjectURL(blob);
            } catch (error) {
                console.error('Error fetching pdf image:', error);
            }
        }

from react-to-pdf.

ivmarcos avatar ivmarcos commented on August 15, 2024

Closing this, but feel free to open another ticket if the problem persists with the newest releases.

from react-to-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.