Fabric.js is amazing library – I know, that we have a lot of drawing possibilities using canvas element, but “vanilla version” is not very readable and difficult to use. With fabric.js, everyting is much simpler and cleaner, we can also use a lot of build-in tools. One of them is image filters. We can modify images in many ways, apply for example sepia filter, but also make other changes. Last time I must just change image color. Yep, user can upload image (or I load image using static url), and I want to force using color, not original. Diffucult? Not with fabric.js.Continue reading “Fabric.js – change uploaded image color”
Very short, but I think, may help a lot of people… Last time I spent a lot of time on the big issue with Phantom.js in Node app. Very common task: application should generate PDF files from input HTML code. Nothing difficult, yes? Yep, and it worked fine on my Node app… But one day, client said, that we should change font in document. Simple, we can just use font-face in input HTML styles, right? In theory, yes. Phantom.js and Node packages to use this library to convert HTML to PDF can use custom fonts and also other external assets like images.
With very popular html-pdf package we can use external, full link to assets, use absolute path to our local directory with files (using file:/// prefix) or specify base path in rendering options, and then use relative (to this base path) paths in our styles. And… it works fine. It also worked fine with custom fonts on my project. But only on local machine where I use MacOS. After deploying app to Debin, Ubuntu Server or CentOS server, PDFs are broken – with no selected text, but all pages are “images”, with many broken characters and very big results file (it isn’t strange if we have images, instead of text in PDF). Custom fonts have been used correctly, but PDF was broken, why?
It’s library and Phantom.js issue, but solution is very, very simple. We must install our custom fonts locally on production machine and do not attach them in CSS – just use as existing font-family! It’s because Phantom is external script and it can use system-wide fonts. Where should we place our files? There are directories. If you have issues with custom fonts and non-selectable text, just copy fonts to: