Python Lulu想在我的reportlab PDF中嵌入字体来出版一本书

Python Lulu想在我的reportlab PDF中嵌入字体来出版一本书,python,pdf,fonts,reportlab,Python,Pdf,Fonts,Reportlab,我收集了大量的数据,并将它们发布为PDF格式,由reportlab生成。现在,我在考虑出版一本纸质书要花多少钱,但露露抱怨我的PDF: 字体:我们在您的文件中发现一些需要嵌入的字体。请检查您的PDF,并确保所有字体都已嵌入 我使用了Acrobat Reader内置的字体,比如Helvetica,所以我认为它们可以在任何地方使用 下面是一个让露露抱怨的简单例子: from subprocess import run from reportlab.lib import pagesizes from

我收集了大量的数据,并将它们发布为PDF格式,由reportlab生成。现在,我在考虑出版一本纸质书要花多少钱,但露露抱怨我的PDF:

字体:我们在您的文件中发现一些需要嵌入的字体。请检查您的PDF,并确保所有字体都已嵌入

我使用了Acrobat Reader内置的字体,比如Helvetica,所以我认为它们可以在任何地方使用

下面是一个让露露抱怨的简单例子:

from subprocess import run

from reportlab.lib import pagesizes
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph


def main():
    pdf_path = 'booklet.pdf'
    doc = SimpleDocTemplate(pdf_path,
                            pagesize=pagesizes.letter,
                            topMargin=0.625*inch,
                            bottomMargin=0.625*inch)
    styles = getSampleStyleSheet()
    normal_style: ParagraphStyle = styles['Normal']
    custom_style = ParagraphStyle('custom',
                                  parent=normal_style,
                                  fontSize=300,
                                  leading=360)
    story = []
    for i, text in enumerate('ABCDEFGH'):
        flowable = Paragraph(text, custom_style)
        story.append(flowable)

    doc.build(story)

    # run(["evince", pdf_path], check=True)  # launch PDF viewer


main()
如何嵌入字体以便Lulu接受我的PDF?

介绍了不适合我的内置字体,但也说明了如何嵌入其他字体。我尝试了reportlab附带的两种字体,Lulu接受了PDF

为了有两种以上的字体可供选择,我从那里下载了一些,那里有一个很好的搜索功能,可以推荐字体配对

下面是使用我下载的两种字体的最终代码:

from subprocess import run

from reportlab.lib import pagesizes
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.pdfbase import pdfmetrics


def main():
    pdf_path = 'booklet.pdf'
    doc = SimpleDocTemplate(pdf_path,
                            pagesize=pagesizes.letter,
                            topMargin=0.625*inch,
                            bottomMargin=0.625*inch)
    fredoka_file = 'fonts/Fredoka_One/FredokaOne-Regular.ttf'
    raleway_file = 'fonts/Raleway/static/Raleway-Regular.ttf'
    pdfmetrics.registerFont(TTFont("Fredoka", fredoka_file))
    pdfmetrics.registerFont(TTFont("Raleway", raleway_file))
    styles = getSampleStyleSheet()
    normal_style: ParagraphStyle = styles['Normal']
    header_style = ParagraphStyle('Fredoka',
                                  parent=normal_style,
                                  fontName='Fredoka',
                                  fontSize=300,
                                  leading=360)
    body_style = ParagraphStyle('Raleway',
                                parent=normal_style,
                                fontName='Raleway',
                                fontSize=30,
                                leading=36)
    story = []
    for i, text in enumerate('ABCDEFGH'):
        if i % 2 == 0:
            custom_style = header_style
        else:
            custom_style = body_style
        flowable = Paragraph(text, custom_style)
        story.append(flowable)

    doc.build(story)

    # run(["evince", pdf_path], check=True)  # launch PDF viewer


main()