コード例 #1
0
def datasource_postgresql_sample(
        jrxml_filename='./jrxml/datasource_postgresql.jrxml',
        output_filename='./output/datasource_postgresql.pdf'):
    """
    PostgreSQL data source sample.
    WARNING:Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/postgresql' to create and populated database tables.

    CAUTION: Edit values of 'host' and 'port' to those in your environment.
     """
    logger.info('running datasource postgresql sample')
    # jrxml_filename = './jrxml/datasource_postgresql.jrxml'  # input jrxml filename
    # output_filename = './output/datasource_postgresql.pdf'  # output pdf filename

    # Postgresql datasource
    config = {
        "adapter":
        "postgres",
        "config":
        "host='172.18.0.4' port='5432'"
        " dbname='agatereports' user='******' password='******'"
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #2
0
def blank_when_null_sample(jrxml_filename='./jrxml/blank_when_null.jrxml',
                           output_filename='./output/blank_when_null.pdf'):
    """
    Blank when null sample.
    When 'Blank When NULL' is checked on a TextField properties, no value will be displayed when the value is None.
    Otherwise, string 'None' will be displayed.

    In this sample, columns 'street' and column 'city' in the first row is None.
    Also, in the report layout, column 'street' is NOT set to 'Blank when Null' while column 'city' is set.
    As such, 'None' is displayed in column 'street' in the first row while column 'city' is blank in the first row.

    WARNING: Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/mysql' to create and populated database tables.

    CAUTION: Edit values of 'host' and 'port' to those in your environment.
     """
    logger.info('running blank when null sample')
    # jrxml_filename = './jrxml/blank_when_null.jrxml'  # input jrxml filename
    # output_filename = './output/blank_when_null.pdf'  # output pdf filename

    # MySQL datasource
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'port': '3306',
        'user': '******',
        'password': '******',
        'database': 'agatereports'
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #3
0
def datasource_mysql_sample(jrxml_filename='./jrxml/datasource_mysql.jrxml',
                            output_filename='./output/datasource_mysql.pdf'):
    """
    MySQL data source sample.

    WARNING: Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/mysql' to create and populated database tables.

    CAUTION: Edit values of 'host' and 'port' to those in your environment.
     """
    logger.info('running datasource mysql sample')
    # jrxml_filename = './jrxml/datasource_mysql.jrxml'  # input jrxml filename
    # output_filename = './output/datasource_mysql.pdf'  # output pdf filename

    # MySQL datasource
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'port': '3306',
        'user': '******',
        'password': '******',
        'database': 'agatereports'
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #4
0
def variables_system_sample(jrxml_filename='./jrxml/variables_system.jrxml',
                            output_filename='./output/variables_system.pdf'):
    """
    Displaying variables such as row number and page number that are supported by the engine.

    WARNING: Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/mysql' to create and populated database tables.

    CAUTION: Edit values of 'host' and 'port' to those in your environment.

    'PAGE_NUMBER': current page number in the report
    'REPORT_COUNT': current row number in the data source
    'PAGE_COUNT': current row number of the data source in a page
     """
    logger.info('running variables system sample')
    # jrxml_filename = './jrxml/variables_system.jrxml'  # input jrxml filename
    # output_filename = './output/variables_system.pdf'  # output pdf filename

    # MySQL datasource
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'port': '3306',
        'user': '******',
        'password': '******',
        'database': 'agatereports'
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #5
0
def number_formatting_sample(jrxml_filename='./jrxml/number_formatting.jrxml',
                             output_filename='./output/number_formatting.pdf'):
    """
    Jaspersoft Studio is a Java application that uses Java classes and format patterns. However, AgateReports is a
    Python application and uses Python classes and format patterns instead. That is, Python number formats such as
    '{:,}' and '{:.2f}' are used to format a number.
    Reference:
    https://docs.python.org/3.6/library/string.html

    WARNING: Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/mysql' to create and populated database tables.

    CAUTION: Edit values of 'host' and 'port' to those in your environment.
     """
    logger.info('running number formatting sample')
    # jrxml_filename = './jrxml/number_formatting.jrxml'  # input jrxml filename
    # output_filename = './output/number_formatting.pdf'  # output pdf filename

    # MySQL datasource
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'port': '3306',
        'user': '******',
        'password': '******',
        'database': 'agatereports'
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #6
0
def dates_sample(jrxml_filename='./jrxml/dates.jrxml',
                 output_filename='./output/dates.pdf'):
    """
    Dates sample.
    WARNING: This sample uses MySQL database.
    Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/mysql' to create and populated database tables.

    Jaspersoft Studio is a Java application and uses Java classes and formats. It is necessary instead to use
    Python classes and formats in AgateReports.
    For example, today's date is retrieved using 'datetime.datetime.now()' instead of 'new java.util.Date()'
    Date/time format is specified using Python strftime formats. e.g. %Y-%m-%d
     """
    logger.info('running dates sample')
    # jrxml_filename = './jrxml/dates.jrxml'  # input jrxml filename
    # output_filename = './output/dates.pdf'  # output pdf filename

    # MySQL datasource
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'user': '******',
        'password': '******',
        'database': 'agatereports'
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #7
0
def image_database_blob_postgresql_sample(
        jrxml_filename='./jrxml/image_database_blob.jrxml',
        output_filename='./output/image_database_blob_postgresql.pdf'):
    """
    Display an image saved as a blob in a postgresql database table column.

    WARNING: Before running this sample, database table 'pictures' must be create and populated.
    Run Python scripts in directory 'agatereports/tests/database/postgresql/create_pictures.py ' to create and
    populated database table.
    """
    logger.info('running image database blob sample')
    # jrxml_filename = './jrxml/image_database_blob.jrxml'  # input jrxml filename
    # output_filename = './output/image_database_blob_postgresql.pdf'    # output pdf filename

    # Postgresql datasource
    config = {
        "adapter":
        "postgres",
        "config":
        "host='172.18.0.4' port='5432' dbname='agatereports' user='******' password='******'"
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #8
0
def image_database_blob_mysql_sample(
        jrxml_filename='./jrxml/image_database_blob.jrxml',
        output_filename='./output/image_database_blob_mysql.pdf'):
    """
    Display an image saved as a blob in a mysql database table column.

    WARNING: Before running this sample, database table 'pictures' must be create and populated.
    Run Python scripts in directory 'agatereports/tests/database/mysql/create_pictures.py ' to create and
    populated database table.
    """
    logger.info('running image database blob sample')
    # jrxml_filename = './jrxml/image_database_blob.jrxml'  # input jrxml filename
    # output_filename = './output/image_database_blob_mysql.pdf'    # output pdf filename

    # MySQL datasource
    # WARNING: when handling blog columns, it is currently necessary to specify 'use_pure: True' attribute because
    #          of a bug in MySQL Connector bug.
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'port': '3306',
        'user': '******',
        'password': '******',
        'database': 'agatereports',
        'use_pure': True
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #9
0
ファイル: shapes.py プロジェクト: weldermarcosxd/agatereports
def shapes_sample(jrxml_filename = './jrxml/shapes.jrxml', output_filename = './output/shapes.pdf'):
    """
    Shapes samples.
    """
    logger.info('running shapes sample')
    # jrxml_filename = './jrxml/shapes.jrxml'  # input jrxml filename
    # output_filename = './output/shapes.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename, output_filename=output_filename)
    pdf_page.generate_report()
コード例 #10
0
def text_styles_sample(jrxml_filename='./jrxml/text_styles.jrxml',
                       output_filename='./output/text_styles.pdf'):
    """
    Samples of different text styles.
    """
    logger.info('running text styles sample')
    # jrxml_filename = './jrxml/text_styles.jrxml'  # input jrxml filename
    # output_filename = './output/text_styles.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #11
0
ファイル: image.py プロジェクト: weldermarcosxd/agatereports
def image_sample(jrxml_filename='./jrxml/image.jrxml',
                 output_filename='./output/image.pdf'):
    """
    Image images in a local file system sample.
    """
    logger.info('running image sample')
    # jrxml_filename = './jrxml/image.jrxml'  # input jrxml filename
    # output_filename = './output/image.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #12
0
def image_workspace_sample(jrxml_filename='./jrxml/image_workspace.jrxml',
                           output_filename='./output/image_workspace.pdf'):
    """
    Display an image in a workspace sample.
    """
    logger.info('running image workspace sample')
    # jrxml_filename = './jrxml/image_workspace.jrxml'  # input jrxml filename
    # output_filename = './output/image_workspace.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #13
0
def barcode_sample(jrxml_filename='./jrxml/barcode.jrxml',
                   output_filename='./output/barcode.pdf'):
    """
    Barcode generation sample.
    """
    logger.info('running barcode sample')
    # jrxml_filename = './jrxml/barcode.jrxml'  # input jrxml filename
    # output_filename = './output/barcode.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #14
0
def image_url_sample(jrxml_filename='./jrxml/image_url.jrxml',
                     output_filename='./output/image_url.pdf'):
    """
    Display an image from the Internet sample.
    """
    logger.info('running image url sample')
    # jrxml_filename = './jrxml/image_url.jrxml'  # input jrxml filename
    # output_filename = './output/image_url.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #15
0
def hello_world_sample(jrxml_filename='./jrxml/hello_world.jrxml',
                       output_filename='./output/hello_world.pdf'):
    """
    Hello World sample.
    """
    logger.info('running hello world sample')
    # jrxml_filename = './jrxml/hello_world.jrxml'  # input jrxml filename
    # output_filename = './output/hello_world.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #16
0
def page_format_A3_sample(jrxml_filename='./jrxml/page_format_A3.jrxml',
                          output_filename='./output/page_format_A3.pdf'):
    """
    Page format sample. A3 sized page.
    """
    logger.info('running print format A3 sample')
    # jrxml_filename = './jrxml/page_format_A3.jrxml'  # input jrxml filename
    # output_filename = './output/page_format_A3.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #17
0
def no_elements_sample(jrxml_filename='./jrxml/no_elements.jrxml',
                       output_filename='./output/no_elements.pdf'):
    """
    Hello World sample.
    """
    logger.info('running no elements sample')
    # jrxml_filename = './jrxml/no_elements.jrxml'  # input jrxml filename
    # output_filename = './output/no_elements.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename)
    pdf_page.generate_report()
コード例 #18
0
def datasource_csv_sample(jrxml_filename='./jrxml/datasource_csv.jrxml',
                          output_filename='./output/datasource_csv.pdf'):
    """
    CSV data source sample.
     """
    logger.info('running datasource csv sample')
    # jrxml_filename = './jrxml/datasource_csv.jrxml'  # input jrxml filename
    # output_filename = './output/datasource_csv.pdf'    # output pdf filename

    # CSV datasource configuration
    data_config = {'adapter': 'csv', 'filename': '../data/product.csv'}

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=data_config)
    pdf_page.generate_report()
コード例 #19
0
def no_datasource_sample(jrxml_filename='./jrxml/no_datasource.jrxml',
                         output_filename='./output/no_datasource.pdf'):
    """
    No datasource sample.

    To display only static elements, data_source may be set to 'None' or omitted from BaseClass argument.
    """
    logger.info('running no datasource sample')
    # jrxml_filename = './jrxml/no_datasource.jrxml'  # input jrxml filename
    # output_filename = './output/no_datasource.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=None)
    # OR 'data_config' may be entirely omitted from the argument as in the statement below.
    # pdf_page = BaseClass(jrxml_filename=jrxml_filename, output_filename=output_filename)
    pdf_page.generate_report()
コード例 #20
0
def image_database_sample(jrxml_filename = './jrxml/image_database.jrxml', output_filename = './output/image_database.pdf'):
    """
    Display an image based on file path from a database table.
    """
    logger.info('running image database sample')
    # jrxml_filename = './jrxml/image_database.jrxml'  # input jrxml filename
    # output_filename = './output/image_database.pdf'    # output pdf filename

    # MySQL datasource configuration
    config = {'adapter': 'mysql', 'host': 'localhost', 'port': '3306', 'user': '******', 'password': '******',
              'database': 'agatereports'}

    # # Postgresql datasource configuration
    # config = {"adapter": "postgres",
    #           "config": "host='172.18.0.4' port='5432' dbname='agatereports' user='******' password='******'"}

    pdf_page = BasicReport(jrxml_filename=jrxml_filename, output_filename=output_filename, data_config=config)
    pdf_page.generate_report()
コード例 #21
0
def when_no_data_no_data_section_sample(
        jrxml_filename='./jrxml/when_no_data_no_data_section.jrxml',
        output_filename='./output/when_no_data_no_data_section.pdf'):
    """
    When no data, 'No Data Section' sample.

    What to do when datasource is specified but the query return is specified in 'No Data Section' on a report.
    In this sample, sql query is set to 'SELECT * FROM address WHERE id < 1' to return no result.

    Below are possible values of 'When No Data Type' and description of what will happen.
    Value                       Description
    <NULL>                      no report is generated (no file is created). (default)
    'No Pages'                  same as <NULL>. no report is generated (no file is created).
    'Blank Page'                a blank report is generated.
    'All Sections No Detail'    a report is generated with all bands except 'detail' and 'No Data' bands.
    'No Data Section'           a report is generated with content of the 'No Data' band.

    WARNING: Before running this sample, schema 'agatereports' must be create and populated.
    Run scripts in directory 'agatereports/tests/database/mysql' to create and populated database tables.

    CAUTION: Edit values of 'host' and 'port' to those in your environment.
     """
    logger.info('running when no data no data section sample')
    # jrxml_filename = './jrxml/when_no_data_no_data_section.jrxml'  # input jrxml filename
    # output_filename = './output/when_no_data_no_data_section.pdf'  # output pdf filename

    # MySQL datasource
    config = {
        'adapter': 'mysql',
        'host': 'localhost',
        'port': '3306',
        'user': '******',
        'password': '******',
        'database': 'agatereports'
    }

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           data_config=config)
    pdf_page.generate_report()
