How to Generate PDFs from HTML Views using AngularJS

Utilizing bootstrap, I have developed a modal window that includes valuable information, tables, and text areas. Is there a way to generate a .pdf file from this particular .html modal view?

I explored FileSaver, which seems to be effective for downloading tables only. What I am aiming for is more like capturing a screenshot of the modal window.

Answer №1

How to convert HTML to a canvas using html2canvas and then utilize jsPdf to transform it into a PDF document. Check out this example on JSFiddle.

Here is an example of how you can achieve this:

<canvas id="canvas" width="480" height="320"></canvas>
<button id="download">Download Pdf</button>

html2canvas($("#canvas"), {
    onrendered: function(canvas) {         
        var imgData = canvas.toDataURL(
            'image/png');              
        var doc = new jsPDF('p', 'mm');
        doc.addImage(imgData, 'PNG', 10, 10);
        doc.save('sample-file.pdf');
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The functionality of a Vue custom tooltip behaves strangely after clicking the button multiple times

I created this custom tooltip code that automatically closes after 2 seconds when a user clicks on a button, not just hovers over it. Initially, it works perfectly for the first two clicks, but then starts behaving strangely from the third click onwards. ...

Ways to acquire dynamic content without relying on Remark/Grey Matter

In my stack of technologies, I am using nextJS with react and typescript. While I have successfully set dynamic routes for my blog posts, I am now facing a challenge in creating pages that do not rely on markdown. Despite searching extensively for code exa ...

What is the method for incorporating a fixed tooltip on a plotline in highstock?

After coming across this example on jsfiddle, I stumbled upon a related question on Highcharts plotband tooltip styling on Stack Overflow... My goal is to have the label displayed from the start without needing the "mouseout and mouseover" events. events ...

Choose an option from the selection menu automatically using a link

I am looking to utilize either PHP or JavaScript in order to link to a page and add either "?type=foo" or "#foo" at the end of the URL. This will allow for a specific option to be automatically selected from a dropdown menu within a form when the linked ...

Angular's ng-repeat is capable of iterating through each character rather than each entry in a JSON object

Currently, I am in the process of learning AngularJS and attempting to pull JSON data into a table. However, when using "ng-repeat" on a table row, it seems to repeat for every character in my JSON instead of finding the element. This is my INDEX file: & ...

What is the best way to access a JSON Array in php without using any specified keys?

I'm dealing with a JSON object created in JavaScript and passed to PHP via AJAX. The issue I'm facing is that I can't figure out how to assign keys to each JSON object within the JSON array. Here's an example of how the JSON array looks ...

After updating next.config, the NextJS + NextAuth middleware doesn't seem to be triggered

I'm currently utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0ded5c8c49dd1c5c4d8f0849e81889e87">[email protected]</a> & <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemai ...

Utilizing Javascript / jQuery to eliminate specific CSS styles

I am facing an issue with the CSS code for a table positioned at the bottom of the screen. The current code includes a filter specifically for IE 8, but I need to make it compatible with IE 10 as well by removing the filter and adding a background color. ...

Passing a PHP variable to a JavaScript function in Laravel results in the key being displayed instead of the value

I am currently passing the ID of a Laravel object through a href click to a JavaScript function. <a onclick="getDetails('{{$details->id}}')"</a> This method works partially, as my console.log displays the correct ID 28. However, whe ...

Error: The variable "user" has not been declared in server.js when using passportjs

As a novice with limited experience and a tendency to borrow code snippets from various sources, I'm struggling to identify the root cause of the Reference Error: User is not defined. This particular error crops up when I try to input or submit a new ...

How can I resolve the issue of "require is not defined" in the code?

tag, you can find the following code snippet: Upon importing the 'mysql' module, an issue persists in the browser matching the error indicated by the title. Starting my journey into programming, I aim to develop a membership registration functio ...

JavaScript Cursor-Based Auto Typing Tool

I want to develop a straightforward Javascript auto writer within an HTML page. Below is the code I have written: <html> <head> <style> #type { display: inline-block; } #cur { display: inline-block; ...

I need assistance with getting checkboxes to submit information when clicked - they just refuse to cooperate!

Hello there! This is my second post and I'm only in my second week of programming, so please bear with me. I've got a group of checkboxes that act as different search filters which I'd like to pass to params. For instance, if it was a resta ...

Is there a way to hit the Enter key without causing the page to reload?

Currently, I am working on a wiki search project and facing an issue that I haven't been able to resolve through Stack Overflow. My challenge lies in trying to trigger an XMLHttp request when the enter key is pressed, without the page refreshing. Desp ...

NextJS application having trouble re-rendering after state update

Although this question is commonly asked, none of the solutions seem to work for me. I am facing an issue where updating a variable using useState does not trigger re-rendering of any components. The scenario involves POSTing data using NextJS API Routing ...

To effectively execute a JQuery / Javascript function, it is essential to incorporate both $(document).ready and $(document).ajaxSucces

I have a JavaScript function that is used for basic UI functionality across my site. Some elements affected by this function are injected via Ajax, while others are static HTML. Currently, I have duplicated the function and applied it to both $(document). ...

Possible issue with accurate indexing causing caption error with API images in React

Continuing from: Implementing a lightbox feature in react-multi-carousel for my ReactJS app My application utilizes react-images for the lightbox functionality and react-carousel-images for the carousel. The API provides a title and image data. The issue ...

"Unlocking the Power of jQuery: A Guide to Accessing XML Child

I'm struggling to extract the xml in its current format. While I can easily retrieve the InventoryResponse, I am facing difficulties when trying to access the child node a:Cost. Despite conducting research, I have been unable to find a solution that w ...

Is there a way to convert a PDF file to a Javascript array using a

Is there a way to extract only words from a PDF document using JavaScript? I am not interested in images, digits, or tables - just the words so that I can manipulate them as JavaScript objects. ...

What is the process for retrieving the text element from a React component when using React.cloneElement?

Can I centralize a translation function for all table header elements? const CustomersTable = () => { var headers=<> <th>Name</th> <th>Age</th> <th>Another text</th> </> ...