@@ -11,14 +11,14 @@ import {
1111 SurveyCreatorComponent ,
1212 SurveyCreator
1313} from 'survey-creator-react' ;
14- import { ComputedUpdater , Action , SurveyModel , SvgRegistry } from 'survey-core' ;
15- import { IDocOptions , SurveyPDF } from 'survey-pdf' ;
1614import 'survey-core/survey-core.css' ;
1715import 'survey-creator-core/survey-creator-core.css' ;
1816import 'ace-builds/src-noconflict/ace' ;
1917import 'ace-builds/src-noconflict/ext-searchbox' ;
2018import SurveyCreatorTheme from 'survey-creator-core/themes' ;
2119import { creatorTheme } from '../styles/form-builder-theme' ;
20+ import { createPdfAction } from '../utils/surveyPdf' ;
21+ import { Action } from 'survey-core' ;
2222
2323registerCreatorTheme ( SurveyCreatorTheme ) ;
2424
@@ -57,37 +57,7 @@ export default function FormBuilderComponent(props: {
5757
5858 creator . applyCreatorTheme ( creatorTheme ) ;
5959
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 ) ;
9161 creator . toolbar . actions . push ( savePdfAction ) ;
9262 creator . footerToolbar . actions . push ( savePdfAction ) ;
9363
0 commit comments