1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-22 13:26:38 +01:00

Sostituzione di ViewerJS con PDFJS

Sostituzione di ViewerJS con PDFJS e bugfix.
This commit is contained in:
Thomas Zilio 2017-12-30 14:13:11 +01:00
parent 655532c241
commit 90efc32121
7 changed files with 53 additions and 21 deletions

View File

@ -27,6 +27,8 @@ $rootdir = str_replace('%2F', '/', rawurlencode($rootdir));
define('DOCROOT', $docroot);
define('ROOTDIR', $rootdir);
$pdfjs = '../../../..';
// Caricamento delle dipendenze e delle librerie del progetto
require_once __DIR__.'/vendor/autoload.php';

View File

@ -178,7 +178,6 @@ gulp.task('srcFonts', function () {
.pipe(gulp.dest(config.production + '/' + config.paths.fonts));
});
gulp.task('ckeditor', function () {
gulp.src([
config.main.bowerDirectory + '/ckeditor/{adapters,lang,skins,plugins}/**/*.{js,json,css,png}',
@ -207,12 +206,20 @@ gulp.task('chartjs', function () {
.pipe(gulp.dest(config.production + '/' + config.paths.js + '/chartjs'));
});
gulp.task('viewerjs', function () {
gulp.task('pdfjs', function () {
gulp.src([
config.main.bowerDirectory + '/ViewerJS_release/ViewerJS/**/*',
'!' + config.main.bowerDirectory + '/ViewerJS_release/ViewerJS/example.local.css',
config.main.bowerDirectory + '/pdfjs/web/*',
'!' + config.main.bowerDirectory + '/pdfjs/web/cmaps/',
'!' + config.main.bowerDirectory + '/pdfjs/web/*.map',
'!' + config.main.bowerDirectory + '/pdfjs/web/*.pdf',
])
.pipe(gulp.dest(config.production + '/viewerjs'));
.pipe(gulp.dest(config.production + '/pdfjs/web'));
gulp.src([
config.main.bowerDirectory + '/pdfjs/build/*',
'!' + config.main.bowerDirectory + '/pdfjs/build/*.map',
])
.pipe(gulp.dest(config.production + '/pdfjs/build'));
});
// Elaborazione e minificazione delle informazioni sull'internazionalizzazione
@ -351,7 +358,7 @@ gulp.task('other', ['clean'], function () {
gulp.start('colorpicker');
gulp.start('i18n');
gulp.start('viewerjs');
gulp.start('pdfjs');
gulp.start('chartjs');
gulp.start('php-debugbar');

View File

@ -20,12 +20,9 @@ if (get('anteprima') !== null) {
// Gestione della stampa
$rapportino_nome = sanitizeFilename('Rapportino'.$rs[0]['codice'].'.pdf');
$filename = $docroot.'/files/interventi/'.$rapportino_nome;
$id_print = Prints::getModuleMainPrint($id_record)['id'];
$_GET['idintervento'] = $id_record; // Fix temporaneo per la stampa
$idintervento = $id_record; // Fix temporaneo per la stampa
$ptype = 'interventi';
require $docroot.'/pdfgen.php';
Prints::render($id_print, $id_record, $filename);
// HTML per la visualizzazione
echo '
@ -37,7 +34,7 @@ if (get('anteprima') !== null) {
echo '<div class="hide" id="pdf">';
if (isMobile()) {
echo '<iframe src="'.$rootdir.'/assets/dist/viewerjs/#'.$rootdir.'/files/interventi/'.$rapportino_nome.'" allowfullscreen="" webkitallowfullscreen="" width="100%" height="550" ></iframe>';
echo '<iframe src="'.$rootdir.'/assets/dist/pdfjs/web/viewer.html?file='.$pdfjs.'/files/interventi/'.$rapportino_nome.'" allowfullscreen="" webkitallowfullscreen="" width="100%" height="550" ></iframe>';
} else {
echo '<object data="'.$rootdir.'/files/interventi/'.$rapportino_nome.'#view=fitH&scrollbar=0&toolbar=0&navpanes=0" id ="rapportino_pdf" type="application/pdf" width="100%">
alt : <a href="'.$rootdir.'/files/interventi/'.$rapportino_nome.'" target="_blank">'.$rapportino_nome.'</a>

View File

@ -30,7 +30,6 @@
},
"main": "gulpfile.js",
"dependencies": {
"ViewerJS_release": "git://github.com/kogmbh/ViewerJS_release.git",
"admin-lte": "~2.3.11",
"autosize": "^3.0.21",
"bootstrap": "^3.3.7",
@ -55,6 +54,8 @@
"moment": "^2.18.1",
"numeral": "^2.0.6",
"parsleyjs": "^2.7.2",
"pdf": "git://github.com/mozilla/pdf.js#gh-pages",
"pdfjs": "git://github.com/mozilla/pdf.js#gh-pages",
"select2": "4.0.3",
"select2-bootstrap-theme": "^0.1.0-beta.10",
"signature_pad": "^2.1.1",

View File

@ -70,7 +70,7 @@ class Prints
*/
public static function getModulePrints($module)
{
$module_id = Modules::getModule($module)['id'];
$module_id = Modules::get($module)['id'];
self::getPrints();
@ -83,6 +83,26 @@ class Prints
return $result;
}
/**
* Restituisce le informazioni relative alle stampe di un singolo modulo specificato.
*
* @param string|int $module
*
* @return array
*/
public static function getModuleMainPrint($module)
{
$prints = self::getModulePrints($module);
$main = array_search(1, array_column($prints, 'main'));
if ($main !== false) {
return $prints[$main];
}
return false;
}
public static function render($print, $id_record, $filename = null)
{
ob_end_clean();
@ -176,6 +196,11 @@ class Prints
$report = str_replace('$body_table_params$', $body_table_params, $report);
$report = str_replace('$table$', $table, $report);
// Footer di default
if (!str_contains($report, '<page_footer>')) {
$report .= '<page_footer>$default_footer$</page_footer>';
}
// Operazioni di sostituzione
include DOCROOT.'/templates/replace.php';
@ -184,11 +209,6 @@ class Prints
$filename = !empty($filename) ? $filename : sanitizeFilename($report_name);
$title = basename($filename);
// Footer di default
if (!str_contains($report, '<page_footer>')) {
$report .= '<page_footer>$default_footer$</page_footer>';
}
$html2pdf = new Spipu\Html2Pdf\Html2Pdf($orientation, 'A4', 'it', true, 'UTF-8');
$html2pdf->writeHTML($report);
@ -331,7 +351,6 @@ class Prints
// Impostazione del font-size
$mpdf->WriteHTML('body {font-size: '.$settings['font-size'].'pt;}', 1);
$mpdf->shrink_tables_to_fit = 1;
// Aggiunta dei contenuti
$mpdf->WriteHTML($report);

View File

@ -2,7 +2,7 @@
include_once __DIR__.'/../../core.php';
$module = Modules::getModule('Interventi');
$module = Modules::get('Interventi');
$id_module = $module['id'];
$total = Modules::getQuery($id_module);

View File

@ -35,6 +35,12 @@ $files = [
'templates/riepilogo_contratti/contratto.html',
'templates/riepilogo_contratti/pdfgen.riepilogo_contratti.php',
'templates/riepilogo_contratti/logo_azienda.jpg',
'assets/dist/viewerjs',
'assets/dist/js/adapters',
'assets/dist/js/lang',
'assets/dist/js/skins',
'assets/dist/js/ckeditor.js',
'assets/dist/js/styles.js',
];
foreach ($files as $key => $value) {