示例#1
0
def mousereport_pdf(animal_id):
    html = mousereport(animal_id=animal_id)
    stylesheets = [
        CSS(url_for('static', filename='styles.css')),
        CSS(url_for('static', filename='datajoint.css'))
    ]
    return render_pdf(HTML(string=html), stylesheets=stylesheets)
示例#2
0
def scanreport_pdf(animal_id, session, scan_idx):
    html = scanreport(animal_id=animal_id, session=session, scan_idx=scan_idx)
    stylesheets = [
        CSS(url_for('static', filename='styles.css')),
        CSS(url_for('static', filename='datajoint.css'))
    ]
    return render_pdf(HTML(string=html), stylesheets=stylesheets)
示例#3
0
def collection(locale):

    form = toPDF_wrap(locale)()
    print(request.method)
    collection_ids = getCollection()
    collection = []
    custom_image_ids = []

    # Get pairs from session object
    for id in collection_ids:
        collection.append(Word.query.get(int(id)))

    custom_image_ids = custom_images_in_collection(collection)

    print(custom_image_ids)

    if request.method == "POST":
        if getCollection():
            if form.validate_on_submit():
                # Background file name is defined in the declaration of wtf choices in forms.py
                bgfilename = form.background.data
                template = render_template("mypdf.html", collection=collection)
                html = HTML(string=template, base_url=request.base_url)

                # This bit of CSS is dynamically generated, the rest is hard coded in the template
                css = CSS(
                    string=
                    '@page :left { background-image: url(/static/permaimages/'
                    + bgfilename + '.png);}')

                count_as_used(collection_ids)

                return render_pdf(html, stylesheets=[css])

    return render_template("collection.html", collection=collection, form=form)
示例#4
0
def download_pdf(schema, eq_id, form_type):
    session_data = get_session_store().session_data

    if _is_submission_viewable(schema.json, session_data.submitted_time):
        submitted_data = data_access.get_by_key(SubmittedResponse,
                                                session_data.tx_id)

        if submitted_data:
            filename = '{}_{}.pdf'.format(eq_id, form_type)
            html = _render_submission_page(session_data, submitted_data,
                                           schema, eq_id, form_type)
            css = """
                .header__main {
                    background: none !important;
                }
                .header__title {
                    color: black !important;
                }
            """

            return render_pdf(HTML(string=html), [CSS(string=css)], filename)

    return redirect(
        url_for('post_submission.get_thank_you',
                eq_id=eq_id,
                form_type=form_type))
示例#5
0
 def test_wrappers(self):
     with app.test_request_context(base_url='http://example.org/bar/'):
         # HTML can also be used with named parameters only:
         html = HTML(url='http://example.org/bar/foo/')
         css = CSS(url='http://example.org/bar/static/style.css')
     assert hasattr(html, 'root_element')
     assert hasattr(css, 'rules')
示例#6
0
def get_patient_admission_discharge_summary_pdf(patient_id, admission_id):
    query = md.Admission.query\
        .filter(md.Admission.patient_id == patient_id)\
        .filter(md.Admission.id == admission_id)\
        .filter(md.Admission.end_time != None)

    admission = query.first()

    if admission is None:
        return errors.resource_not_found("Item with not found.")

    return render_pdf(
        HTML(
            string=render_template(
                'admission/discharge-summary.html',
                admission=admission
            )
        ),
        stylesheets=[
            CSS(
                string=render_template(
                    'admission/discharge-summary.css'
                )
            )
        ]
    )
示例#7
0
def pdf(buyer_order_id):
    """
    文件下载
    :param buyer_order_id:
    :return:
    """
    buyer_order_info = get_buyer_order_row_by_id(buyer_order_id)
    # 检查资源是否存在
    if not buyer_order_info:
        abort(404)
    # 检查资源是否删除
    if buyer_order_info.status_delete == STATUS_DEL_OK:
        abort(410)

    buyer_order_print_date = time_utc_to_local(
        buyer_order_info.update_time).strftime('%Y-%m-%d')
    buyer_order_code = '%s%s' % (
        g.BUYER_ORDER_PREFIX, time_utc_to_local(
            buyer_order_info.create_time).strftime('%y%m%d%H%M%S'))

    # 获取渠道公司信息
    supplier_info = get_supplier_row_by_id(buyer_order_info.supplier_cid)

    # 获取渠道联系方式
    supplier_contact_info = get_supplier_contact_row_by_id(
        buyer_order_info.supplier_contact_id)

    # 获取询价人员信息
    user_info = get_user_row_by_id(buyer_order_info.uid)

    buyer_order_items = get_buyer_order_items_rows(
        buyer_order_id=buyer_order_id)

    # 文档信息
    document_info = DOCUMENT_INFO.copy()
    document_info['TITLE'] = _('buyer order pdf')

    template_name = 'buyer/order/pdf.html'

    html = render_template(template_name,
                           buyer_order_id=buyer_order_id,
                           buyer_order_info=buyer_order_info,
                           supplier_info=supplier_info,
                           supplier_contact_info=supplier_contact_info,
                           user_info=user_info,
                           buyer_order_items=buyer_order_items,
                           buyer_order_print_date=buyer_order_print_date,
                           buyer_order_code=buyer_order_code,
                           **document_info)
    # return html
    return render_pdf(
        html=HTML(string=html),
        stylesheets=[CSS(string='@page {size:A4; margin:35px;}')],
        download_filename='采购订单.pdf'.encode('utf-8'))
