Beispiel #1
0
def main():
    arguments = get_args()
    supported_ext_types = ['.json', '.xml']

    # Get the file extension
    _, ext = os.path.splitext(arguments.data_file)

    if ext not in supported_ext_types:
        msg = 'PDF Creator only accepts the following file types: ' \
        '{}. Got {}'
        raise RuntimeError(msg.format(str(supported_ext_types, ext)))

    doc = SimpleDocTemplate(arguments.path,
                            rightMargin=72,
                            leftMargin=36,
                            topMargin=125,
                            bottomMargin=18)

    if ext == '.xml':
        data = parse_xml(arguments.data_file)
    elif ext == '.json':
        data = parse_json(arguments.data_file)

    elements = []

    txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit,'
    styles = getSampleStyleSheet()
    paragraph = Paragraph(txt, styles["Normal"])
    elements.append(paragraph)

    doc.data = data
    doc.logo_path = arguments.logo

    doc.build(elements, onFirstPage=header)
def main():
    arguments = get_args()
    doc = SimpleDocTemplate(
        arguments.path,
        rightMargin=72, leftMargin=36,
        topMargin=125, bottomMargin=18)
    
    xml = parse_xml(arguments.data_file)
    
    elements = []
    
    txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit,'
    styles = getSampleStyleSheet()
    paragraph = Paragraph(txt, styles["Normal"])
    elements.append(paragraph)
    
    doc.xml = xml
    doc.logo_path = arguments.logo

    doc.build(elements, onFirstPage=header)
Beispiel #3
0
def main(pdf_file, xml_file):
    doc = SimpleDocTemplate(pdf_file,
                            rightMargin=72,
                            leftMargin=36,
                            topMargin=125,
                            bottomMargin=18)

    xml = parse_xml(xml_file)

    doc.xml = xml
    doc.logo_path = get_logo_from_config()

    elements = []

    txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit,'
    styles = getSampleStyleSheet()
    paragraph = Paragraph(txt, styles["Normal"])
    elements.append(paragraph)

    doc.build(elements, onFirstPage=header)
Beispiel #4
0
def main(pdf_file, xml_file, logo):
    doc = SimpleDocTemplate(pdf_file,
                            rightMargin=72,
                            leftMargin=36,
                            topMargin=125,
                            bottomMargin=36)

    xml = parse_xml(xml_file)

    doc.xml = xml
    doc.logo_path = logo

    elements = []

    txt = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit,'
    styles = getSampleStyleSheet()
    for line in range(150):
        paragraph = Paragraph(txt, styles["Normal"])
        elements.append(paragraph)

    doc.build(elements, onFirstPage=header, onLaterPages=footer)