pdf button with configuration that generates PDF file but i want to prevent it from downloading

pdf button with configuration that generates PDF file but i want to prevent it from downloading

vaishalir04vaishalir04 Posts: 1Questions: 1Answers: 0
edited August 26 in Free community support
{
                            text: 'Share PDF',
                            className: 'buttons-share-pdf',
                            filename: 'Financial_Statement' + Date.now(),
                            orientation: 'landscape',
                            pageSize: 'LEGAL',
                            customize: function customize(doc) {
                              doc.content[1].table.body.slice(1).forEach(function (rows) {
                                rows[3].text = rows[3].text.replace(/\s+/g, '');
                              }); // Create the PDF without downloading
                        
                              pdfMake.createPdf(doc).getBlob(function (blob) {
                                var formData = new FormData();
                                formData.append('pdf', blob, 'Financial_Statement' + Date.now() + '.pdf'); // Retrieve CSRF token from meta tag
                        
                                var csrfTokenMeta = document.head.querySelector("[name~=csrf-token][content]");
                                var csrfToken = csrfTokenMeta ? csrfTokenMeta.content : null;
                        
                                if (csrfToken) {
                                  formData.append('_token', csrfToken); // Append CSRF token to formData
                                } // Send the Blob to the server
                        
                        
                                var url = HOME;
                                $.ajax({
                                  url: url,
                                  method: 'POST',
                                  data: formData,
                                  processData: false,
                                  contentType: false,
                                  success: function success(response) {
                                    console.log('PDF sent to server successfully', response);
                                  },
                                  error: function error(xhr, status, _error) {
                                    console.error('Error sending PDF to server', _error);
                                  }
                                });
                              });
                            },
                            enabled: false
                        } 

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Just to confirm, you are sharing your solution?

    Allan

Sign In or Register to comment.