示例#8
0
def pdf(sales_order_id):
    """
    文件下载
    :param sales_order_id:
    :return:
    """
    sales_order_info = get_sales_order_row_by_id(sales_order_id)
    # 检查资源是否存在
    if not sales_order_info:
        abort(404)
    # 检查资源是否删除
    if sales_order_info.status_delete == STATUS_DEL_OK:
        abort(410)

    sales_order_print_date = time_utc_to_local(
        sales_order_info.update_time).strftime('%Y-%m-%d')
    sales_order_code = '%s%s' % (
        g.SALES_ORDER_PREFIX, time_utc_to_local(
            sales_order_info.create_time).strftime('%y%m%d%H%M%S'))

    # 获取客户公司信息
    customer_info = get_customer_row_by_id(sales_order_info.customer_cid)

    # 获取客户联系方式
    customer_contact_info = get_customer_contact_row_by_id(
        sales_order_info.customer_contact_id)

    # 获取询价人员信息
    user_info = get_user_row_by_id(sales_order_info.uid)

    sales_order_items = get_sales_order_items_rows(
        sales_order_id=sales_order_id)

    # 文档信息
    document_info = DOCUMENT_INFO.copy()
    document_info['TITLE'] = _('sales order pdf')

    template_name = 'sales/order/pdf.html'

    html = render_template(template_name,
                           sales_order_id=sales_order_id,
                           sales_order_info=sales_order_info,
                           customer_info=customer_info,
                           customer_contact_info=customer_contact_info,
                           user_info=user_info,
                           sales_order_items=sales_order_items,
                           sales_order_print_date=sales_order_print_date,
                           sales_order_code=sales_order_code,
                           **document_info)
    # return html
    return render_pdf(
        html=HTML(string=html),
        stylesheets=[CSS(string='@page {size:A4; margin:35px;}')],
        download_filename='采购订单.pdf'.encode('utf-8'))
示例#9
0
def pdf(purchase_id):
    """
    文件下载
    :param purchase_id:
    :return:
    """
    purchase_info = get_purchase_row_by_id(purchase_id)
    # 检查资源是否存在
    if not purchase_info:
        abort(404)
    # 检查资源是否删除
    if purchase_info.status_delete == STATUS_DEL_OK:
        abort(410)

    purchase_print_date = time_utc_to_local(
        purchase_info.update_time).strftime('%Y-%m-%d')
    purchase_code = '%s%s' % (
        g.ENQUIRIES_PREFIX, time_utc_to_local(
            purchase_info.create_time).strftime('%y%m%d%H%M%S'))

    # 获取渠道公司信息
    supplier_info = get_supplier_row_by_id(purchase_info.supplier_cid)

    # 获取渠道联系方式
    supplier_contact_info = get_supplier_contact_row_by_id(
        purchase_info.supplier_contact_id)

    # 获取进货人员信息
    user_info = get_user_row_by_id(purchase_info.uid)

    purchase_items = get_purchase_items_rows(purchase_id=purchase_id)

    # 文档信息
    document_info = DOCUMENT_INFO.copy()
    document_info['TITLE'] = _('purchase pdf')

    template_name = 'purchase/pdf.html'

    html = render_template(template_name,
                           purchase_id=purchase_id,
                           purchase_info=purchase_info,
                           supplier_info=supplier_info,
                           supplier_contact_info=supplier_contact_info,
                           user_info=user_info,
                           purchase_items=purchase_items,
                           purchase_print_date=purchase_print_date,
                           purchase_code=purchase_code,
                           **document_info)
    # return html
    return render_pdf(
        html=HTML(string=html),
        stylesheets=[CSS(string='@page {size:A4; margin:35px;}')],
        download_filename='销售出货.pdf'.encode('utf-8'))
示例#10
0
def pdf(quotation_id):
    """
    文件下载
    :param quotation_id:
    :return:
    """
    quotation_info = get_quotation_row_by_id(quotation_id)
    # 检查资源是否存在
    if not quotation_info:
        abort(404)
    # 检查资源是否删除
    if quotation_info.status_delete == STATUS_DEL_OK:
        abort(410)

    quotation_print_date = time_utc_to_local(
        quotation_info.update_time).strftime('%Y-%m-%d')
    quotation_code = '%s%s' % (
        g.QUOTATION_PREFIX, time_utc_to_local(
            quotation_info.create_time).strftime('%y%m%d%H%M%S'))

    # 获取客户公司信息
    customer_info = get_customer_row_by_id(quotation_info.customer_cid)

    # 获取客户联系方式
    customer_contact_info = get_customer_contact_row_by_id(
        quotation_info.customer_contact_id)

    # 获取报价人员信息
    user_info = get_user_row_by_id(quotation_info.uid)

    quotation_items = get_quotation_items_rows(quotation_id=quotation_id)

    # 文档信息
    document_info = DOCUMENT_INFO.copy()
    document_info['TITLE'] = _('quotation download')

    template_name = 'quotation/pdf.html'

    html = render_template(template_name,
                           quotation_id=quotation_id,
                           quotation_info=quotation_info,
                           customer_info=customer_info,
                           customer_contact_info=customer_contact_info,
                           user_info=user_info,
                           quotation_items=quotation_items,
                           quotation_print_date=quotation_print_date,
                           quotation_code=quotation_code,
                           **document_info)
    # return html
    return render_pdf(
        html=HTML(string=html),
        stylesheets=[CSS(string='@page {size:A4; margin:35px;}')],
        download_filename='报价单.pdf'.encode('utf-8'))
