Hello,
I generate a PDF by using a CLI command calling a python script and my custom font is not rendered in the producted pdf. (See attachements)
If I export manually in pdf by using the Scribus menu it works.
So I must have a problem with my CLI command or the python export code.
Following is th CLI command called by a Python program. Just for info, this python program fill the sla from a calc file replacing placeholder by the content of calc cell keeping formating (color, bold, italic) at word level.
import subprocess
subprocess.check_output(['C:\Program Files\Scribus 1.5.8\Scribus.exe','-g','-ns',"-py","to-pdf.py",'--',str(fileOut)], shell=True)
The python code "to-pdf.py" is here (don't remember where it come from, maybe the wiki) :
# Produces a PDF for the SLA passed as a parameter.
# Uses the same file name and replaces the .sla extension with .pdf
#
# usage:
# scribus -g -py to-pdf.py -- file.sla
#
# license:
# (c) MIT Ale Rimoldi
import os
import scribus
if scribus.haveDoc() :
filename = os.path.splitext(scribus.getDocName())[0]
pdf = scribus.PDFfile()
pdf.file = filename+".pdf"
pdf.save()
else :
print("No file open")
Thank you for your help
hi zacl
some wild guesses:
how did you add the custom font?
there might be a problem with the system variables and, when run from the script, scribus might not see it.
and how are you replacing the placeholders?
you might be breaking things, if you're manipulating the .sla directly...
Thank you for the quick answer :)
The custom font is a TFF font installed like a font you can download on the net (Double clic and select install with windows font manager). By coping the example below i see that font from internet don't work either ( emoji Regular).
My code replace the placeholder (that is a number, below it is "25") by the corresponding text processed in order to include styles and specific fonts.
I don't think I break things (I can be wrong :) ) cause it works when not automated for all of the generated pages (102 pages). I have to try with a file manually made.
Sla files are in attachement. I tried to put fontt but it don't work.
Model with number as placeholder :
<StoryText>
<DefaultStyle PARENT="Titre3 Summary Blanc"/>
<ITEXT CH="25"/>
<trail PARENT="Titre3 Summary Blanc" ALIGN="2"/>
</StoryText>
Processed code including instead of the placeholder 25
<StoryText>
<DefaultStyle PARENT="Titre3 Summary Blanc"/>
<ITEXT FONT="Oregon LDO Bold" CH="8 - BLEU "/>
<ITEXT FONT="emoji Regular" CH="🎲"/>
<trail PARENT="Titre3 Summary Blanc" ALIGN="2"/>
</StoryText>
I found the solution.
I had to configure the pdf export python file to-pdf.py to embed Unicode TTF font in pdf as vector with this line :
pdf.fontEmbedding = 1
The code come from Scripter API found here https://gitlab.com/scribus/scribus/-/blob/master/doc/en/scripterapi-PDFfile.html (https://gitlab.com/scribus/scribus/-/blob/master/doc/en/scripterapi-PDFfile.html) cause the link in the wiki don't work https://wiki.scribus.net/canvas/Command_line_scripts#Full_.27export_document_to_PDF_with_options_for_the_PDF_type.27 (https://wiki.scribus.net/canvas/Command_line_scripts#Full_.27export_document_to_PDF_with_options_for_the_PDF_type.27):
QuotefontEmbedding = <attribute 'fontEmbedding' of 'PDFfile' objects>
Choose the font embedding mode :
0 - Embed fonts fully or as subset depending on 'fonts' attribute
1 - Outline fonts: fonts will be converted to vector
2 - No embedding: no font will be embedded.
I think the problem come from the (Unicode?) font as said here https://wiki.scribus.net/canvas/Help:Manual_Fontsconfig (https://wiki.scribus.net/canvas/Help:Manual_Fontsconfig) :
Quote
OpenType Fonts - Unicode True Type Fonts cannot be fully embedded by default. This greatly simplifies handling them in other applications. OpenType Fonts and Unicode TrueType Fonts can be quite large, some larger than 10 Mb... OpenType Fonts/Unicode True Type Fonts are exported as outlines in PDF. This allows them to be used in PDF, where often other applications cannot use them. Moreover, embedding Open Type fonts is only supported in PDF 1.6+ (Acrobat 7.0.x) and this technology is quite new.
Attachment for previous messages was missing, so it is there with the pdf working result.
---
Full code :
# Produces a PDF for the SLA passed as a parameter.
# Uses the same file name and replaces the .sla extension with .pdf
#
# usage:
# scribus -g -py to-pdf.py -- file.sla
#
# license:
# (c) MIT Ale Rimoldi
import os
import scribus
if scribus.haveDoc() :
filename = os.path.splitext(scribus.getDocName())[0]
pdf = scribus.PDFfile()
pdf.file = filename+".pdf"
pdf.fontEmbedding = 1
pdf.save()
else :
print("No file open")
hi zacl
nice to see that you sorted this out.
if you're using a current version of scribus, this is a bug you might want to report to https://bugs.scribus.net .
embedding the fonts should be the default, also when the pdf is exported through a script.
ciao
a.l.e
In fact I just noticed all my text was converted and I wanted only the missing characters to be outlined. So I'm not done. :-[
So I did some digging and the export works well directly for some just downloaded and installed font.
Simbola works : https://fontlibrary.org/fr/font/symbola
But it didn't work for following experimental one (emoji) and mine that were both used in p102 I attached :
https://github.com/jslegers/emoji-icon-font/tree/master/fonts
It may be a bug like you said cause it works when made manually and not automaticly.
I searched in the source code but I have hard time finding the part in cause. Here? https://github.com/scribusproject/scribus/blob/185141911977459c2399b96480f1345f1ff7fd44/scribus/plugins/scriptplugin/objpdffile.cpp#L1408
Maybe I have to give the list of font to embed with the "font" method : https://impagina.org/scribus-scripter-api/pdf-export/
I have found a solution with a kind of "black magic" manipulation of the file 8)
It is not automated because I have to manually configure and save the file once between 2 call of PDF generation script ???
So my case this case is not solved but it can indicate a configuration or setup needed for it to work.
I reproduced this procedure with a new file that contain only the dice character using emoji font.
Using my trick I noticed a modification in the sla at 'PDF' part.
- FirstUse is set to 0
- Subset of font are added
- An unamed color appeared ?
After that the automatic generation works
Part of the modifcated code :
<PDF firstUse="0" ...>
<Subset Name="Arial Regular"/>
<Subset Name="emoji Regular"/>
<LPI Color="" Frequency="133" Angle="45" SpotFunction="3"/>
|
<LPI Color=.../>
</PDF>
So, in the end, only "subset part " is usefull to succesfully export to pdf.
To generate them in the sla file :
- I manually open the file and export to pdf with embed/subset
- I save and close the file (subsets are written in sla file)
After that I can call the script to-pdf.py to generate a pdf with font embeded.
I will open a bug report cause it must embed font directly. PDF().fonts methods must be usefull to declare subset but I didn't managed to make it work
I managed to embed font ;D
I pass the name of the font in "pdf.subsetList" (not yet documented) instead of "pdf.fonts" and it worked!
SubsetList code here : https://github.com/scribusproject/scribus/blob/185141911977459c2399b96480f1345f1ff7fd44/scribus/plugins/scriptplugin/objpdffile.cpp#L1398
import os
import scribus
if scribus.haveDoc() :
filename = os.path.splitext(scribus.getDocName())[0]
pdf = scribus.PDFfile()
#pdf.fonts = ["emoji Regular"]
pdf.subsetList = ["emoji Regular","Middara Regular"]
pdf.file = filename+"-direct.pdf"
pdf.save()
else :
print("No file open")
Bug Report submited https://bugs.scribus.net/view.php?id=16885