surveyjs / survey-analytics

Customizable JavaScript library to create interactive survey data dashboards and facilitate survey results analysis for your end-users.
https://surveyjs.io/dashboard/examples/plain-data
Other
97 stars 49 forks source link

Signature Pad - Export a Signature to PDF instead of a question name (e.g., 'signature') #376

Open JaneSjs opened 8 months ago

JaneSjs commented 8 months ago

https://github.com/surveyjs/survey-analytics/blob/d4d8887a2d0f5f6c4840cc3870dbb671d5052e10/src/tables/tabulator.ts#L239

User Issue: T15237 - COMO DESCARGAR LAS PDF Y EXCEL CON IMAGENES https://surveyjs.answerdesk.io/internal/ticket/details/T15237

Tabulator appears as follows: image

Current output after exporting a Tabulator to PDF: image

Expected output: signature images appear in PDF.

tsv2013 commented 7 months ago

I used the following code:

        if(question instanceof QuestionSignaturePadModel) {
          return this.currentDownloadType === "pdf" && !!dataCell ? `<img-${question.signatureWidth}-${question.signatureHeight}>${dataCell}` : questionName;
        }

in the accessorDownload function. And this code in the defaultDownloadOptions:

        didParseCell: function(data) {
          if (data && data.cell.raw.content) {
            const hasImagePrefix = (data.cell.raw.content || "").substring(0, 5) === "<img-";
            if(hasImagePrefix) {
              data.cell.height = 200;
            }
          }
        },
        willDrawCell: function(data) {
          if (data && data.cell.raw.content) {
            const hasImagePrefix = (data.cell.raw.content || "").substring(0, 5) === "<img-";
            if(hasImagePrefix) {
              const imagePreficIndex = data.cell.raw.content.indexOf(">");
              const imageUrl = data.cell.raw.content.substring(imagePreficIndex+1);
              if(!!imageUrl) {
                const dims = data.cell.raw.content.substring(5, imagePreficIndex).split("-");
                // var dim = data.cell.height - data.cell.padding("vertical");
                doc.addImage(imageUrl, data.cell.x, data.cell.y, Number.parseInt(dims[0]), Number.parseInt(dims[1]));
                data.cell.contentWidth = data.cell.width;
                data.cell.contentHeight = Number.parseInt(dims[1]);
                data.row.maxCellHeight = Object.keys(data.row.cells).reduce((a, key) => Math.max(a, data.row.cells[key].height), 0);
                data.row.height = data.row.maxCellHeight;
                return false;
              }
            }
          }
        }

But I still have the problem: table row height still remains large (as it was calculated for lerge base64 text). Right now I've not found a quick solution for it.

tsv2013 commented 7 months ago

For more details check code in the https://github.com/simonbengtsson/jsPDF-AutoTable repo

https://github.com/simonbengtsson/jsPDF-AutoTable/blob/16b9a37d5d2f88c6ff39b03349adede17b71ec90/src/widthCalculator.ts#L67