Closed jaguarxii closed 1 month ago
You should be able to do this as long as there is a way to load the font in the html enclosing the chart.
A quick search for me turned out that this must be done via css (https://stackoverflow.com/questions/64508137/how-to-use-ttf-as-font-family-in-html). You can include such a css file in your chart output head tags by usingh the DisplayOptions
API just as it is done here for the bulma stylesheet.
Hi, in my use case there is no web page for the chart, I need the svg-rendered chart so it can be embedded into a pdf file (server-side).
it is really strange because using a proper linux distro (debian 12) there is no font for the charts (squares instead of letters), using a wsl instance (debian 11) i got proper letters (dejavusansmono)
somehow it takes a "default font" from the wsl instance eventhough x-server is not installed.
Hi, in my use case there is no web page for the chart, I need the svg-rendered chart so it can be embedded into a pdf file (server-side).
You will still need the html page to display properly, because rendering as svg is done in a headless browser. So i would expect everything to work once you manage the chart to reference the font via css
could you maybe attach the svg that has no font as well? maybe that helps narrowing it down
Here is the sample SVG
it seems a valid file, but when it is attached to the PDF it has wrong letters (font)
it seems a valid file, but when it is attached to the PDF it has wrong letters (font)
Are you creating that pdf programmatically? You can include fonts in pdfs, so that might be a solution for you.
I did some digging and this is not natively supported in plotly.js either (see here for reference). This means you have to either patch the generated SVG or the PDF with your custom font if you want to make the files self contained.
Hi @kMutagene, thanks for the references, will test and come back with the results
The PDF file is created programmatically using QuestPDF (already created an issue about this behavior), it includes the fonts that are required. QuestPDF Issue
Using Plotly.js (client side) I had no troubles creating PDFs using pdfmake, the approach was the same, render the chart in SVG format then embed in the PDF document.
Using Plotly.js (client side) I had no troubles creating PDFs using pdfmake, the approach was the same, render the chart in SVG format then embed in the PDF document.
Could you maybe also attach that pdf that is working here? maybe we can spot a difference between the 2
As I've mentioned in the linked QuestPDF issue, I have the same issue with QuestPDF and ScottPlot 5, so it might be an issue on the QuestPDF side.
closed as this seems to be an external issue
Description
Currently only installed fonts are available for styling charts, it would be very helpful to load custom fonts from its source such as TTF, WOFF fonts (other formats are also welcome).
Repro steps
I created a c# project using dotnet8, plptly.net 4.2, Plotly.NET.ImageExport 5.0.1, this is the code for a basic chart:
` // Creating a bar trace Plotly.NET.Trace barTrace = new Plotly.NET.Trace("bar");
`
. in a windows environment there is no trouble to get the chart with its labels . In a linux environment there are no labels, instead empty squares
Expected behavior
It would be very useful to load an arbitrary font from its source file, similar to a Font-face setting in a web page.
for instance:
layout.SetValue("font", Font.init(Family:FontFamily.NewCustom("DejaVu Serif", "font_file_path")))
Related information