コード例 #22
0
    def horarios(self, tienda, fecha1, fecha2):

        db = DB_reporte()
        Datos = db.horarios(tienda, fecha1, fecha2)

        path = os.getcwd() + r'\reportes\temp\datos_horarios.csv'
        pandas.DataFrame(Datos).to_csv(path, index=False)

        jrxml_filename = './reportes/jrxml/Horarios.jrxml'  # input jrxml filename
        output_filename = './reportes/descargas/Horarios.pdf'  # output pdf filename

        data_config = {
            'adapter': 'csv',
            'filename': './reportes/temp/datos_Horarios.csv'
        }

        pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                               output_filename=output_filename,
                               data_config=data_config)
        pdf_page.generate_report()
        rutapdf = os.getcwd() + r'\reportes\descargas\Horarios.pdf'

        return 1
コード例 #23
0
    def Productos(self):

        db = DB_reporte()
        Datos = db.productos()

        path = os.getcwd() + r'\reportes\temp\datos_productos.csv'
        pandas.DataFrame(Datos).to_csv(path, index=False)

        jrxml_filename = './reportes/jrxml/Producto.jrxml'  # input jrxml filename
        output_filename = './reportes/descargas/Producto.pdf'  # output pdf filename

        data_config = {
            'adapter': 'csv',
            'filename': './reportes/temp/datos_productos.csv'
        }

        pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                               output_filename=output_filename,
                               data_config=data_config)
        pdf_page.generate_report()
        rutapdf = os.getcwd() + r'\reportes\descargas\Producto.pdf'

        return 1