示例#11
0
def pdf(enquiry_id):
    """
    文件下载
    :param enquiry_id:
    :return:
    """
    enquiry_info = get_enquiry_row_by_id(enquiry_id)
    # 检查资源是否存在
    if not enquiry_info:
        abort(404)
    # 检查资源是否删除
    if enquiry_info.status_delete == STATUS_DEL_OK:
        abort(410)

    enquiry_print_date = time_utc_to_local(
        enquiry_info.update_time).strftime('%Y-%m-%d')
    enquiry_code = '%s%s' % (
        g.ENQUIRIES_PREFIX, time_utc_to_local(
            enquiry_info.create_time).strftime('%y%m%d%H%M%S'))

    # 获取客户公司信息
    supplier_info = get_supplier_row_by_id(enquiry_info.supplier_cid)

    # 获取客户联系方式
    supplier_contact_info = get_supplier_contact_row_by_id(
        enquiry_info.supplier_contact_id)

    # 获取询价人员信息
    user_info = get_user_row_by_id(enquiry_info.uid)

    enquiry_items = get_enquiry_items_rows(enquiry_id=enquiry_id)

    # 文档信息
    document_info = DOCUMENT_INFO.copy()
    document_info['TITLE'] = _('enquiry edit')

    template_name = 'enquiry/pdf.html'

    html = render_template(template_name,
                           enquiry_id=enquiry_id,
                           enquiry_info=enquiry_info,
                           supplier_info=supplier_info,
                           supplier_contact_info=supplier_contact_info,
                           user_info=user_info,
                           enquiry_items=enquiry_items,
                           enquiry_print_date=enquiry_print_date,
                           enquiry_code=enquiry_code,
                           **document_info)
    # return html
    return render_pdf(
        html=HTML(string=html),
        stylesheets=[CSS(string='@page {size:A4; margin:35px;}')],
        download_filename='询价单.pdf'.encode('utf-8'))
示例#12
0
def pdf(delivery_id):
    """
    文件下载
    :param delivery_id:
    :return:
    """
    delivery_info = get_delivery_row_by_id(delivery_id)
    # 检查资源是否存在
    if not delivery_info:
        abort(404)
    # 检查资源是否删除
    if delivery_info.status_delete == STATUS_DEL_OK:
        abort(410)

    delivery_print_date = time_utc_to_local(
        delivery_info.update_time).strftime('%Y-%m-%d')
    delivery_code = '%s%s' % (
        g.ENQUIRIES_PREFIX, time_utc_to_local(
            delivery_info.create_time).strftime('%y%m%d%H%M%S'))

    # 获取客户公司信息
    customer_info = get_customer_row_by_id(delivery_info.customer_cid)

    # 获取客户联系方式
    customer_contact_info = get_customer_contact_row_by_id(
        delivery_info.customer_contact_id)

    # 获取出货人员信息
    user_info = get_user_row_by_id(delivery_info.uid)

    delivery_items = get_delivery_items_rows(delivery_id=delivery_id)

    # 文档信息
    document_info = DOCUMENT_INFO.copy()
    document_info['TITLE'] = _('delivery pdf')

    template_name = 'delivery/pdf.html'

    html = render_template(template_name,
                           delivery_id=delivery_id,
                           delivery_info=delivery_info,
                           customer_info=customer_info,
                           customer_contact_info=customer_contact_info,
                           user_info=user_info,
                           delivery_items=delivery_items,
                           delivery_print_date=delivery_print_date,
                           delivery_code=delivery_code,
                           **document_info)
    # return html
    return render_pdf(
        html=HTML(string=html),
        stylesheets=[CSS(string='@page {size:A4; margin:35px;}')],
        download_filename='销售出货.pdf'.encode('utf-8'))
示例#13
0
def export_diary_by_date():
    user_name = request.form.get('user_name')
    date = request.form.get('date')
    if '-' in date:
        yyyy, mm, dd = date.split("-")
        date = mm + dd + yyyy
    file_location = DIARY_FOLDER + user_name + '/' + date + '.json'
    if not os.path.exists(file_location):
        return render_pdf(HTML(string="No diary entry for this day: %s" %
                               date))
    pdf_content = ''
    f = open(file_location)
    for l in f:
        pdf_content += l.rstrip()
    f.close()

    pdf_content = json.loads(pdf_content)
    html_content = '<h2>%s</h2>' % date
    for key in pdf_content:
        if key == 'content':
            html_content += '<p>%s</p>' % pdf_content[key]
    html_content += '<img class="diary_image" src="/static/photos/%s/%s.jpg" />' % (
        user_name, date)

    ## pdfkit method for exporting only works locally.
    ## does not work on pythonanywhere, since it requires wkhtmltopdf which cannot be installed without root
    # pdf = pdfkit.from_string(pdf_content, False) # pdfkit can also export from file and url. buggy not solved.
    #
    # print(pdf)
    # response = make_response(pdf)
    # response.headers["Content-Type"] = "application/pdf"
    # response.headers["Content-Disposition"] = "inline; filename=%s.pdf" % date
    # return response

    ## testing weasyprint
    # html = HTML(string='<h1>The title</h1>')
    html = HTML(string=html_content)
    css = CSS(string='''
        @font-face {
            font-family: Gentium;
            src: url(http://example.com/fonts/Gentium.otf);
        }
        h1 { font-family: Gentium }
        .diary_image { width: 100%; }
        ''')

    # html.write_pdf(
    #     '/tmp/example.pdf', stylesheets=[css])

    return render_pdf(html, stylesheets=[css])
示例#14
0
def generate_report(site, response):

    site_info = models.describe_site_for_twilio(site)
    html = render_template('describe_report.html', r=site_info)
    report_file = site.replace(" ", "_") + '_report.png'
    HTML(string=html).write_png(
        config.fig_dir + report_file,
        stylesheets=[CSS(url_for('static', filename='report.css'))],
        resolution=200)

    # with response.message(site_info['message']) as m:
    #   m.media('/trend_figures/' + report_file)
    response.message(site_info['message'])
    response.message('').append(
        twilio.twiml.Media('/trend_figures/' + report_file))

    return response
示例#15
0
def hygge_contract(contract_title):
    sdf = Pinyin().get_pinyin(contract_title.split('-')[0], '').upper()
    # 页眉和日期
    with open('flaskr/static/hyggeadd.css', 'w') as hygge_css:
        hygge_css.write(
            "@media print { @page { @top-left { content: '咨询服务合同号: " +
            Pinyin().get_initials(contract_title.split("-")[0], '') +
            time.strftime("%Y%m%d", time.localtime()) + "'}} " +
            ".sign-date::before { content: '" +
            time.strftime(" %Y 年 %m 月 %d 日", time.localtime()) + "'; }" +
            ".contract-series::before { content: 'T-" +
            time.strftime("%Y%m%d", time.localtime()) + "-" +
            Pinyin().get_pinyin(contract_title.split("-")[0], "").upper() +
            "';}}")
    html = render_template('hygge_contract.html')
    cssfile = CSS(url_for("static", filename='hyggeadd.css'))
    return HTML(string=html).render(stylesheets=[cssfile])
