@ckeditor/ckeditor5-export-pdf
Version:
Export to PDF feature for CKEditor 5.
23 lines • 9.46 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 _0x4e8a71,Plugin as _0x2b6414}from'@ckeditor/ckeditor5-core/dist/index.js';import{collectStylesheets as _0xca0b12}from'@ckeditor/ckeditor5-utils/dist/index.js';import{ButtonView as _0x66d570,MenuBarMenuListItemButtonView as _0x56bb0a,SpinnerView as _0x36c2b7,Notification as _0x5c5b5c}from'@ckeditor/ckeditor5-ui/dist/index.js';import{IconExportPdf as _0x1284c7}from'@ckeditor/ckeditor5-icons/dist/index.js';function s(_0x55371e,_0x5521d2){const t=_0x55371e['t'];switch(_0x5521d2){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 _0x5521d2;}}class e extends _0x4e8a71{constructor(_0x36c6c2){super(_0x36c6c2),this['set']('isBusy',!0x1),this['affectsData']=!0x1;}['refresh'](){this['isEnabled']=!this['isBusy'],this['value']=this['isBusy']?'pending':void 0x0;}['execute'](_0x52e030={}){const _0x5e50a7=this['editor'],_0x4fe219=_0x52e030['converterUrl']||'https://pdf-converter.cke-cs.com/v1/convert/',_0x1d0c66=_0x52e030['dataCallback']||(_0x5938f9=>_0x5938f9['data']['get']()),_0x1b916c=_0x5e50a7['plugins']['get']('ExportPdf'),_0x333922=_0x52e030['token']||_0x1b916c['_token'];return this['isBusy']=!0x0,this['refresh'](),_0xca0b12(_0x52e030['stylesheets']||['EDITOR_STYLES'])['then'](async _0x34849b=>{if(_0x5e50a7['ui']['ariaLiveAnnouncer']['announce'](s(_0x5e50a7['locale'],'PDF\x20export\x20started')),_0x5e50a7['plugins']['has']('MergeFields')){_0x52e030['converterOptions']||(_0x52e030['converterOptions']={});const _0x19707e=_0x5e50a7['plugins']['get']('MergeFieldsEditing'),_0x3a23e6=_0x19707e['previewMode'],{prefix:_0x4075a5,suffix:_0x3c5163}=_0x5e50a7['config']['get']('mergeFields'),_0x369fee='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP88B8AAuUB8e2ujYwAAAAASUVORK5CYII=',_0x1511fc={'prefix':_0x4075a5,'suffix':_0x3c5163,'data':{}};if('$labels'===_0x3a23e6){for(const _0x2762f4 of _0x19707e['getMergeFieldsIds']())'image'===_0x19707e['getMergeFieldType'](_0x2762f4)?_0x1511fc['data'][_0x2762f4]=_0x369fee:_0x1511fc['data'][_0x2762f4]=_0x19707e['wrapInAffixes'](_0x19707e['getLabel'](_0x2762f4)||_0x2762f4);}else{const _0x2bb7d5='$defaultValues'===_0x3a23e6?_0x19707e['getDefaultValues']():_0x19707e['getDataSetValues'](_0x3a23e6,!0x0);for(const _0x540715 of Object['entries'](_0x2bb7d5)){const [_0x571d64,_0x49e94b]=_0x540715;'image'===_0x19707e['getMergeFieldType'](_0x571d64)?_0x1511fc['data'][_0x571d64]=null!==_0x49e94b?_0x49e94b:_0x369fee:_0x1511fc['data'][_0x571d64]=null!==_0x49e94b?_0x49e94b:_0x19707e['getLabel'](_0x571d64)||_0x571d64;}}_0x52e030['converterOptions']['merge_fields']=_0x1511fc;}const _0x5ba53e=0x2===_0x52e030['version']?function(_0xfc0dee){const _0x3de04a=_0xfc0dee?.['document']?.['margins'];return a({'pageWidth':m(_0xfc0dee?.['document']?.['size']||'A4'),'marginLeft':_0x3de04a?.['left'],'marginRight':_0x3de04a?.['right']});}(_0x52e030['converterOptions']):(_0x2dce9a=_0x52e030['converterOptions'],a({'pageWidth':m(_0x2dce9a?.['format']||'A4'),'marginLeft':_0x2dce9a?.['margin_left'],'marginRight':_0x2dce9a?.['margin_right']}));var _0x2dce9a;const _0x3f99ac={'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'+_0x5e50a7['locale']['contentLanguageDirection']+'\x22\x20style=\x22'+_0x5ba53e+'\x22>\x0a\x09\x09\x09\x09\x09\x09\x09\x09'+await _0x1d0c66(_0x5e50a7)+'\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':_0x34849b,[0x2===_0x52e030['version']?'config':'options']:_0x52e030['converterOptions']},_0x2e5629={'method':'POST','headers':{'Content-Type':'application/json','Accept':'application/pdf',..._0x333922?{'Authorization':_0x333922['value']}:null,'x-cs-app-id':_0x52e030['appID']||'cke5'},'body':JSON['stringify'](_0x3f99ac)};return window['fetch'](_0x4fe219,_0x2e5629)['then'](_0x39efe8=>{if(0xc8!==_0x39efe8['status'])throw _0x39efe8;return _0x39efe8['blob']();})['then'](_0x1042bf=>{_0x5e50a7['ui']['ariaLiveAnnouncer']['announce'](s(_0x5e50a7['locale'],'PDF\x20export\x20successful'));const _0x20752d='function'==typeof _0x52e030['fileName']?_0x52e030['fileName']():_0x52e030['fileName'];this['_downloadFile'](_0x1042bf,_0x20752d||'document.pdf');});})['catch'](_0x2ebc65=>{const _0x30d7fb=_0x5e50a7['plugins']['get']('Notification');throw _0x5e50a7['ui']['ariaLiveAnnouncer']['announce'](s(_0x5e50a7['locale'],'PDF\x20export\x20failed'),{'politeness':'assertive'}),_0x30d7fb['showWarning'](s(_0x5e50a7['locale'],'An\x20error\x20occurred\x20while\x20generating\x20the\x20PDF.')),_0x2ebc65;})['finally'](()=>{this['isBusy']=!0x1,this['refresh']();});}['_downloadFile'](_0xc8e6e8,_0x2f0ec6){const _0xc238ee=document['createElement']('a');_0xc238ee['href']=window['URL']['createObjectURL'](_0xc8e6e8),_0xc238ee['download']=_0x2f0ec6,_0xc238ee['click'](),_0xc238ee['remove']();}}function a({pageWidth:_0x161abf,marginLeft:_0x2b0027,marginRight:_0x2f7ca8}){return'width:calc('+[_0x161abf,_0x2b0027,_0x2f7ca8]['filter'](Boolean)['join']('\x20-\x20')+');';}function m(_0x5c0ac6){if('object'==typeof _0x5c0ac6&&'width'in _0x5c0ac6)return _0x5c0ac6['width'];return{'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']}[_0x5c0ac6['toLowerCase']()][0x0];}class o extends _0x2b6414{static get['pluginName'](){return'ExportPdfUI';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}['init'](){const _0x33315e=this['editor'];_0x33315e['ui']['componentFactory']['add']('exportPdf',()=>{const _0xe9635c=this['_createButton'](_0x66d570),_0x51b6ed=_0x33315e['commands']['get']('exportPdf');return _0xe9635c['set']({'tooltip':!0x0}),_0xe9635c['bind']('isOn')['to'](_0x51b6ed,'isBusy'),_0xe9635c;}),_0x33315e['ui']['componentFactory']['add']('menuBar:exportPdf',()=>this['_createButton'](_0x56bb0a));}['_createButton'](_0x1c5fa1){const _0x360eaa=this['editor'],_0x328919=_0x360eaa['config']['get']('exportPdf')||{},_0x15b607=_0x360eaa['commands']['get']('exportPdf'),_0x56eb46=new _0x1c5fa1(_0x360eaa['locale']),_0x213f22=new _0x36c2b7();return _0x56eb46['children']['add'](_0x213f22),_0x213f22['bind']('isVisible')['to'](_0x15b607,'isBusy'),_0x56eb46['iconView']['bind']('isVisible')['to'](_0x15b607,'isBusy',_0x518efb=>!_0x518efb),_0x56eb46['set']({'icon':_0x1284c7}),_0x56eb46['bind']('isEnabled')['to'](_0x15b607,'isEnabled'),_0x56eb46['bind']('label')['to'](_0x15b607,'isBusy',_0x208d41=>s(_0x360eaa['locale'],_0x208d41?'Exporting\x20PDF\x20document':'Export\x20to\x20PDF')),this['listenTo'](_0x56eb46,'execute',()=>{_0x360eaa['execute']('exportPdf',_0x328919),_0x360eaa['editing']['view']['focus']();}),_0x56eb46;}}class l extends _0x2b6414{['_token'];static get['pluginName'](){return'ExportPdf';}static get['isOfficialPlugin'](){return!0x0;}static get['isPremiumPlugin'](){return!0x0;}static get['requires'](){return['CloudServices',_0x5c5b5c,o];}['init'](){const _0x1a6ecb=this['editor'],_0x4b0e24=_0x1a6ecb['config']['get']('exportPdf')||{};_0x1a6ecb['commands']['add']('exportPdf',new e(_0x1a6ecb));const _0x252a8d=_0x1a6ecb['plugins']['get']('CloudServices');!0x1===_0x4b0e24['tokenUrl']?this['_token']=null:_0x4b0e24['tokenUrl']?_0x252a8d['registerTokenUrl'](_0x4b0e24['tokenUrl'])['then'](_0x175dcb=>{this['_token']=_0x175dcb;}):this['_token']=_0x252a8d['token'];}}export{l as ExportPdf,e as ExportPdfCommand};