コード例 #24
0
    def print(self):
        jrxml_filename = './reports/employees.jrxml'  # input jrxml filename
        output_filename = 'output\datasource_mysql.pdf'  # output pdf filename

        # MySQL datasource
        config = {
            'host': 'localhost',
            'port': '3306',
            'user': '******',
            'password': '******',
            'database': 'employees'
        }
        data_source = MysqlAdapter(**config)

        pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                               output_filename=output_filename,
                               data_source=data_source)
        print(datetime.fromtimestamp(time()).strftime('%Y-%m-%d %H:%M:%S'))
        pdf_page.generate_report()
        print(datetime.fromtimestamp(time()).strftime('%Y-%m-%d %H:%M:%S'))

        path = os.path.abspath((os.path.join(os.getcwd(), output_filename)))
        subprocess.Popen('%s' % path, shell=True)
コード例 #25
0
def generate_test_pdf(output_dir='output'):
    """
    Generate test pdf reports.
    """
    filenames = [
        'empty_report', 'no_data', 'text_fields', 'text_fields_lastPageFooter',
        'shapes', 'current_date', 'barcodes', 'pattern',
        'when_no_data_All_sections_no_detail', 'when_no_data_Blank_page',
        'when_no_data_No_data_section', 'when_no_data_No_pages',
        'when_no_data_Null', 'fonts', 'variables_system', 'only_title',
        'only_column_header', 'only_page_footer', 'only_page_header',
        'only_group_header', 'only_group_footer',
        'only_group_header_with_field'
    ]

    for filename in filenames:
        logger.info('currently processing: ' + filename + '.jrxml')
        input_filename = './jrxml/' + filename + '.jrxml'  # input jrxml filename
        output_filename = './' + output_dir + '/pdf_' + filename + '.pdf'  # output pdf filename
        fonts = [
            # list of additional directories to search for fonts
            {
                'font_path': [
                    '../../tests/fonts/',
                    '/usr/share/fonts/truetype/msttcorefonts/'
                ]
            },
            # Japanese font
            {
                'font_filename':
                'ipag.ttc',
                'fonts': [{
                    'index': 0,
                    'name': 'IPAGothic'
                }, {
                    'index': 1,
                    'name': 'IPAPGothic'
                }]
            },
            # tests/fonts
            {
                'font_filename': 'TIMES.TTF',
                'fonts': [{
                    'index': 0,
                    'name': 'Times_New_Roman'
                }]
            },
            {
                'font_filename': 'TIMESBD.TTF',
                'fonts': [{
                    'index': 1,
                    'name': 'Times_New_Roman-Bold'
                }]
            },
            {
                'font_filename': 'timesi.ttf',
                'fonts': [{
                    'index': 2,
                    'name': 'Times_New_Roman-Italic'
                }]
            },
            {
                'font_filename': 'TIMESBI0.TTF',
                'fonts': [{
                    'index': 3,
                    'name': 'Times_New_Roman-BoldItalic'
                }]
            },
            {
                'font-family': {
                    'name': 'Times_New_Roman',
                    'normal': 'Times_New_Roman',
                    'bold': 'Times_New_Roman-Bold',
                    'italic': 'Times_New_Roman-Italic',
                    'boldItalic': 'Times_New_Roman-BoldItalic'
                }
            },
            # tests/fonts. No index
            {
                'font_filename': 'Vera.ttf',
                'fonts': 'Vera'
            },
            {
                'font_filename': 'VeraBd.ttf',
                'fonts': 'Vera-Bold'
            },
            {
                'font_filename': 'VeraIt.ttf',
                'fonts': 'Vera-Italic'
            },
            {
                'font_filename': 'VeraBI.ttf',
                'fonts': 'Vera-BoldItalic'
            },
            {
                'font-family': {
                    'name': 'Vera',
                    'normal': 'Vera',
                    'bold': 'Vera-Bold',
                    'italic': 'Vera-Italic',
                    'boldItalic': 'Vera-BoldItalic'
                }
            },
            # ubuntu font
            {
                'font_filename': 'Verdana.ttf',
                'fonts': [{
                    'index': 0,
                    'name': 'Verdana'
                }]
            },
            {
                'font_filename': 'Verdana_Bold.ttf',
                'fonts': [{
                    'index': 1,
                    'name': 'Verdana-Bold'
                }]
            },
            {
                'font_filename': 'Verdana_Italic.ttf',
                'fonts': [{
                    'index': 2,
                    'name': 'Verdana-Italic'
                }]
            },
            {
                'font_filename': 'Verdana_Bold_Italic.ttf',
                'fonts': [{
                    'index': 3,
                    'name': 'Verdana-BoldItalic'
                }]
            },
            {
                'font-family': {
                    'name': 'Verdana',
                    'normal': 'Verdana',
                    'bold': 'Verdana-Bold',
                    'italic': 'Verdana-Italic',
                    'boldItalic': 'Verdana-BoldItalic'
                }
            }
        ]

        # TODO write tests to check config parameters
        # MySQL datasource
        config = {
            'adapter': 'mysql',
            'host': '172.18.0.2',
            'user': '******',
            'password': '******',
            'database': 'agatereports'
        }

        # Postgresql datasource
        # config = {"adapter": "postgres",
        #           "config": "host='172.18.0.4' port='5432' dbname='agatereports' user='******' password='******'"}

        pdf_page = BasicReport(input_filename, output_filename, config, fonts)
        pdf_page.generate_report()
