I'm trying to display data with TCPDF from my DB which were specifically indented.
I use a writeHTMLCell to do so.
e.g. :
"This should be indented as so :
- First bullet
- Second one
Then the end of the example."
But of course, it render the text on a single line.
Does anyone know how i can render the text properly ?
Thank you very much !
With HTML preformatted text requires that you use <pre>. Here is an example:
This should be indented as so:
- First bullet
- Second one
Then the end of the example.
<pre>
This should be indented as so:
- First bullet
- Second one
Then the end of the example.
</pre>
Using <pre> tags with the preformatted text block should achieve the result you are looking for. Preformatted text defaults to a monospaced font and can be changed with $pdf->SetDefaultMonospacedFont(). Here is an example with and without <pre>:
<?php
require_once('tcpdf_include.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
$text_sample = 'This should be indented as so:
- First bullet
- Second one
Then the end of the example.';
$y = $pdf->getY();
$pdf->SetDefaultMonospacedFont('helvetica');
$pdf->SetFont('helvetica', '', 14, '', true);
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(255, 92, 92);
$pdf->writeHTMLCell(190, '', '', $y, $text_sample, 1, 0, 1, true, 'J', true);
$pdf->SetTextColor(53,183,41);
$pdf->writeHTMLCell(190, '', '', $y+20, '<pre>'.$text_sample.'</pre>', 1, 1, 1, true, 'J', true);
$pdf->Output('example.pdf', 'I');
The PDF will contain the following cells:
Related
I am in the finishing stages of my first real Plotly Dash dashboard. I have run into a problem where I can't add dcc.Markdown to any dcc.Graph elements.
It works fine with the dash.DataTable, as shown in the image below.
I am using Python v3.10, Dash v 2.6.2 & Plotly 5.10.
I tried to then use the same methodology to add markdown to the chart next to it, but this throws an error
TypeError: The dash_bootstrap_components.Col component (version
1.2.1) with the ID "Graph(id='sun_burst1', figure={}, style={'height': '45vh'})" detected a Component for a prop other than children Prop
id has value Graph(id='sun_burst1', figure={}, style={'height':
'45vh'})
The DataTable is inside a Row and Col. The code is as follows. I haven't closed it below as it runs on for quite some time
dbc.Row(
# Dash Data Table
[dbc.Col(
[dcc.Markdown('### Top Risks ###'),
dash_table.DataTable(
id='table1',
columns=[
{'name': 'Risk ID', 'id': 'risk_id', 'type': 'text', 'editable': False},
Here is my erroneous code, Am I barking up the wrong Tree, does Markdown even work with dcc.Graph.
dbc.Col(
[dcc.Markdown('### Risk Breakdown ###'),
dcc.Graph(id='sun_burst1', figure={}, style={'height': '45vh'}),
width=4, lg={'size': 5, "offset": 0, 'order': 'second'}
]),
I really am quite stumped.
My page is made up of 2 rows, top row with 3 columns of width 4, Bottom Row 2 x 6 columns.
The answer was simple in the end. I had not taken into consideration where the 'children' ended.
I had the following which did not work. Note the terminating square bracket after the complete definition.
dbc.Col(
[dcc.Markdown('#### Breakdown of Risk by Risk Type - 2021 ####'),
dcc.Graph(id='sun_burst1', figure={}, style={'height': '40vh'})],
width=4, lg={'size': 5, "offset": 0, 'order': 'second'}
]),
Ther solution is as follows. encase the 'children in square brackets and leave the other column definitions outside.
Solution:
dbc.Col(
[dcc.Markdown('#### Breakdown of Risk by Risk Type - 2021 ####'),
dcc.Graph(id='sun_burst1', figure={}, style={'height': '40vh'})],
width=4, lg={'size': 5, "offset": 0, 'order': 'second'}
),
With this in place, I can now mark up my charts as I wish.
A big thank you to jinnynor at Plotly community for provoking my thoughts
I have a line break \n in a string that I'm reading from my sqflite row (the specific column data type is TEXT) through the bloc state, and am trying to display it within a TextSpan-
RichText(
text: TextSpan(
text: _state.feedback, //this is the string
style: TextStyle(
fontSize: 20,
color: Colors.black
)
),
)
When doing this, it just renders onscreen as the literal some text \n some text, but if I hardcode the same string as the text value instead of reading from the bloc state, eg:
RichText(
text: TextSpan(
text: "some text \n some text"
style: TextStyle(
fontSize: 20,
color: Colors.black
)
),
)
I've tried with just a plain Text(_state.feedback) widget as well, and I get the exact same behaviour.. line break works correctly when I hard-code the text value, but won't break when reading the string from the column value.
Has anyone else experienced this or can see something I'm doing wrong?
Have you tried it like this:
text: "${_state.feedback}",
I hope it works for you.
Try this. It should work.
text: _state.feedback.replaceAll(r'\n', '\n'),
I'm trying to put a script into jade, but it won't let me use multiple curly braces. Here is the chartist code I am trying to put in jade.
body
h1 Crimes by Category
.ct-chart
script(new Chartist.Bar('.ct-chart', {
labels: ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'],
series: [20, 60, 120, 200, 180, 20, 10]
}, {
distributeSeries: true
});)
I am getting Duplicate attribute "{" is not allowed. I don't know how to get around this. Any help would be appreciated.
To insert multi-line javascript in Jade, use the script. tag (with the content of the script indented):
body
h1 Crimes by Category
.ct-chart
script.
new Chartist.Bar('.ct-chart', {
labels: ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'],
series: [20, 60, 120, 200, 180, 20, 10]
}, {
distributeSeries: true
});
You probably also need to indent script. one notch if you want it inside your .ct-chart div.
source: How can I render inline JavaScript with Jade?
I have used mpdf to output some html to a pdf. I am not sure why mpdf is not inserting a top or right margin on the PDF yet the left side seems to have one:
I want to just have the content in the horiztonal center as it is cutting off text on the right. I also want to have a top margin as top content is being cut off.
Here is the settings I have set right now:
$mpdf = new mPDF('win-1252', 'Letter', '', '', 10, '', '', '', '', '');
$mpdf->useOnlyCoreFonts = true;
$mpdf->SetDisplayMode('fullpage');
I switched my declaration to the following:
$mpdf = new mPDF('win-1252','Letter', 12, '', 10, 10, 10, 10);
This correctly set the margins.
At first i thought TCPDF's GetStringWidth() was not working right, giving me the wrong width:
[----------------------------------------------------------------------------------------------------------------------]
I have some text like $txt = "hallo".
I've tried to get the strings width via the built in function GetStringWidth()
and then create a cell with the strings width.
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setFontSubsetting(true);
$pdf->AddPage();
$pdf->SetFont('times', '', 20);
$pdf->SetCellPadding(0);
$txt = "hey i'm santa clause";
$width = $pdf->GetStringWidth($txt);
$pdf->Cell($width, $h=0, $txt, $border=1, $ln=0, $align='', $fill=false, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M');
$pdf->Output('example_001.pdf', 'I');
?>
The created cell however is to short for it's content.
If I try the same with courier it works fine.
I think it's a measure of GetStringWidth not processing the font's width right, cause of Courier having the same width for each character, which works.
How can I get GetStringWidth() working
[----------------------------------------------------------------------------------------------------------------------]
Today I tried opening it with Firefox/Evince instead of chrome
Here's the result:
Firefox is on the left, chrome on the right.
The generated PDF file is v. 1.7
Used version of chrome:
google-chrome-beta (41.0.2272.53-1)
What could have gone wrong here? Is it really chromes fault? Or am I missing somethign here?
Thanks
You must try with replacing:
$pdf->Output("{$filename}.pdf", 'I');
with
$pdf->Output("{$filename}.pdf", 'D');