Coder Social home page Coder Social logo

Comments (7)

pipwerks avatar pipwerks commented on August 30, 2024 2

Now that PDFObject uses iframes exclusively, the onload handler will be consistent across browsers.

Important: The onload event only indicates that the iframe has loaded something, there is no guarantee the iframe has properly loaded the PDF (and no way to check).

let pdf_iframe = PDFObject.embed("myfile.pdf");
pdf_iframe.addEventListener('load', function () {
    alert('loaded');
});

from pdfobject.

pipwerks avatar pipwerks commented on August 30, 2024

A good idea, but I don't think this is possible; Adobe Reader exposes a JavaScript API, but built-in PDF readers (Chrome, Safari) don't expose a JavaScript API. No API means no way to know whether the file has finished loading. Sorry.

from pdfobject.

filipefigcorreia avatar filipefigcorreia commented on August 30, 2024

Would pre-loading the pdf be a possibility? I suppose that could allow to know when it finishes loading.

from pdfobject.

niklas-dahl avatar niklas-dahl commented on August 30, 2024

ist there now 4 years later the possibility to get a load event?

from pdfobject.

pipwerks avatar pipwerks commented on August 30, 2024

This is not possible due to a limitation in the browsers themselves -- their built-in PDF rendering engines do not provide APIs. There is no 'loaded' event, and no way to know whether the PDF has properly loaded.

from pdfobject.

cwilby avatar cwilby commented on August 30, 2024

I'm not sure if this changed recently, but it looks to be possible to add a load event listener to either the iframe (PDFObject 2.x) or object (PDFObject 1.x) as follows:

v1.2.0

PDFObject({ url: '/test.pdf' }).embed(document.querySelector('#pdf'));

document.querySelector('#pdf object').addEventListener('load', function () {
    alert('loaded');
});

v2.3.0

PDFObject.embed('/test.pdf', '#pdf');

document.querySelector('#pdf iframe').addEventListener('load', function () {
    alert('loaded');
});

I am currently using this to implement a loadmask/spinner.

from pdfobject.

pipwerks avatar pipwerks commented on August 30, 2024

I added this use case to the docs https://pdfobject.com/examples/#callback-on-onload-event

from pdfobject.

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.