I'm using FPDF to generate PDF. I use a PDF template created on Adobe Acrobat that include form inputs.
I've been using the following code to generate my pdf :
<?php
***************************
Sample using a PHP array
****************************/
require('fpdm.php');
$fields = array(
'date' => '07/07/2017',
'names' => 'Something',
);
$pdf = new FPDM('Singlepage.pdf');
$pdf->Load($fields, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output();
?>
It's working perfectly but now i'd like to add multiples lines to my "names" form. Something like 'names' => 'Someone1 \n Someone2But I can't figure out how to do it.
On my pdf template, I added the "multiples lines" to the text input.
Do you have any idea ?
And then i'd like to format this text, so I could add bold, italic etc to the text
The problem are the single quotes, change to double quotes and it will work (if the field is multi-line, of course):
$fields = array(
'date' => '07/07/2017',
'names' => "Something \n more",
);
Related
How can disable encode html in ActiveForm::Dropdown active form Yii2?
I want to create a select html tag that shows multilevel data so that children make fixed padding than its parents. So, I create an array like this:
$items = [
'Computer'
' Hardware'
' Software',
' Programming'
'&nbps; C#'
];
But space is removed and &nbps; encoded and both not worked. We can use pure html tag, but how can create it using Yii2::ActiveField?
Note that we can encode items before calling widget based on our conditions.
There is any idea?!
To retain the spaces,
echo $form->field($model, 'attribute')->dropDownList($data, [
'encodeSpaces' => true,
]);
I want to create a form in Drupal 7 similar to what it is in the following link : https://bmicalculator.cc/?gclid=CIrvnaXv1MQCFQwnjgodvWgAlQ
Form should start with text "BMI Calculator", then 2 columns similar in link and then note text similar to "BMI can be inaccurate for people..."
I know little bit Drupal Form Api so that I can create form but how to display text at the top, how to create form in 2 columns and then again text after form.
I am new to Drupal and hence don't have deep understanding of how drupal works.
To display the text at top, use the #markup item in the form render array. You can then embed the html that you need in this markup.
For the two columns, use the #container type in your form render array. This allows you to wrap a <div> around the child elements. You can then float the div as needed.
So an example would be
$form = array(
/*
* ... form header info here
*/
'header' => array(
'#markup'=>'<h1> BMI Calc </h1>',
),
'col1'=>array(
'#type'=>'container',
'subitemA'=>array(
//some stuff
),
'subitemB'=>array(
//some stuff
),
'#attributes' => array(
'class' => array('class-name'), //use css to float left
//alternatively float left using style in this area
),
),
'col2'=>array(
'#type'=>'container',
'subitemA'=>array(
//some stuff
),
'subitemB'=>array(
//some stuff
),
'#attributes' => array(
'class' => array('class-name'), //use css to float left
//alternatively float left using style in this area
//NOTE: still float left, the divs will align as two columns unless
//screen space is too small, then it will stack responsively.
),
),
);
Hope this helps.
I'm using the FormServiceProvider in Silex to generate my forms.
Now I want to put a default text in a generated textarea.
(not a placeholder! && the attribute 'value' I use on my textfields doens't work on a textarea)
I know the text in a textarea is between the tags,
but I don't find an option to fill this tags with my FormServiceProvider.
Is it possible?
Example code:
$form = $app['form.factory']->createNamed('form')
->add('description', 'textarea',
array('attr (??)' => array(' ??? (not placeholder or value!!) ??? ' => 'Default text')),
)
The solution:
array('data' => 'Default text')
I have setup OpenTBS to generate dynamically from my contacts database. Now I want to setup the actual content of the email to come from a MySQL table created using CKeditor or another WYSISYG JS editor.
I have been able to get the content to display on the outputted docx file but it is coming this as a straing with the html tags, I somehow need this to format so it comes though as it was put in by the client. I am only going to allow them to use the basics, paragrahs, bold, italics and maybe a few other tags.
Is this someway I can convert this html string to word copy / text? Or somehow have a different WYSIWYG editor to save it in MySQL as word code rather then html code.
Thanks
It's not really relevant but below is the function that generates the OpenTBS document from a template and the database (I am using CakePHP) MailMerge.description is the body with the html code at the moment.
// FUNCTION EXPORT MAIL MERGE
// -------------------------------------------------------------->
function mail_merge()
{
Configure::write('debug',2);
$this->layout = null;
$this->autoRender = FALSE;
// GET THE CONTACTS
// ------------------------------------------------------------->
$contacts = $this->Contact->find('all', array('limit' => 20, 'contain' => FALSE));
$this->loadModel('MailMerge');
$content = $this->MailMerge->find('first', array(
'conditions' => array('MailMerge.id' => 1),
'fields' => array('MailMerge.description')
));
// Get a new instance of TBS with the OpenTBS plug-in
// ------------------------------------------------------------->
$otbs = $this->Tbs->getOpenTbs();
// Load the template file
// ------------------------------------------------------------->
$otbs->LoadTemplate(APP . DS . WEBROOT_DIR . '/files/data_files/enquiry_letter_sample_redcliffe.docx');
// Merge data in the template
// ------------------------------------------------------------->
$otbs->MergeBlock('r', $contacts);
$otbs->MergeBlock('content', $content);
// End the merge and export
// ------------------------------------------------------------->
$file_name = 'export.docx';
$otbs->Show(OPENTBS_DOWNLOAD, $file_name);
}
I'm using CodeIgniter, alongside the highlight_code("$string"); (More info) function to provide syntax highlighting to a dynamic site. I want the users to be able to submit their own posts written in a BBCode-style format. I'm using NBBC PHP library for this.
My problem is that nomatter how I do it I cannot get NBBC to syntax-highlight only [code][/code] tags that my users enter. Here's the PHP for [code]:
'code' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => "\n<div class=\"bbcode_code\">\n<p>Code:</p>\n<code><?php $highlight_code(\"?>{\$_content/v}<?php \");?></code>\n</div>\n",
'class' => 'code',
'allow_in' => Array('listitem', 'block', 'columns'),
'content' => BBCODE_VERBATIM,
'before_tag' => "sns",
'after_tag' => "sn",
'before_endtag' => "sn",
'after_endtag' => "sns",
'plain_start' => "<div id=\"footer\">",
'plain_end' => "</div>",
'simple_start' => '\n<div class=\"bbcode_code\">\n<p>Code:</p>\n<code>',
'simple_end' => '</code>\n</div>\n',
),
If you see the line which says <?php $highlight_code(\"?>{\$_content/v}<?php \");?> that I whacked in there, I thought that would highlight the code contained within the tags. I can't quite remember what this outputs (I've tried plenty of different combinations) but the closest I got was it being exported as text from PHP - in my page XHTML source it just appeared as text.
What can I do to make all content within tags on a page be syntax-highlighted, ideally using highlight_code($string); or similar?
I was thinking preg_replace would be an option but I don't know how to do it to dynamically replace everything between outputted tags (not [code], remember, but HTML which NBBC outputs).
First use preg_match to extract the contents of the [code][/code] tags, and highlight_code() that.
Use the results to preg_replace() the code area in the original string with the highlighted code. Pseudocode-ish:
$code = preg_match(/code pattern/, $string);
$code = highlight_code($code);
$string = preg_replace(/code pattern/, $code, $string);
Hope it works.