Is it possible to manually input values when printing a PDF instead of pulling them from the main HTML?

I am facing a challenge in adding a "Print PDF" option to my website because it is built using Ext.js, and therefore the code is not in HTML. Despite searching for ways to print a PDF from the site, all solutions I found involve using HTML. Is there any library or method available that allows me to manually specify what content I want to print rather than extracting it from the HTML code?

Below is how I have defined the table that I intend to print out in a PDF file:

const store = Ext.create('Ext.data.Store', {
                storeId:'hotelsStore',
                fields:['name', 'Best price', 'Price1', 'Price2', 'Price3'],
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'json',
                        root: 'items'
                    }
                }
            });

            const grid = Ext.define('KitchenSink.view.grid.CellEditing', {
                extend: 'Ext.grid.Panel',                
                xtype: 'cell-editing',
                initComponent: function() {                   
                    Ext.apply(this, {
                        store: Ext.data.StoreManager.lookup('hotelsStore'),
                        columns: [
                        {
                            header: 'Name',
                            dataIndex: 'name',
                            width: 300                           
                        }, {
                            header: 'Best price',
                            dataIndex: 'bestPrice',
                            width: 105
                        },
                        {
                            header: 'Price1',
                            dataIndex: 'priceSite1',
                            width: 200
                        },
                        {
                            header: 'Price2',
                            dataIndex: 'priceSite2',
                            width: 200
                        },
                        {
                            header: 'Price3',
                            dataIndex: 'priceSite3',
                            width: 200
                        },
                        {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            id: 'delete-column',
                            items: [{
                                icon: '/assets/img/delete.png',
                                tooltip: 'Delete',
                                scope: this,
                                handler: this.onRemoveClick
                            }],

                        }],
                        dockedItems: [{
                            xtype: 'toolbar',
                            items: [{
                                text: 'Add',
                                scope: this,
                                handler: this.add
                            }, {
                                text: 'Print values',
                                scope: this,
                                hander: this.printValues
                            }, {
                                text: 'Logout',
                                scope: this,
                                handler: this.logout
                            }]
                        }],                     
                    });

                    this.callParent();
},

The array containing the values I wish to include in the PDF is as follows:

function fillData()
  for(var i = 0; i<hotelNames.length; i++) {
      dataArray.push({ 'name': names[i], 'bestPrice': results[i2], 'Price1': 
      results[i4], 'Price2': results[i5], 'Price3': results[i6]})
      i2 = i2 + 4;
      i3 = i3 + 4;
      i4 = i4 + 4;
      i5 = i5 + 4;
      i6 = i6 + 4;
  }
}

Lastly, here is how I populate the table:

fillData();
store.getProxy().data = dataArray;
store.load();

Given that Ext.js uses JavaScript instead of HTML, I am unsure about how to proceed with achieving the desired functionality. Any guidance on this matter would be greatly appreciated.

Thank you in advance.

Answer №1

If you're looking to generate PDF documents, consider using either PDFMake or PDFKit libraries.

PDFMake is a PDF document generation library that can be used on both the server-side and client-side in pure JavaScript.

PDFKit is another option for PDF document generation, specifically designed for Node.js and browser environments. It simplifies the process of creating complex, multi-page documents with its chainable API featuring low-level functions and higher-level abstractions.


New Update! How to Utilize PDFKit in the Browser?

To integrate PDFKit into your web application, start by including the blobStream JS followed by the PDFkit JS.

Suggestive Code Snippets:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>Document</title>

    <script src="lib/blob-stream.js"></script>
    <script src="lib/pdfkit.js"></script>
    
    <script src="lib/script.js"></script>
    
</body>
</html>

script.js

var element = document.getElementById('printDoc'); 
element.addEventListener('click', ()=>{
 // create a document and pipe to a blob
        var doc = new PDFDocument();
        var stream = doc.pipe(blobStream());

        // draw some text
        doc.fontSize(25).text('Generating PDFs with ease!', 100, 80);

        doc.end();
        stream.on('finish', function () {

               window.open(stream.toBlobURL('application/pdf'), '_blank');
        });

});

For a visual demonstration, check out this Demo

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

What is the best method for utilizing the jQuery Selector in this particular web application?

I have been attempting to figure out how to select a delete icon within my personal web application. delectIcon HTML <main> <div class="container"> <div class="tabs"> <a href=""><p><span class="act ...

Is it possible to integrate a collection of libraries along with external dependencies into Vite?

Currently, I am in the process of packaging a library for npm that uses type: "module". To accomplish this, I have configured vite's library mode with the following settings: export default defineConfig({ css: { postcss: { plugin ...

The server is failing to provide the requested data in JSON format

I am struggling with making a simple API call using Node.js as the backend and React in the frontend. My Node.js file is not returning data in JSON format, and I'm unsure of the reason behind this issue. I need assistance with two main things: Why is ...

Looking for a way to choose an Object using the key value in VueJS?

In my Vuejs setup, there is an object containing various fields including an email value which looks like this: "[email protected]". { "fields": [ { "label": "email", "value": "<a href="/cdn-cgi/l/email-protection ...

Determine the height of a DIV element and its contents using JQuery

In this div, there are various elements present: <div class="menuItem designMenu" id="dMenu"> <ul class="menuList menu"> <li class="menuHeader">Design</li> <li class="projectHeader">Mother</li> <li clas ...

Select Menu (Code Languages:CSS, JS, HTML, BBCode)

I'm currently in the process of setting up a BB code for a forum I moderate. Here's the code snippet I'm using to generate a dropdown box that users can add to the signature field of their profiles: <!DOCTYPE html> <html> <d ...

I am interested in duplicating the li elements retrieved from a JSON source

$.getJSON("leftlist.json" , function(data) { $.each(data.articles,function(){ $('#ullist').before("<li id='mylic' style= color:blue class='item new"+cc+"'> "+el.name+"<div class='block'>&l ...

Assigning event to the body element

Is there a way to bind an event to the entire page, specifically the html or body tag? I am trying to achieve the following: document.addEventListener('mousemove', function() { alert('a'); }); I want an alert to be triggered whenever ...

Troubleshooting GLSL scripts within a web-based WebGL environment

Are there ways to debug GLSL code or display variable values directly from within the GLSL code when using it with WebGL? Does three.js or scene.js offer any features for this purpose? ...

Passing Data from Child to Parent Components in ReactJS

I'm new to React and JavaScript, currently working on a website. I've encountered an issue with passing data between components from child to parent. Here's the scenario: In my App.js script, I'm using react-router-dom for routing. I ...

AngularJS select box setting selected valueIt can be accomplished by manipulating the

I am facing an issue with a selectbox populated with options from the backend. <tr> <td class="col-lg-4">Superkund</td> <td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item as item ...

The error property is not found in the type AxiosResponse<any, any> or { error: AxiosError<unknown, any>; }

As a beginner with typescript, I am encountering some issues with the following code snippet import axios, { AxiosResponse, AxiosError } from 'axios'; const get = async () => { const url = 'https://example.com'; const reques ...

Is there a way to limit the rotation of an a-camera in aframe?

One scenario could be enabling rotation around the z-axis within a range of -70 to 70 degrees, or alternatively, preventing rotation around any arbitrary axis. Thank you! ...

Encountering difficulties with updating an object in Angular

Currently, I have the ability to generate objects and store them in a rails database using a json api. The application is a basic todo list where adding an object places it into the todo list above the input fields. Furthermore, I can access all objects on ...

Concealing UI elements within the primary stack during navigation to a nested stack in React navigation

Is there a way to hide the user interface in my main stack when I switch to the nested drawer stack? I am currently facing an issue where the header from my main stack appears above the header in my nested stack when I navigate to a screen using: navigat ...

Explore how to set up Express with React without resorting to using create-react

I am familiar with the react and Node.js Express bundle, but I require assistance. While this question may have been posed by someone else before, I have not come across a similar query within the same framework. The specific question is: How can queries ...

Displaying API response array object in React application

Currently, I am attempting to retrieve information from an API, parse the response content, and then display it in a loop. However, I have encountered a warning message: webpackHotDevClient.js:138 ./src/App.js Line 20: Expected an assignment or function ...

What is the best method for determining the cookie expiration time in AngularJS 1.3?

Currently in my application, I am utilizing AngularJS 1.3. I encountered a challenge while using $cookies to store data where I needed to implement a 1-minute expiration time for the cookie. However, the $cookies service in AngularJS 1.3 does not provide ...

Updates to the visibility of sides on ThreeJS materials

When viewed from the back, the side is hidden as desired, but I am struggling to determine if it is visible from the renderer or camera. new THREE.MeshBasicMaterial({ map: new, THREE.TextureLoader().load('image.jpg'), side: THREE. ...

Stop users from inputting dates beyond the current date in Angular 4

Encountering an issue with comparing the date of birth object and today's date object using Moment.js. Even if the entered date is smaller than today's date, it still throws an error. Below is the HTML code: <div class="form-group datepicker ...