我收集了一堆domino games并将它们发布为我使用 reportlab 生成的 PDF。现在,我正在考虑出版一本纸质书要花多少钱,但 Lulu 提示我的 PDF:
Fonts: We found some fonts in your file that need to be embedded. Please review your PDF and make sure all Fonts are embedded.
我使用了 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 FAQ描述了对我不起作用的内置字体,但它也解释了如何嵌入其他字体。我尝试了 reportlab 中包含的两种字体,Lulu 接受了 PDF。
为了有两种以上的字体可供选择,我从 Google Fonts 下载了一些这里有一个很好的搜索功能,可以推荐字体配对。
这是使用我下载的两种字体的最终代码:
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()
关于python - Lulu 希望在我的 reportlab PDF 中嵌入字体以出版一本书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67140620/