示例#16
0
def render_paper(paper):
    html = render_template(
        "papers/ptp.html",
        css_files=["css/ptp.css"],
        title="Paper-to-PDF",
        paper=paper,
    )
    css = """
    body { font: 2em Fontin, serif }
    nav { font-size: .7em }

    @page { size: A4; margin: 1cm }
    @media print {
        nav { display: none }
    }
    """
    filename = f"{paper.name}-{paper.exam_date}.pdf"
    return filename, HTML(string=html), CSS(string=css)
示例#17
0
def export_all_diaries():
    user_name = request.form.get('user_name')
    files_location = DIARY_FOLDER + user_name

    diary_list = glob.glob(files_location + '/*')

    html_content = ''
    for file_location in diary_list:
        f = open(file_location)
        pdf_content = ''
        for l in f:
            pdf_content += l.rstrip()
        f.close()

        pdf_content = json.loads(pdf_content)
        if 'date' in pdf_content:
            html_content += '<h2>%s</h2>' % pdf_content['date']
        if 'content' in pdf_content:
            html_content += '<p>%s</p>' % pdf_content['content']

        html_content += '<img class="diary_image" src="/static/photos/%s/%s.jpg" />' % (
            user_name, pdf_content['date'])

    # return Response(
    #     diary_all,
    #     mimetype="text/csv",
    #     headers={"Content-disposition":
    #              "attachment; filename=diaries.json"})

    html = HTML(string=html_content)
    css = CSS(string='''
        @font-face {
            font-family: Gentium;
            src: url(http://example.com/fonts/Gentium.otf);
        }
        h1 { font-family: Gentium }
        .diary_image { width: 100%; }
        ''')

    # html.write_pdf(
    #     '/tmp/example.pdf', stylesheets=[css])

    return render_pdf(html, stylesheets=[css])
示例#18
0
def get_pdf(pdf_data):
    try:
        decoded_data = base64.b64decode(pdf_data).decode('utf-8')
    except binascii.Error:
        return jsonify({'error': 'Url not valid'}), 400
    data_dict = parse_qs(decoded_data.replace('?', ''))
    doc_id = data_dict['id'][0] if data_dict['id'] else None
    doc_lost = DocLost.query.get_or_404(doc_id)
    user = get_current_user()
    data = {
        'doc_lost': doc_lost,
        'history_objects': [],
        'user': user,
        'user_dep_name': user['dmsudep'].get(str(user.get('dmsudep_id', ''))),
        'ref_num': f'{doc_id}{time.strftime("%H%S%d%Y")}',
        'ref_date': time.strftime("%Y-%m-%d")
    }
    if data_dict.get('type') == ['full']:
        queryset = DocLostHistory.query.filter_by(source_id=doc_id).order_by(
            desc("created_at"))
        data['history_objects'] = get_history(doc_lost, queryset)

    def get_data_if_empty(obj_dict, name):
        result = obj_dict.get(name)
        if result is None or result is '':
            result = 'Не заповненно'
        return result

    def get_citizenship_if_empty(obj_dict, name):
        result = obj_dict.get(name)
        if result is None or result is '':
            result = 'Не заповненно'
        else:
            result = ', '.join([c['name'] for c in result])
        return result

    data['get_data_if_empty'] = get_data_if_empty
    data['get_citizenship_if_empty'] = get_citizenship_if_empty
    rendered_html = render_template('pdf_template.html', **data)
    rendered_css = render_template('pdf_styles.css')
    return render_pdf(HTML(string=rendered_html),
                      stylesheets=[CSS(string=rendered_css)])
示例#19
0
def create_quittance(date, date_paiement):
    "create pdf quittance"
    with open('data.json', 'r') as f:
        json_dict = json.load(f)
    splitdate = date.split('/')
    month_range = calendar.monthrange(int(splitdate[1]), int(splitdate[0]))
    firstday, lastday = month_range
    formatted_firstday = "01/" + date
    formatted_lastday = str(lastday) + "/" + date
    format = "%d/%m/%Y"
    today = datetime.now()
    today_str = today.strftime(format)
    for data in json_dict:
        html = render_template('quittance.html',
                               data=data,
                               firstday=formatted_firstday,
                               lastday=formatted_lastday,
                               today=today_str,
                               paymentdate=date_paiement)
        pdf = render_pdf(HTML(string=html))
        HTML(string=html, base_url='.').write_pdf(
            'quittance.pdf', stylesheets=[CSS(filename='static/style.css')])
示例#20
0
def pdf_verso():
    css = CSS(string='@page { size: 450mm 620mm; margin: 0.5cm; }')
    a3css = CSS(string='@page { size: A3; margin: 0.5cm; }')
    #return render_template('main-verso.html')
    html = render_template('main-verso.html')
    return render_pdf(HTML(string=html), stylesheets=[css])
示例#21
0
def render_contract(html):
    userstylesheet_url = url_for("static", filename='userStyles.css')
    cssfile = CSS(url_for("static", filename="sample.css"))
    if os.path.exists("flaskr/" + userstylesheet_url):
        cssfile = CSS(userstylesheet_url)
    return HTML(string=html).render(stylesheets=[cssfile])
示例#22
0
 def test_wrappers(self):
     with app.test_request_context(base_url='http://example.org/bar/'):
         # HTML can also be used with named parameters only:
         html = HTML(url='http://example.org/bar/foo/')
         css = CSS(url='http://example.org/bar/static/style.css')
     assert html.write_pdf(stylesheets=[css]).startswith(b'%PDF')
