@@ -11,14 +11,14 @@ import {
11
11
SurveyCreatorComponent ,
12
12
SurveyCreator
13
13
} from 'survey-creator-react' ;
14
- import { ComputedUpdater , Action , SurveyModel , SvgRegistry } from 'survey-core' ;
15
- import { IDocOptions , SurveyPDF } from 'survey-pdf' ;
16
14
import 'survey-core/survey-core.css' ;
17
15
import 'survey-creator-core/survey-creator-core.css' ;
18
16
import 'ace-builds/src-noconflict/ace' ;
19
17
import 'ace-builds/src-noconflict/ext-searchbox' ;
20
18
import SurveyCreatorTheme from 'survey-creator-core/themes' ;
21
19
import { creatorTheme } from '../styles/form-builder-theme' ;
20
+ import { createPdfAction } from '../utils/surveyPdf' ;
21
+ import { Action } from 'survey-core' ;
22
22
23
23
registerCreatorTheme ( SurveyCreatorTheme ) ;
24
24
@@ -57,37 +57,7 @@ export default function FormBuilderComponent(props: {
57
57
58
58
creator . applyCreatorTheme ( creatorTheme ) ;
59
59
60
- function savePdf ( survey : SurveyModel ) {
61
- const pdfDocOptions : IDocOptions = {
62
- fontSize : 14 ,
63
- margins : {
64
- left : 10 ,
65
- right : 10 ,
66
- top : 10 ,
67
- bot : 10
68
- } ,
69
- format : [ 210 , 297 ]
70
- } ;
71
- const surveyPDF = new SurveyPDF ( survey . toJSON ( ) , pdfDocOptions ) ;
72
- surveyPDF . readOnly = survey . pdfReadonly ;
73
- surveyPDF . locale = survey . locale ;
74
- surveyPDF . data = survey . data ;
75
- surveyPDF . save ( survey . pdfFileName ) ;
76
- }
77
- const customIcon = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 2a2 2 0 0 0-2 2v16c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2V8l-6-6H6zm7 1.5L18.5 9H13V3.5zM12 13v4.17l-1.59-1.58L9 17l4 4 4-4-1.41-1.41L13 17.17V13h-1z"/></svg>' ;
78
- SvgRegistry . registerIcon ( "icon-savepdf" , customIcon ) ;
79
- const savePdfAction = new Action ( {
80
- id : 'svd-save-pdf' ,
81
- title : 'Save as PDF' ,
82
- iconName : 'icon-savepdf' ,
83
- visible : new ComputedUpdater ( ( ) => creator . activeTab === 'preview' ) ,
84
- enabled : true ,
85
- action : ( ) => {
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- const surveyModel = ( creator . getPlugin ( "preview" ) as any ) . model . survey as SurveyModel ;
88
- savePdf ( surveyModel ) ;
89
- }
90
- } ) ;
60
+ const savePdfAction : Action = createPdfAction ( creator ) ;
91
61
creator . toolbar . actions . push ( savePdfAction ) ;
92
62
creator . footerToolbar . actions . push ( savePdfAction ) ;
93
63
0 commit comments