From df7e9fccdd7a2083b22e1b1988379bbaf0a5a5e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jun 2018 19:12:18 +0200 Subject: [PATCH 1/4] Autofill alias --- htdocs/website/index.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 89528c10b91..8d8a7bfea36 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -2076,14 +2076,14 @@ if ($action == 'editmeta' || $action == 'createcontainer') print ''; print $langs->trans('WEBSITE_TITLE'); print ''; - print ''; + print ''; print ''; // Alias print ''; print $langs->trans('WEBSITE_PAGENAME'); print ''; - print ''; + print ''; print ''; print ''; @@ -2138,7 +2138,6 @@ if ($action == 'editmeta' || $action == 'createcontainer') print ''; print ''; - if ($action == 'createcontainer') { print '
'; @@ -2149,7 +2148,26 @@ if ($action == 'editmeta' || $action == 'createcontainer') print '
'; } - + if ($action == 'createcontainer') + { + print ''; + } //print ''; //dol_fiche_end(); From 54fc711a6b1bb164b7d68b3269a20d97ac846160 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jun 2018 20:22:58 +0200 Subject: [PATCH 2/4] Add tool --- scripts/invoices/facturex-pdfextractxml.py | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 scripts/invoices/facturex-pdfextractxml.py diff --git a/scripts/invoices/facturex-pdfextractxml.py b/scripts/invoices/facturex-pdfextractxml.py new file mode 100755 index 00000000000..fe1e96ccadd --- /dev/null +++ b/scripts/invoices/facturex-pdfextractxml.py @@ -0,0 +1,97 @@ +#! /usr/bin/python +# -*- coding: utf-8 -*- +# © 2017 Alexis de Lattre + +from optparse import OptionParser +import sys +from facturx import get_facturx_xml_from_pdf +from facturx.facturx import logger +import logging +from os.path import isfile, isdir + +__author__ = "Alexis de Lattre " +__date__ = "August 2017" +__version__ = "0.1" + +options = [ + {'names': ('-l', '--log-level'), 'dest': 'log_level', + 'action': 'store', 'default': 'info', + 'help': "Set log level. Possible values: debug, info, warn, error. " + "Default value: info."}, + {'names': ('-d', '--disable-xsd-check'), 'dest': 'disable_xsd_check', + 'action': 'store_true', 'default': False, + 'help': "De-activate XML Schema Definition check on Factur-X XML file " + "(the check is enabled by default)"}, + ] + + +def main(options, arguments): + if options.log_level: + log_level = options.log_level.lower() + log_map = { + 'debug': logging.DEBUG, + 'info': logging.INFO, + 'warn': logging.WARN, + 'error': logging.ERROR, + } + if log_level in log_map: + logger.setLevel(log_map[log_level]) + else: + logger.error( + 'Wrong value for log level (%s). Possible values: %s', + log_level, ', '.join(log_map.keys())) + sys.exit(1) + + if len(arguments) != 2: + logger.error( + 'This command requires 2 arguments (%d used). ' + 'Use --help to get the details.', len(arguments)) + sys.exit(1) + pdf_filename = arguments[0] + out_xml_filename = arguments[1] + if not isfile(pdf_filename): + logger.error('Argument %s is not a filename', pdf_filename) + sys.exit(1) + if isdir(out_xml_filename): + logger.error( + '2nd argument %s is a directory name (should be a the ' + 'output XML filename)', out_xml_filename) + sys.exit(1) + pdf_file = open(pdf_filename) + check_xsd = True + if options.disable_xsd_check: + check_xsd = False + # The important line of code is below ! + try: + (xml_filename, xml_string) = get_facturx_xml_from_pdf( + pdf_file, check_xsd=check_xsd) + except Exception as e: + logger.error(e) + sys.exit(1) + if xml_filename and xml_string: + if isfile(out_xml_filename): + logger.warn( + 'File %s already exists. Overwriting it!', out_xml_filename) + xml_file = open(out_xml_filename, 'w') + xml_file.write(xml_string) + xml_file.close() + logger.info('File %s generated', out_xml_filename) + else: + logger.warn('File %s has not been created', out_xml_filename) + sys.exit(1) + + +if __name__ == '__main__': + usage = "Usage: facturx-pdfextractxml " + epilog = "Author: %s\n\nVersion: %s" % (__author__, __version__) + description = "This extracts the XML file from a Factur-X invoice." + parser = OptionParser(usage=usage, epilog=epilog, description=description) + for option in options: + param = option['names'] + del option['names'] + parser.add_option(*param, **option) + options, arguments = parser.parse_args() + sys.argv[:] = arguments + main(options, arguments) + + \ No newline at end of file From 8142a672a70f754724e56f3f6bf7bee2724f51e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jun 2018 21:12:30 +0200 Subject: [PATCH 3/4] PDF compatibility. Use hidden option to force PDF1/A instead of PDF-1.3 --- htdocs/core/lib/pdf.lib.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index b0cda2ecd6a..30d6b82bb21 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -129,8 +129,11 @@ function pdf_getInstance($format='',$metric='mm',$pagetype='P') //$format=array($arrayformat['width'],$arrayformat['height']); //$metric=$arrayformat['unit']; - if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format); - else $pdf = new TCPDF($pagetype,$metric,$format); + $pdfa=false; // PDF-1.3 + if (! empty($conf->global->PDF_USE_1A)) $pdfa=true; // PDF1/A + + if (class_exists('TCPDI')) $pdf = new TCPDI($pagetype,$metric,$format,true,'UTF-8',false,$pdfa); + else $pdf = new TCPDF($pagetype,$metric,$format,true,'UTF-8',false,$pdfa); // Protection and encryption of pdf if (! empty($conf->global->PDF_SECURITY_ENCRYPTION)) From fb8dd2f32b6b06044a0350195a689245dc22b333 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Jun 2018 09:37:26 +0200 Subject: [PATCH 4/4] FIX TCPDF is generated PDF 1.7 but TCPDI was setting version to 1.3 --- htdocs/includes/tcpdi/tcpdi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/includes/tcpdi/tcpdi.php b/htdocs/includes/tcpdi/tcpdi.php index 999ff99ea5b..675e2226b4a 100644 --- a/htdocs/includes/tcpdi/tcpdi.php +++ b/htdocs/includes/tcpdi/tcpdi.php @@ -135,7 +135,7 @@ class TCPDI extends FPDF_TPL { * * @return string */ - function setPDFVersion($version = '1.3') { + function setPDFVersion($version = '1.7') { $this->PDFVersion = $version; }