コード例 #26
0
def fonts_sample(jrxml_filename='./jrxml/fonts.jrxml',
                 output_filename='./output/fonts.pdf'):
    """
    Font samples.
    """
    logger.info('running fonts sample')
    font_list = [
        # list of additional directories to search for fonts
        {
            'font_path':
            ['../tests/fonts/', '/usr/share/fonts/truetype/msttcorefonts/']
        },
        # Japanese font (ttc).
        # 'font_filename' is the name of the ttc file
        # 'index' is the subfontIndex.
        # 'name' if the font name
        {
            'font_filename':
            'ipag.ttc',
            'fonts': [{
                'index': 0,
                'name': 'IPAGothic'
            }, {
                'index': 1,
                'name': 'IPAPGothic'
            }]
        },
        # specifying normal, bold, italic, bold italic fonts as a single font family.
        # It is necessary to specify these 4 fonts in a font family.
        # When a font family name is specified in the report, selecting bold and italic attributes will cause to
        # automatically select the appropriate font in the family.
        # 'file_filename' is the name of the ttf file
        {
            'font_filename': 'TIMES.TTF',  # normal font
            'fonts': [{
                'index': 0,
                'name': 'Times_New_Roman'
            }]
        },
        {
            'font_filename': 'TIMESBD.TTF',  # bold font
            'fonts': [{
                'index': 1,
                'name': 'Times_New_Roman-Bold'
            }]
        },
        {
            'font_filename': 'timesi.ttf',  # italic font
            'fonts': [{
                'index': 2,
                'name': 'Times_New_Roman-Italic'
            }]
        },
        {
            'font_filename': 'TIMESBI0.TTF',  # bold + italic font
            'fonts': [{
                'index': 3,
                'name': 'Times_New_Roman-BoldItalic'
            }]
        },
        # 'name' is the font name to use in the report
        # 'normal', 'bold', 'italic', and 'boldItalic' are names of fonts specified above.
        {
            'font-family': {
                'name': 'Times_New_Roman',
                'normal': 'Times_New_Roman',
                'bold': 'Times_New_Roman-Bold',
                'italic': 'Times_New_Roman-Italic',
                'boldItalic': 'Times_New_Roman-BoldItalic'
            }
        },
        # font family. 'index' may be omitted when using ttf fonts
        {
            'font_filename': 'Vera.ttf',
            'fonts': 'Vera'
        },
        {
            'font_filename': 'VeraBd.ttf',
            'fonts': 'Vera-Bold'
        },
        {
            'font_filename': 'VeraIt.ttf',
            'fonts': 'Vera-Italic'
        },
        {
            'font_filename': 'VeraBI.ttf',
            'fonts': 'Vera-BoldItalic'
        },
        {
            'font-family': {
                'name': 'Vera',
                'normal': 'Vera',
                'bold': 'Vera-Bold',
                'italic': 'Vera-Italic',
                'boldItalic': 'Vera-BoldItalic'
            }
        },
        # ubuntu font - example of specifying fonts installed in Ubuntu directory
        # '/usr/share/fonts/truetype/msttcorefonts/'
        # It is still necessary to define font family to get bold, italic, bold italic attributes on fonts
        {
            'font_filename': 'Verdana.ttf',
            'fonts': [{
                'index': 0,
                'name': 'Verdana'
            }]
        },
        {
            'font_filename': 'Verdana_Bold.ttf',
            'fonts': [{
                'index': 1,
                'name': 'Verdana-Bold'
            }]
        },
        {
            'font_filename': 'Verdana_Italic.ttf',
            'fonts': [{
                'index': 2,
                'name': 'Verdana-Italic'
            }]
        },
        {
            'font_filename': 'Verdana_Bold_Italic.ttf',
            'fonts': [{
                'index': 3,
                'name': 'Verdana-BoldItalic'
            }]
        },
        {
            'font-family': {
                'name': 'Verdana',
                'normal': 'Verdana',
                'bold': 'Verdana-Bold',
                'italic': 'Verdana-Italic',
                'boldItalic': 'Verdana-BoldItalic'
            }
        }
    ]

    # jrxml_filename = './jrxml/fonts.jrxml'  # input jrxml filename
    # output_filename = './output/fonts.pdf'    # output pdf filename

    pdf_page = BasicReport(jrxml_filename=jrxml_filename,
                           output_filename=output_filename,
                           fonts=font_list)
    pdf_page.generate_report()