Transform HTML and CSS into a PDF format using JavaScript

I have a design page in a .cshtml document that displays correctly in all major browsers (FireFox, Chrome, and IE). It utilizes basic CSS for styling and looks great in HTML format.

Now, I am attempting to convert one of its DIV elements to PDF. However, I am encountering challenges such as white spaces and page breaks. I have explored various options:

jsPDF: While it worked fine with regular content, it struggled greatly with HTML tables. Even after removing the large tables, it failed to properly render images and caused the tables to break incorrectly at page ends.

Windows Print: Another approach involved using the Windows print feature through JavaScript. Unfortunately, this method automatically included the site logo image on every page of the PDF, causing overlaps with the data lines.

nReco: I also experimented with nReco tools for converting HTML to PDF, only to find myself facing the same issues as mentioned above.

What could be the missing piece here? How can I potentially resolve these challenges?

Answer №1

If you're struggling with jspdf, consider giving the html2pdf library a try. In my experience, it's been much easier to implement and has successfully resolved tricky svg/grid problems.

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

Tips for automatically updating the time in a React application while utilizing the 'date-fns' library

I've been working on my personal Portfolio using React and I'm looking to add a feature on the landing page that showcases my local time and timezone to potential recruiters. However, there's a small hiccup in my implementation. The displaye ...

NG build error: Module parsing failed due to an unexpected token - no updates made

Two days ago, out of nowhere, we started encountering build errors during deployment using GitLab CI. No alterations have been made to the build scripts, and none of the versions of NPM, NG, or Angular have been modified. The same compilation commands cont ...

Trying to set headers in Node/Express after they have already been sent is causing an error

I am attempting to send form data from the client side using jQuery to a POST route that will then pass the data to an API in Node/Express. I am encountering an issue where I receive the error message "Can't set headers after they are sent" and I am ...

How can a component in AngularJS 1.5 access a function from its parent service?

In my main app module, I have a service with several methods and two independent components that are injected into the main module. The goal is to trigger an event in component1 that will call a method in the service of the main app module, which in turn w ...

ReadAllLines() method in C# LINQ encounters issues when processing a sizable 650MB CSV file

I've encountered an issue with my code that works perfectly fine when dealing with CSV files under 1MB, but fails when attempting to read a 600MB file. Do you know why this is happening and what possible solutions I could implement? My goal is to rea ...

Guide on adding the newest version of Jquery in asp.net 4.5 using <asp:scriptreference> tag

Looking to update the jQuery version in my web application. Currently, jQuery 1.7.1 is being loaded by default. I am aware that the following code is responsible for this. But how can I switch to loading jQuery 1.10 instead? <asp:ScriptManager runat ...

Reset IntersectionObserverAPI to its initial state when none of the elements are in view

Currently, I am utilizing a React Hook that enables me to observe when an element becomes visible in the viewport. The functionality works smoothly until I encounter the need to 'reset' the state once all elements are hidden (such as when reachin ...

Ways to standardize the input email address?

While using express-validator, I came across an issue where I used normalize email for validation of email during sign up and stored the normalized email on the server. Validation code: router.post( "/signup", [ check("name").n ...

Challenges with integrating a Bootstrap 4 table into a card component

Here is a problem I am facing. It seems that the table inside the card is not displaying correctly. I want the table to be centered or at least eliminate the blank space that is currently showing. Here is my code (using Angular 6): <div class="row ...

The HTTPS Ajax Request Google Chrome Extension

I am developing a Google Chrome extension and need to send an AJAX request to a HTTPS *REST API*. When I tested this request on an HTTP page but attempted to make the request to a HTTPS page, it did not work due to cross-domain posting restrictions. I sear ...

Obtain a controller's reference from a callback by utilizing TypeScript

Implementing a simple controller that utilizes a directive/component and passes a function as binding. However, when the function is called, there is no reference available to access any of the controller class services. Within the "public onTileClicked" ...

Tips for navigating an Angular JS web application

I am currently attempting to crawl a web application that presents login as the initial obstacle, and is constructed using AngularJS. My approach involved employing Scrapy and Selenium for crawling the website; however, I encountered an issue with the logi ...

Preventing the removal of a choice by disabling it in the selector

I have a unique selector that is designed like this: <select id="patientSelector"> <option disabled selected style='display: none;' id="select0"> New Patients to Come</option> <option id="select1"></opt ...

Arranging elements in XML file based on attribute

Check out this XML code: <Group> <GElement code="x"> <Group> <GElement code="x"> <fname>a</fname> <lname>b</lname> </GElement> ...

Enhance your CSS tables by including margin columns and adding a bottom border to each row

After working on an HTML table element, I decided to include some space between the columns. To achieve this, I used the following css properties: table { border-collapse: separate; border-spacing: 36px 0px; } However, I encountered an issue when attem ...

Hot Towel Angular with Visual Studio 2015

I recently installed Visual Studio 2015 RC1 and attempted to install the Hot Towel Angular Package. However, upon installation, I encountered the following messages in the output window: Successfully installed 'HotTowel.Angular.2.3.3' to Value ...

Ways to transfer information to a Jquery Dialog upon its opening

Upon loading the JSP, I want to display a JQuery dialog without requiring the user to click on a button. To achieve this, I am checking for a flag from the bean called showPopupFlag. Additionally, I would like to populate the dialog with some data using di ...

Update the status of the reactive form control to invalid

I'm attempting to mark a form control as invalid, however, the following code snippet is not producing the desired result this.currencyForm.controls['currencyMaxSell'].setErrors({smallerThan: true}) ...

Brick-themed HTML/CSS elements drift away from each other

I'm currently designing an image collage for my website and attempted to use masonry for the layout. However, when I adjust the size of the blocks, they seem to drift apart, creating large gaps between each block. Any suggestions on how to resolve thi ...

Why is this chip-list not functioning properly in my Angular 14 and Angular material application?

I'm currently developing a form using Angular 14. My goal is to incorporate a field with Angular Material chips. Within the component's Typescript file, I have the following code: constructor(private fb: FormBuilder,) { } public visible: boole ...