Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work for #376 - Signature Pad - Export a Signature to PDF instead of … #379

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/tables/tabulator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ITableOptions, Table, TableRow } from "./table";
import { SurveyModel } from "survey-core";
import { Question, QuestionSignaturePadModel, SurveyModel } from "survey-core";
import { ColumnDataType, IColumnData, QuestionLocation } from "./config";
import { DocumentHelper } from "../utils";
import { localization } from "../localizationManager";
Expand Down Expand Up @@ -44,6 +44,33 @@ export const defaultDownloadOptions = {
cellWidth: 1,
},
margin: { top: 10, right: 10, bottom: 10, left: 10 },
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;
}
}
}
}
};
},
},
Expand Down Expand Up @@ -228,14 +255,17 @@ export class Tabulator extends Table {

this._rows.push(tableRow);
};
private accessorDownload = (cellData: any, rowData: any, reason: string, _: any, columnComponent: any, rowComponent: any) => {
private accessorDownload = (question: Question) => (cellData: any, rowData: any, reason: string, _: any, columnComponent: any, rowComponent: any) => {
const columnDefinition = columnComponent.getDefinition();
const questionName = columnDefinition.field;
const column = this.columns.filter(col => col.name === questionName)[0];
if (!!column && rowComponent) {
const dataRow = this.data[rowComponent.getPosition()];
const dataCell = dataRow[questionName];
if (column.dataType === ColumnDataType.Image) {
if(question instanceof QuestionSignaturePadModel) {
return this.currentDownloadType === "pdf" && !!dataCell ? `<img-${question.signatureWidth}-${question.signatureHeight}>${dataCell}` : questionName;
}
return questionName;
}
if (column.dataType === ColumnDataType.FileLink && Array.isArray(dataCell)) {
Expand Down Expand Up @@ -302,7 +332,7 @@ export class Tabulator extends Table {
headerSort: false,
download: this._options.downloadHiddenColumns ? true : undefined,
formatter,
accessorDownload: this.accessorDownload,
accessorDownload: this.accessorDownload(question),
titleFormatter: (cell: any, formatterParams: any, onRendered: any) => {
return this.getTitleFormatter(
cell,
Expand Down
Loading