prawnto and text format - plugins

Prawn/prawnto is cool stuff to generate pdf file. But I am not able to render formatted text exactly as they are. Prawn is rendering all the html tags <b>, <i>, <p> as string. Below is the code i have written
pdf.text "#{#product.name}", :size => 20, :style => :bold
pdf.text "<b>Ashis Rai<b>"
and want to see the result as
Nokia N97
Ashis Rai
but I am getting final result as below
Nokia N97
<b>Ashis Rai<b>

The pdf.text method will render what it is passed. To make the text bold you need to use
pdf.text, :font_style => :bold
A good way to get the docs is to run
gem server
Then point your browser to http://localhost:8808/doc_root/prawn-core-0.8.4/rdoc/Prawn/Text.html
This will give you more details on the methods and some of the options.

There is a below option that allows our formatted text to be render in pdf file
:inline_format => true
You can look over How can I do inline formatting (bold and underline) for PDF generated by Prawnto in Rails? by #Angela

Related

Copy formatted text to clipboard

A simple html page has FORMATTED text - not fancy - line breaks, and italic.
I want to have a button that takes this formatted text, and copies it to the clipboard, formatted (it is planned to be pasted into some LibreOffice document later).
Couldn't find how to do it.
I tried ZeroClipboard, and a suggestion to parse the text, replacing ""-s to "\r\n". That indeed does the trick for line breaks, but what about italic?... Any means to get this functionality?...
When you create an italic tag the responsible for formatting the document and showing the text properly is the browser. If you want to copy the text you should get the text already parse and render by the browser or parse yourself the text like you did with break lines. For italics when you find a ... tag you must create the adequate text. That is, text in italics, but that depends on the language you are using, but i'm sure it can be done.
OK,
Turns out that ZeroClipboard had this functionality (of rendering the HTML text upon paste), but have disabled it.
However, the version that supports it can be found at: https://github.com/botcheddevil/ZeroClipboard
Note:
You may find that in this version, creating the client, binding the flash to a component, and handling the events are rather different than the documentation of current version of ZeroClipboard (https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md

Formatting PHP code for Epub in MS Word

I'm trying to format the PHP code sections of a 700+ page book for Epub conversion. If I use soft returns at the end of the code lines, they get eaten. If I use hard returns (making each line a paragraph), I either get too much space between the lines, or not enough before and after the code section. If I add an empty line before and after the code section, it gets eaten.
There are thousands of lines of code in the book. Is there some way to handle this without manually editing the html file?
Is there some common format for these code section like being wrapped with PHP tags?
If they are PHP tags you can use this, which will wrap each tag set with a :
function fixPHPcode($matches)
{
return '<p class="php_code">' . $matches[0] . '</p>';
}
$data = preg_replace_callback('/<\?php(.|\s)+?\?>/i', 'fixPHPcode', $data);
I did try some fairly complex regex transforms, but I've found an easier method that actually works fairly well.
The secret is to create a style based on Word's "HTML Preformatted" style, or if you don't have that style, a style based on Normal that specifies Arial Unicode MS or Courier New as the font, with no proofing, left justified.
Indent with spaces and use soft returns (shift-enter) at the end of each line.
Calibre will produce acceptable Epub and Mobi versions of this. Courier is a crap font for code, but at least it's monospaced so the indents will line up, and people are used to seeing it as a code font.

html2pdf special characters not rendered

I am using html2pdf library for genarating pdf with bookmarked index. By default it seems to work well for English content but i need to generate content that includes English & Arabic text. The "aefurat" font seems to work relatively good, except some special characters (’, ‘, “, ”, ...) that are rendered as boxes ([]).
The code I used is,
require_once(dirname(__FILE__).'/../html2pdf.class.php');
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 0);
$html2pdf->setDefaultFont('aefurat');
$html2pdf->writeHTML($content);
$html2pdf->Output('bookmark.pdf');
A Sample content that includes arabic and special chararacters is,
’This is Arabic’ "العربية" Example With TCPDF... some text here some
text here some “text here”.
Wondering if I need to use some other font or alter some configurations. Kindly advice me.

Formatting Field values using itextsharp

how can i have a string format "i am fine here" using itextsharp
fields.SetField("tgPara2", message2);
where message is "i am fine here" i want the fine word only to be bold.
Any help would be
iText has partial support for "rich text values" for text fields. You can get and set the rich values, but iText won't actually draw those values properly. You need to turn off SetGenerateAppearances, and open the PDF in Acrobat/Reader to see the rich text.
This means flattening isn't going to work (unless you open the PDF in Acrobat, then save it again... clunky).
You might want to check out the PDF Specification (Section 12..7.3.4 Rich Text Strings) for further information on what is and isn't legal. <b> is legal, as is the font-weight CSS style

with tinymce, how to convert an html tag into a different format

I want to convert an HTML tag that tinymce returns into a different format.
e.g.
The italics tag I want to convert to #i#
Is that possible with the editor itself?
During postback I strip all html tags, so I need it in a different safer format.
Add an onsubmit call to your form and use a simple javascript function to string replace the html tags you want to keep.
A more constructive method that might achieve what you want is to use the built in 'Valid elements' feature of tinymce. You can specify exactly which HTML tags you want to keep and it will strip out anything else. Plus it might be able to save you the step of stripping out the HTML yourself.
e.g.
valid_elements : "i,b,u",
http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_elements