Laur IVAN

Styling HTML to PDF with iText 2.1.7

Posted by in Software, Tutorial

There are various solutions for producing PDFs from a HTML file, some with excellent results (e.g. ones based on the chrome renderer). Unfortunately, they usually mean adding more dependencies to an existing system. To keep things in check, we’ve chosen to use iText to generate PDFs. Following the previous post, we need to enhance the generated PDF with some styles. Now, the older versions of iText can’t use CSS directly, so we’ll need to produce the styles by hand. iText has a StyleSheet object which can load tag styles via…read more

Strip HTML tags in python

Posted by in Software, Tutorial

Note: This is a post transferred from Laurii for historical and consolidation purposes. A common problem I have to deal with quite often is to remove all HTML tags from a document. While this is easy for XML (well formatted etc.) and you could do it by hand with a regexp, HTML has a bit more problems. There are several solutions to get around this… Using a browser This is a bit overkill, but you could use a browser’s renderer to “display” the string content and then get it as…read more

Brand Colors

Posted by in Software

A while ago I’ve found a list of common brands’ colors. A little experiment: If you find this post and ad below useful, please check the ad out :-)

Copy Text to Clipboard in HTML Page using JavaScript

Posted by in Software

I’ve got a problem on one of my sites: I have a unique identifier displayed on one page, which I need to make it easy to copy to clipboard. After looking online, I’ve found three approaches using only JS. Clipboard.js Clipboard.js is a new (September 2015) approach which uses only JS to copy the text transparently (using the Selection/execCommand APIs). The code is as simple as:

where trigger is a CSS selector. [Thanks Gabriel Gularte]. Popup approach This method opens a dialog box with a text. The code is…read more

Send POST to server via python-requests

Posted by in Software

The other day I’ve had a question asked: How do you send a form data to a server and get the reply? My solution involves python-requests:

r.text contains the reply HTML page, which then needs to be processed via e.g. python’s DOM processing module or BeautifulSoup (if you’re looking for something more tolerant). HTH, A little experiment: If you find this post and ad below useful, please check the ad out :-)

Decent image loader widget in django

Posted by in Software

I’m working on a website where I need to be able to load an image. The default widget is abysmal; it has a url to the current image, a checkbox and a file loader input element. Even styled, it looks pretty bad. So, I’ve taken upon myself to prettify it and get from this: to this: To accomplish the transformation, we need: Crispy forms – just because my app uses it and it gives nice bootstrap-based formatting Floppy forms – because it allow us to customise widgets markusslima’s bootstrap-filestyle –…read more