示例#23
0
def render_canvas_pdf():
    if request.method == 'POST':
        access_token = request.form['access_token']
        course_number = request.form['course_number']
        canvas_url = request.form['canvas_url']
        # Canvas API URL
        API_URL = canvas_url
        # Canvas API key
        API_KEY = access_token

        # Initialize a new Canvas object
        canvas = Canvas(API_URL, API_KEY)

        try:
            course = canvas.get_course(course_number, include='syllabus_body')
        except Exception as e:
            message = str(e.args[0]['errors'][0]['message'])
            if 'user not authorised to perform that action' in message:
                message = 'User not authorised to perform that action. Did you spell the course code correctly?'
            return render_template('error.html', message=message)

        def getmodulehtml(module, module_id):
            m = module.get_module_item(module_id)

            if m.type == "SubHeader":
                d = dict()
                d['toc'] = '<b><a href="#' + str(
                    module_id) + '">' + m.title + '</a></b>'
                d['title'] = m.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>' + m.title + '</h2><p style="page-break-before: always" ></p>'
                return d
            elif m.type == "Assignment":
                assignment = course.get_assignment(m.content_id)
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">Assignment: ' + assignment.name + '</a>'
                d['title'] = assignment.name
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>Assignment: ' + assignment.name + '</h2><br/>' + assignment.description + '<p style="page-break-before: always" ></p>'
                return d
            elif m.type == "Quiz":
                quiz = course.get_quiz(m.content_id)
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">Quiz: ' + quiz.title + '</a>'
                d['title'] = quiz.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>Quiz: ' + quiz.title + '</h2><br/>' + quiz.description + '<br/><a href=' + quiz.mobile_url + '>Link</a><p style="page-break-before: always" ></p>'
                return d
            elif m.type == "Page":
                page = course.get_page(m.page_url)
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">Page: ' + page.title + '</a>'
                d['title'] = page.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>Page: ' + page.title + '</h2><br/>' + page.body + '<p style="page-break-before: always" ></p>'
                return d
            elif m.type == "Discussion":
                discussion = course.get_discussion_topic(i.content_id)
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">Discussion: ' + discussion.title + '</a>'
                d['title'] = discussion.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>Discussion: ' + discussion.title + '</h2><br/>' + discussion.message + '<p style="page-break-before: always" ></p>'
                return d
            elif m.type == "File":
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">File: ' + m.title + '</a>'
                d['title'] = m.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>File: ' + m.title + '</h2><br/><a href="' + m.html_url + '">' + m.title + '</a><p style="page-break-before: always" ></p>'
                return d
            elif m.type == "ExternalUrl":
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">External url: ' + m.title + '</a>'
                d['title'] = m.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>External url: ' + m.title + '</h2><br/><a href="' + m.external_url + '">' + m.title + '</a><p style="page-break-before: always" ></p>'
                return d
            elif m.type == "ExternalTool":
                d = dict()
                d['toc'] = '&bull;<a href="#' + str(
                    module_id) + '">External tool: ' + m.title + '</a>'
                d['title'] = m.title
                d['html'] = '<a id="' + str(
                    module_id
                ) + '"></a><h2>External tool: ' + m.title + '</h2><br/><a href="' + m.html_url + '">' + m.title + '</a><p style="page-break-before: always" ></p>'
                return d

        ### CREATE HTML ###
        course_manual_html = '''
        <html><head><title>''' + course.name + '''</title></head><body>
        <p>&nbsp;</p>
        <span class="a"><h1>Course Manual</h1><br/>
        <h2>''' + course.name + ''' (''' + course.course_code + ''')</h2></span>
        '''

        type_list = ['teacher']
        users = course.get_users(enrollment_type=type_list)
        type_list2 = ['ta']
        users2 = course.get_users(enrollment_type=type_list2)

        course_manual_html += '<span class="b">'
        for user in users:
            course_manual_html += '<p>Teacher: ' + user.name + '</p>'
        for user2 in users2:
            course_manual_html += '<p>Teaching assistant: ' + user2.name + '</p>'
        course_manual_html += '</span><p style="page-break-before: always" ></p>'  # add page break

        course_manual_html += "<h1>Table of Contents</h1><br/>"

        toc_html = '<br/><h3><a href="#syllabus">Syllabus</a></h3><br/>'
        content_html = ""

        modules = course.get_modules()
        for m in modules:
            module = course.get_module(m.id)
            module_items = module.get_module_items()
            toc_html += '<a href="#' + str(
                m.id) + '"><h3>' + module.name + '</h3></a><br/>'
            content_html += '<a id="' + str(
                m.id
            ) + '"></a><h1>' + module.name + '</h1><p style="page-break-before: always" ></p>'
            for i in module_items:
                r = getmodulehtml(module, i.id)
                toc_html += r['toc'] + "<br/>"
                content_html += r['html']
        course_manual_html += toc_html + '</ul><p style="page-break-before: always" ></p>'
        course_manual_html += '<a id="syllabus"></a><h1>Syllabus</h1><br/>' + course.syllabus_body + '<p style="page-break-before: always" ></p>' + content_html
        course_manual_html += "</body></html>"

        ### CREATE CSS ###

        css = '''
           span.a {
                display: block;
                position: absolute;
                left: 100px;
                top: 100px;
            }
            span.b {
                display: block;
                position: absolute;
                left: 100px;
                top: 750px;
            }         
            html{font-family:Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif;font-size:100%;
            }
            img {
                width: auto;
                max-width: 100%;
                height: auto;
            }
            @page {
            @bottom-center{
                width: 30%;
                content: "Page " counter(page) " of " counter(pages);
            }
            @top-center {
                content: "Course Manual ''' + course.name + '''";
            }
        }
        '''
        cn = course.name
        file_name = cn.replace(" ", "_") + '.pdf'

        stylesheet = CSS(string=css)
        return render_pdf(HTML(string=course_manual_html),
                          stylesheets=[stylesheet],
                          download_filename=file_name)
