@ckeditor/ckeditor5-export-pdf
Version:
Export to PDF feature for CKEditor 5.
23 lines • 9.66 kB
JavaScript
/*
* Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
*
*
*
*
* +---------------------------------------------------------------------------------+
* | |
* | Hello stranger! |
* | |
* | |
* | What you're currently looking at is the source code of a legally protected, |
* | proprietary software. Any attempts to deobfuscate / disassemble this code |
* | are forbidden and will result in legal consequences. |
* | |
* | |
* +---------------------------------------------------------------------------------+
*
*
*
*
*/
import{Command as _0x2e54a3,Plugin as _0x5d1c32}from'@ckeditor/ckeditor5-core';import{collectStylesheets as _0x4582ee}from'@ckeditor/ckeditor5-utils';import{ButtonView as _0x26713a,MenuBarMenuListItemButtonView as _0x401b6f,Notification as _0x33b3a9,SpinnerView as _0x24a5a6}from'@ckeditor/ckeditor5-ui';import{CloudServices as _0x30ec22}from'@ckeditor/ckeditor5-cloud-services';import{IconExportPdf as _0x1a56c2}from'@ckeditor/ckeditor5-icons';function u(_0x10f710,_0x3dd4a1){const t=_0x10f710['t'];switch(_0x3dd4a1){case'Export\x20to\x20PDF':return t('Export\x20to\x20PDF');case'An\x20error\x20occurred\x20while\x20generating\x20the\x20PDF.':return t('An\x20error\x20occurred\x20while\x20generating\x20the\x20PDF.');case'PDF\x20export\x20started':return t('PDF\x20export\x20started');case'PDF\x20export\x20failed':return t('PDF\x20export\x20failed');case'PDF\x20export\x20successful':return t('PDF\x20export\x20successful');case'Exporting\x20PDF\x20document':return t('Exporting\x20PDF\x20document');default:return _0x3dd4a1;}}var l=class extends _0x2e54a3{constructor(_0x953e47){super(_0x953e47),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}execute(_0x10b50b={}){const {editor:_0x2ee0f1}=this,_0x16dbb8=_0x10b50b['version']||_0x2ee0f1['config']['get']('exportPdf.version'),_0x2f1dac=_0x10b50b['converterUrl']||function(_0x256739){return 0x2===_0x256739?'https://pdf-converter.cke-cs.com/v2/convert/html-pdf':'https://pdf-converter.cke-cs.com/v1/convert/';}(_0x16dbb8),_0x10a47a=_0x10b50b['dataCallback']||(_0x3ca8c4=>_0x3ca8c4['data']['get']()),_0x15de1a=_0x2ee0f1['plugins']['get']('ExportPdf'),_0x8818b7=_0x10b50b['token']||_0x15de1a['_token'];return this['isBusy']=!0x0,this['refresh'](),_0x4582ee(_0x10b50b['stylesheets']||['EDITOR_STYLES'])['then'](async _0x425bbb=>{if(_0x2ee0f1['ui']['ariaLiveAnnouncer']['announce'](u(_0x2ee0f1['locale'],'PDF\x20export\x20started')),_0x2ee0f1['plugins']['has']('MergeFields')){_0x10b50b['converterOptions']||(_0x10b50b['converterOptions']={});const _0x212bc0=_0x2ee0f1['plugins']['get']('MergeFieldsEditing'),_0x36c1b4=_0x212bc0['previewMode'],{prefix:_0x21d2c0,suffix:_0x1cffb5}=_0x2ee0f1['config']['get']('mergeFields'),_0xc47f0a='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x328a85={'prefix':_0x21d2c0,'suffix':_0x1cffb5,'data':{}};if('$labels'===_0x36c1b4){for(const _0x26418b of _0x212bc0['getMergeFieldsIds']())'image'===_0x212bc0['getMergeFieldType'](_0x26418b)?_0x328a85['data'][_0x26418b]=_0xc47f0a:_0x328a85['data'][_0x26418b]=_0x212bc0['wrapInAffixes'](_0x212bc0['getLabel'](_0x26418b)||_0x26418b);}else{const _0x5be0e6='$defaultValues'===_0x36c1b4?_0x212bc0['getDefaultValues']():_0x212bc0['getDataSetValues'](_0x36c1b4,!0x0);for(const _0x152c45 of Object['entries'](_0x5be0e6)){const [_0x18f0a7,_0x2c1f5a]=_0x152c45;'image'===_0x212bc0['getMergeFieldType'](_0x18f0a7)?_0x328a85['data'][_0x18f0a7]=null!==_0x2c1f5a?_0x2c1f5a:_0xc47f0a:_0x328a85['data'][_0x18f0a7]=null!==_0x2c1f5a?_0x2c1f5a:_0x212bc0['getLabel'](_0x18f0a7)||_0x18f0a7;}}_0x10b50b['converterOptions']['merge_fields']=_0x328a85;}const _0x3f7d13=0x2===_0x16dbb8?function(_0x12cf29){const _0x2b36b6=_0x12cf29?.['document']?.['margins'];return m({'pageWidth':p(_0x12cf29?.['document']?.['size']||'A4'),'marginLeft':_0x2b36b6?.['left'],'marginRight':_0x2b36b6?.['right']});}(_0x10b50b['converterOptions']):(_0x2e00d5=_0x10b50b['converterOptions'],m({'pageWidth':p(_0x2e00d5?.['format']||'A4'),'marginLeft':_0x2e00d5?.['margin_left'],'marginRight':_0x2e00d5?.['margin_right']}));var _0x2e00d5;const _0x1a374b={'html':('\x0a\x09\x09\x09\x09\x09<!DOCTYPE\x20html>\x0a\x09\x09\x09\x09\x09<html>\x0a\x09\x09\x09\x09\x09\x09<head>\x0a\x09\x09\x09\x09\x09\x09\x09<title>CKEditor\x205\x20PDF\x20document</title>\x0a\x09\x09\x09\x09\x09\x09\x09<meta\x20charset=\x22utf-8\x22>\x0a\x09\x09\x09\x09\x09\x09</head>\x0a\x09\x09\x09\x09\x09\x09<body>\x0a\x09\x09\x09\x09\x09\x09\x09<div\x20class=\x22ck-content\x22\x20dir=\x22'+_0x2ee0f1['locale']['contentLanguageDirection']+'\x22\x20style=\x22'+_0x3f7d13+'\x22>\x0a\x09\x09\x09\x09\x09\x09\x09\x09'+await _0x10a47a(_0x2ee0f1)+'\x0a\x09\x09\x09\x09\x09\x09\x09</div>\x0a\x09\x09\x09\x09\x09\x09</body>\x0a\x09\x09\x09\x09\x09</html>\x0a\x09\x09\x09\x09')['trim'](),'css':_0x425bbb,[0x2===_0x16dbb8?'config':'options']:_0x10b50b['converterOptions']},_0x46fb5d={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/pdf',..._0x8818b7?{'Authorization':_0x8818b7['value']}:null,'x-cs-app-id':_0x10b50b['appID']||'cke5'},'body':JSON['stringify'](_0x1a374b)};return window['fetch'](_0x2f1dac,_0x46fb5d)['then'](_0x5d765b=>{if(0xc8!==_0x5d765b['status'])throw _0x5d765b;return _0x5d765b['blob']();})['then'](_0x4261ae=>{_0x2ee0f1['ui']['ariaLiveAnnouncer']['announce'](u(_0x2ee0f1['locale'],'PDF\x20export\x20successful'));const _0x436918='function'==typeof _0x10b50b['fileName']?_0x10b50b['fileName']():_0x10b50b['fileName'];this['_downloadFile'](_0x4261ae,_0x436918||'document.pdf');});})['catch'](_0x362124=>{const _0x9750a4=_0x2ee0f1['plugins']['get']('Notification');throw _0x2ee0f1['ui']['ariaLiveAnnouncer']['announce'](u(_0x2ee0f1['locale'],'PDF\x20export\x20failed'),{'politeness':'assertive'}),_0x9750a4['showWarning'](u(_0x2ee0f1['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20PDF.')),_0x362124;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0x17fe4e,_0x5e4d2b){const _0xe7f43c=document['createElement']('a');_0xe7f43c['href']=window['URL']['createObjectURL'](_0x17fe4e),_0xe7f43c['download']=_0x5e4d2b,_0xe7f43c['click'](),_0xe7f43c['remove']();}};function m({pageWidth:_0x79fa8b,marginLeft:_0xc2ac97,marginRight:_0x1372e5}){return'width:calc('+[_0x79fa8b,_0xc2ac97,_0x1372e5]['filter'](Boolean)['join']('\x20-\x20')+');';}function p(_0x1abd06){return'object'==typeof _0x1abd06&&'width'in _0x1abd06?_0x1abd06['width']:{'letter':['21.6cm','27.9cm'],'legal':['21.6cm','35.6cm'],'tabloid':['27.9cm','43.2cm'],'ledger':['43.2cm','27.9cm'],'a0':['84.1cm','118.9cm'],'a1':['59.4cm','84.1cm'],'a2':['42.0cm','59.4cm'],'a3':['29.7cm','42.0cm'],'a4':['21.0cm','29.7cm'],'a5':['14.8cm','21.0cm'],'a6':['10.5cm','14.8cm']}[_0x1abd06['toLowerCase']()][0x0];}var f=class extends _0x5d1c32{static get['pluginName'](){return'ExportPdfUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}init(){const _0x2f5d0a=this['editor'];_0x2f5d0a['ui']['componentFactory']['add']('exportPdf',()=>{const _0x2c8122=this['_createButton'](_0x26713a),_0x1a4e18=_0x2f5d0a['commands']['get']('exportPdf');return _0x2c8122['set']({'tooltip':!0x0}),_0x2c8122['bind']('isOn')['to'](_0x1a4e18,'isBusy'),_0x2c8122;}),_0x2f5d0a['ui']['componentFactory']['add']('menuBar:exportPdf',()=>this['_createButton'](_0x401b6f));}_createButton(_0x33b1cb){const _0x4746b6=this['editor'],_0x4fea97=_0x4746b6['config']['get']('exportPdf'),_0xd9ba2a=_0x4746b6['commands']['get']('exportPdf'),_0x3bd3b7=new _0x33b1cb(_0x4746b6['locale']),_0x3f00a8=new _0x24a5a6();return _0x3bd3b7['children']['add'](_0x3f00a8),_0x3f00a8['bind']('isVisible')['to'](_0xd9ba2a,'isBusy'),_0x3bd3b7['iconView']['bind']('isVisible')['to'](_0xd9ba2a,'isBusy',_0x3703a0=>!_0x3703a0),_0x3bd3b7['set']({'icon':_0x1a56c2}),_0x3bd3b7['bind']('isEnabled')['to'](_0xd9ba2a,'isEnabled'),_0x3bd3b7['bind']('label')['to'](_0xd9ba2a,'isBusy',_0x5c11f2=>u(_0x4746b6['locale'],_0x5c11f2?'Exporting\x20PDF\x20document':'Export\x20to\x20PDF')),this['listenTo'](_0x3bd3b7,'execute',()=>{_0x4746b6['execute']('exportPdf',_0x4fea97),_0x4746b6['editing']['view']['focus']();}),_0x3bd3b7;}},h=class extends _0x5d1c32{_token;static get['pluginName'](){return'ExportPdf';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get requires(){return[_0x30ec22,_0x33b3a9,f];}init(){const {editor:_0x19d55e}=this;_0x19d55e['config']['define']('exportPdf.version',0x2),_0x19d55e['commands']['add']('exportPdf',new l(_0x19d55e));const _0x296b22=_0x19d55e['plugins']['get'](_0x30ec22),_0x28d17f=_0x19d55e['config']['get']('exportPdf');!0x1===_0x28d17f['tokenUrl']?this['_token']=null:_0x28d17f['tokenUrl']?_0x296b22['registerTokenUrl'](_0x28d17f['tokenUrl'])['then'](_0x41dc42=>{this['_token']=_0x41dc42;}):this['_token']=_0x296b22['token'];}};export{h as ExportPdf,l as ExportPdfCommand};