示例#24
0
def print_pdf(inv_id):
    invoice = Invoices.query.get_or_404(inv_id)
    html = render_template('invoice_pdf.html', invoice=invoice)
    css = CSS(url_for('static', filename='invoice_pdf.css'))
    return render_pdf(HTML(string=html), stylesheets=[css])
示例#25
0
def exportPdf(template):
    font_config = FontConfiguration()
    THIS_FILE_DIR = os.path.dirname(os.path.abspath(__file__)) + os.sep
    base_url = 'file://' + THIS_FILE_DIR
    css = CSS(string='''
                        /* dropdown.css */
    
                        @import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300);
    
                        @prim: #53e3a6;
    
                        @font-face {
                          font-family: 'Source Sans Pro';
                          font-style: normal;
                          font-weight: 200;
                          src: url(https://fonts.gstatic.com/s/sourcesanspro/v14/6xKydSBYKcSV-LCoeQqfX1RYOo3i94_wlxdr.ttf) format('truetype');
                        }
    
                        @font-face {
                          font-family: 'Source Sans Pro';
                          font-style: normal;
                          font-weight: 300;
                          src: url(https://fonts.gstatic.com/s/sourcesanspro/v14/6xKydSBYKcSV-LCoeQqfX1RYOo3ik4zwlxdr.ttf) format('truetype');
                        }
    
                        .dropdown-content hover{
                          background-color:#3f6b68;
                        }
    
                        .dropdown {
                          position: relative;
                          display: inline-block;
                        }
    
                        .dropdown-select{
                          font-family: 'Source Sans Pro', sans-serif;
                          color: white;
                          margin-bottom: 20px;
                          background-color: #75CDB6;
                          border: 1px solid rgba(255, 255, 255, 0.4);
                          border-radius: 3px;
                          font-size: 16px;
                          font-weight: 300;
                          padding: 10px 0px 10px 0px;
                          width: 250px;
                          transition: border .5s;
                          text-align: left;
                        }
    
                        .dropdown-select:hover{
                          background-color: #75CDB6;
                        }
    
                        .dropdown-select:focus{
                          background-color: #75CDB6;
                          width: 300px;
                          color: white;
                        }
    
    
                        .dropdown-type{
                          margin-bottom: 20px;
                          /*align-content: left;*/
                          color: #75CDB6;
                          background-color: red;
                          border: 2px solid transparent;
                          border-radius: 3px;
                          font-size: 16px;
                          font-weight: 200;
                          padding: 10px 0px 10px 90px;
                          width: 230px;
                          transition: border .5s;
                          text-align: left;
                          margin-left: -5%;
                        }
    
                        .dropdown-content {
                          display: none;
                          position: absolute;
                          font-family: Didact Gothic;
                          color: #75CDB6;
                          background-color: #75CDB6;
                          min-width: 160px;
                          overflow: auto;
                          z-index: 2;
                        }
    
                        .dropdown-content a {
                          background-color: #75CDB6;
                          color: #75CDB6;
                          padding: 12px 16px;
                          text-decoration: none;
                          display: block;
                        }
    
                        .dropdown a:hover {
                          background-color: #75CDB6;
                        }
    
    
                        .resizing_select {
                          font-family: 'Source Sans Pro', sans-serif;
                          margin-bottom: 20px;
                          align-content: center;
                          background-color: #75CDB6;
                          border: 2px solid transparent;
                          border-radius: 3px;
                          font-size: 17px;
                          font-weight: 200;
                          padding: 3px 0px 3px 3px;
                          transition: border .5s;
                          color: white;
                        }
    
                        .resizingSelectEditMark {
                          font-family: 'Source Sans Pro', sans-serif;
                          align-content: center;
                          text-align: center;
                          border: 1px solid rgba(255, 255, 255, 0.4);
                          background-color: rgba(255, 255, 255, 0.2);
                          border-radius: 3px;
                          font-size: 18px;
                          font-weight: 300;
                          padding: 4px 0px 4px 4px;
                          margin: 0 0 10px 0;
                          transition: border .5s;
                          color: white;
                          height: 41px;
                        }
    
                        .resizingSelectEditMark:hover{
                          background-color: rgba(255, 255, 255, 0.4);
                        }
    
                        .resizingSelectEditMark:focus{
                          background-color: #75CDB6;
                          color: white;
                        }
    
                        #width_tmp_select{
                          display : none;
                        }
    
                        .text{
                          font-family: 'Source Sans Pro', sans-serif;
                          font-size: 19px;
                          font-weight: 200;
                        }
    
                        /* end of dropdown.css */
    
                        /* form.css */
    
                        @import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300);
    
                        @prim: #53e3a6;
    
                        *{
                            box-sizing: border-box;
                            margin: 0;
                            padding: 0;
                            font-weight: 300;
                        }
    
                        .customLabel{
                          text-align: left;
                          margin-left: 29%;
                        }
    
                        .fa-eye:before {
                          content: "\f06e";
                        }
                        .fa-eye-slash:before {
                          content: "\f070";
                        }
    
                        .customLabel2{
                          text-align: left;
                          margin-left: 29%;
                        }
    
                        .control-group {
                          margin-bottom: 20px;
                        }
    
                        .control-group2 {
                          margin-bottom: 8px;
                        }
    
                        .control-group3{
                          margin-bottom: 20px;
                          text-align: left;
                          height: 300px;
                          padding: 0 0.4em 0.4em 0;
                        }
    
    
                        @font-face {
                          font-family: 'Source Sans Pro';
                          font-style: normal;
                          font-weight: 200;
                          src: url(https://fonts.gstatic.com/s/sourcesanspro/v14/6xKydSBYKcSV-LCoeQqfX1RYOo3i94_wlxdr.ttf) format('truetype');
                        }
                        @font-face {
                          font-family: 'Source Sans Pro';
                          font-style: normal;
                          font-weight: 300;
                          src: url(https://fonts.gstatic.com/s/sourcesanspro/v14/6xKydSBYKcSV-LCoeQqfX1RYOo3ik4zwlxdr.ttf) format('truetype');
                        }
                        * {
                          box-sizing: border-box;
                          margin: 0;
                          padding: 0;
                          font-weight: 300;
                        }
                        body {
                          font-family: 'Source Sans Pro', sans-serif;
                          color: white;
                          font-weight: 300;
                        }
    
                        body ::-webkit-input-placeholder {
                          /* WebKit browsers */
                          font-family: 'Source Sans Pro', sans-serif;
                          color: white;
                          font-weight: 300;
                        }
                        body :-moz-placeholder {
                          /* Mozilla Firefox 4 to 18 */
                          font-family: 'Source Sans Pro', sans-serif;
                          color: white;
                          opacity: 1;
                          font-weight: 300;
                        }
                        body ::-moz-placeholder {
                          /* Mozilla Firefox 19+ */
                          font-family: 'Source Sans Pro', sans-serif;
                          color: white;
                          opacity: 1;
                          font-weight: 300;
                        }
                        body :-ms-input-placeholder {
                          /* Internet Explorer 10+ */
                          font-family: 'Source Sans Pro', sans-serif;
                          color: white;
                          font-weight: 300;
                        }
    
                        .wrapper {
                          z-index: 1;
                          background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
                          background-position: center;
                          background-repeat: no-repeat;
                          background-size: cover;
                          position: absolute;
                          top: 0;
                          left: 0;
                          width: 100%;
                          height: 100%;
                          overflow: hidden;
                        }
    
                        .wrapperError404{
                          z-index: 1;
                          background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
                          background-position: center;
                          background-repeat: no-repeat;
                          background-size: cover;
                          position: absolute;
                          top: 0;
                          left: 0;
                          width: 100%;
                          height: 100%;
                          overflow: hidden;
                        }
    
                        .wrapperMarks {
                          z-index: 1;
                          background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%) no-repeat center;
                          background-size: cover;
                          position: absolute;
                          top: 0;
                          left: 0;
                          width: 100%;
                          height: 100%;
                          overflow: scroll;
                        }
    
                        .wrapper.form-success .container h1 {
                          transform: translateY(85px);
                        }
    
                        .container {
                          max-width: 600px;
                          margin: 0 auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                        }
    
                        .containerPageNotFound{
                          position: absolute;
                          top: 35%;
                          left: 45%;
                          margin-top: -50px;
                          margin-left: -50px;
                          height: 100px;
                          text-align: center;
                          z-index: 2;
                        }
    
                        .container-marks {
                          max-width: 600px;
                          margin: -120px auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                        }
    
                        .container-editMarks{
                          max-width: 600px;
                          margin: -120px 900px 0px auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                        }
    
                        .container-absence{
                          max-width: 600px;
                          margin: -120px 900px 0px auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                        }
    
                        .container-student {
                          max-width: 600px;
                          margin: -150px auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                        }
    
                        .container-laboratories {
                          max-width: 600px;
                          margin: -150px auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                        }
    
                        .containerExportedData{
                          max-width: 600px;
                          margin: -150px auto;
                          padding: 250px 0;
                          height: 400px;
                          text-align: center;
                          z-index: 2;
                        }
                        .container h1 {
                          font-size: 40px;
                          transition-duration: 1s;
                          transition-timing-function: ease-in-put;
                          font-weight: 200;
                        }
    
                        form {
                          padding: 20px 0;
                          position: relative;
                          z-index: 2;
                        }
    
                        .form-student{
                          margin-top: -130px;
                        }
    
                        .login-button{
                          color: #50a3a2;
                          background-color: #ECF0F1;
                        }
    
                        .login-button:hover{
                          color: white;
                          background-color: #53e3a6;
                        }
    
                        form input {
                          -webkit-appearance: none;
                             -moz-appearance: none;
                                  appearance: none;
                          outline: 0;
                          border: 1px solid rgba(255, 255, 255, 0.4);
                          background-color: rgba(255, 255, 255, 0.2);
                          width: 250px;
                          border-radius: 3px;
                          padding: 10px 15px;
                          margin: 0 auto 10px auto;
                          display: block;
                          text-align: center;
                          font-size: 18px;
                          color: white;
                          transition-duration: 0.25s;
                          font-weight: 300;
                        }
    
                        form input:hover {
                          background-color: rgba(255, 255, 255, 0.4);
                        }
    
                        form input:focus {
                          background-color: #47c7a8;
                          width: 300px;
                          color: white;
                        }
    
                        form button {
                          -webkit-appearance: none;
                             -moz-appearance: none;
                                  appearance: none;
                          outline: 0;
                          background-color: #ff0000;
                          border: 0;
                          padding: 10px 15px;
                          color: white;
                          border-radius: 3px;
                          width: 250px;
                          cursor: pointer;
                          font-size: 18px;
                          transition-duration: 0.25s;
                        }
                        form button:hover {
                          background-color: #f5f7f9;
                        }
    
                        .bg-bubbles {
                          position: absolute;
                          top: 0;
                          left: 0;
                          width: 100%;
                          height: 100%;
                          z-index: 1;
                        }
    
                        .bg-bubbles li{
                          position: absolute;
                          list-style: none;
                          display: block;
                          width: 40px;
                          height: 40px;
                          background-color: rgba(255, 255, 255, 0.15);
                          bottom: -160px;
                          -webkit-animation: square 25s infinite;
                          animation: square 25s infinite;
                          transition-timing-function: linear;
                        }
    
                        .bg-bubbles li:nth-child(1) {
                          left: 10%;
                        }
    
                        .bg-bubbles li:nth-child(2) {
                          left: 20%;
                          width: 80px;
                          height: 80px;
                          -webkit-animation-delay: 2s;
                                  animation-delay: 2s;
                          -webkit-animation-duration: 17s;
                                  animation-duration: 17s;
                        }
    
                        .bg-bubbles li:nth-child(3) {
                          left: 25%;
                          -webkit-animation-delay: 4s;
                                  animation-delay: 4s;
                        }
    
                        .bg-bubbles li:nth-child(4) {
                          left: 40%;
                          width: 60px;
                          height: 60px;
                          -webkit-animation-duration: 22s;
                                  animation-duration: 22s;
                          background-color: rgba(255, 255, 255, 0.25);
                        }
    
                        .bg-bubbles li:nth-child(5) {
                          left: 70%;
                        }
    
                        .bg-bubbles li:nth-child(6) {
                          left: 80%;
                          width: 120px;
                          height: 120px;
                          -webkit-animation-delay: 3s;
                                  animation-delay: 3s;
                          background-color: rgba(255, 255, 255, 0.2);
                        }
    
                        .bg-bubbles li:nth-child(7) {
                          left: 32%;
                          width: 160px;
                          height: 160px;
                          -webkit-animation-delay: 7s;
                                  animation-delay: 7s;
                        }
    
                        .bg-bubbles li:nth-child(8) {
                          left: 55%;
                          width: 20px;
                          height: 20px;
                          -webkit-animation-delay: 15s;
                                  animation-delay: 15s;
                          -webkit-animation-duration: 40s;
                                  animation-duration: 40s;
                        }
    
                        .bg-bubbles li:nth-child(9) {
                          left: 25%;
                          width: 10px;
                          height: 10px;
                          -webkit-animation-delay: 2s;
                                  animation-delay: 2s;
                          -webkit-animation-duration: 40s;
                                  animation-duration: 40s;
                          background-color: rgba(255, 255, 255, 0.3);
                        }
    
                        .bg-bubbles li:nth-child(10) {
                          left: 90%;
                          width: 160px;
                          height: 160px;
                          -webkit-animation-delay: 11s;
                                  animation-delay: 11s;
                        }
    
                        @-webkit-keyframes square {
                          0% {
                            transform: translateY(0);
                          }
                          100% {
                            transform: translateY(-700px) rotate(600deg);
                          }
                        }
                        @keyframes square {
                          0% {
                            transform: translateY(0);
                          }
                          100% {
                            transform: translateY(-700px) rotate(600deg);
                          }
                        }
    
                        .span{
                          color: red;
                        }
    
                        .show{
                            position: relative;
                            right: -110px;
                            top: -40px;
                        }
    
                        .input_upload{
                          -webkit-appearance: none;
                             -moz-appearance: none;
                                  appearance: none;
                          outline: 0;
                          border: 1px solid rgba(255, 255, 255, 0.4);
                          background-color: rgba(255, 255, 255, 0.2);
                          width: 270px;
                          border-radius: 3px;
                          padding: 10px 15px;
                          margin: 0 auto 10px auto;
                          display: block;
                          text-align: center;
                          font-size: 18px;
                          color: white;
                          transition-duration: 0.25s;
                          font-weight: 300;
                        }
    
                        .hiddenLabel{
                          color: #53D0A5;
                        }
    
                        .h1align{
                          text-align: right;
                        }
    
                        .error404{
                          margin-top: 300px;
                          text-align: center;
                        }
    
                        .redirect{
                          font-size: 30px;
                        }
    
                        /* end of form.css */
    
                        /* sidenav.css */
    
                        .sidenav {
                          height: 100%;
                          width: 0px;
                          position: fixed;
                          z-index: 3;
                          top: 0;
                          left: 0;
                          background-color: #111;
                          overflow-x: hidden;
                          transition: 0.5s;
                          padding-top: 0px;
                        }
    
                        .sidenav a {
                          padding: 8px 8px 8px 32px;
                          text-decoration: none;
                          font-size: 25px;
                          color: #818181;
                          display: block;
                          transition: 0.3s;
                        }
    
                        .sidenav a:hover {
                          color: #f1f1f1;
                        }
    
                        .sidenav .closebtn {
                          position: absolute;
                          top: 0;
                          right: 25px;
                          font-size: 36px;
                          margin-left: 50px;
                        }
    
                        @media screen and (max-height: 450px) {
                          .sidenav {padding-top: 15px;}
                          .sidenav a {font-size: 18px;}
                        }
    
                        #mySidenav{
                            padding-top: 40px;
                        }
    
                        .menu{
                          z-index:2;
                          font-size: 30px;
                          cursor:pointer;
                          color: #000000;
                          position: absolute;
                          padding: 50px 50px 50px 50px;
                        }
    
                        /* end of sidenav.css */
    
                        /* table.css */
    
                        table {
                          font-family: 'Source Sans Pro', sans-serif;
                          border-collapse: collapse;
                          table-layout: auto;
                          width: 100%;
                          letter-spacing: 1px;
                        }
    
                        table td {
                            border: 1px solid #ccc;
                        }
    
                        td,
                        th {
                            border: 1px solid #dddddd;
                            padding: 10px;
                        }
                        th{
                            background: #25a37e;
                            font-weight: bold;
                        }
    
                        td {
                            text-align: center;
                        }
    
                        #deleteBin{
                            margin: -20px 0px -23px 107px;
                        }
    
                        /* end of table.css */
                        ''', font_config=font_config, base_url=base_url)
    html = HTML(string=template)
    html.write_pdf(target='exports/export.pdf', stylesheets=[css])
示例#26
0
def pdf_main():

    css = CSS(string='@page { size: 450mm 620mm; margin: 0.3cm; }')
    a3css = CSS(string='@page { size: A3; margin: 0.5cm; }')
    html = render_template('main.html', temps=temp_table(), pa=pa_table())
    return render_pdf(HTML(string=html), stylesheets=[css])