Archive
Online Convert(er)
http://www.online-convert.com/
I wanted to convert a PDF with Calibre but it failed. I tried with Online Convert(er) too and it succeeded…
Resize .tif file and convert to .jpg
Use case
In the lab we have a photocopier that can scan too. Quite cool, you can precise your email address and it sends you the scanned page in .tif format.
However, pages must be scanned one by one and each of them is sent as a separate .tif file. Each .tif file is around 2.8 MB large with a resolution of 4900 x 7000 pixels. How to resize them and convert them to .jpg files? Gimp is one way but could we solve it in command-line?
Solution
Put the .tif files in a folder and create a subfolder called “out”. This way the output won’t be mixed with the input.
for i in *.tif; do echo $i; convert $i -resize 24% out/`basename $i .tif`.jpg; done
Each .tif is made smaller (width around 1200 pixels) and converted to .jpg.
As a final touch, convert the JPGs to a PDF file.
cd out convert *.jpg doc.pdf
Question
Does anyone know how to to resize an image the following way: let width be 1200 pixels and keep the aspect ratio? Above the 24% was the result of a manual computation…
Answer: just use “convert -resize 1200 in.tif out.jpg“. The output will have width=1200 pixels with the same ratio as the input image. (Thanks Yves for the tip.)
Convert HTML to PDF
In this thread you will find a list of “HTML to PDF” converters, e.g.:
- WKhtmlToPDF (blog post)
- DOMPDF
- Htmldoc
- HTML2PDF
- Prince XML (free for non-commercial use)
- etc.
WKhtmlToPDF
“Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.“
You can get its binary executable here. Then, you can convert an html to pdf like this:
wkhtmltopdf-i386 test.html test.pdf
The result will be similar to exporting the page in PDF in a browser. This is not a surprise, wkhtmltopdf contains the WebKit rendering engine.
View .djvu files
Problem
You want to open .djvu files. Maybe you’d like to convert them in PDF format too.
“DjVu (pronounced like déjà vu) is a computer file format designed primarily to store scanned documents, especially those containing a combination of text, line drawings, and photographs. It uses technologies such as image layer separation of text and background/images, progressive loading, arithmetic coding, and lossy compression for bitonal (monochrome) images. This allows for high-quality, readable images to be stored in a minimum of space, so that they can be made available on the web.” (source)
Solution
The default document viewer of Gnome (evince) can open these files, but it’s quite slow. There is a better program for this format called djview4.
sudo apt-get install djview4
This program can also export .djvu files in PDF format (however, it’ll take some while, the conversion is quite slow).
To open .djvu files with Midnight Commander, add these lines to ~/.mc/bindings:
regex/\.djvu$ Open=djview4 %f &
PNG to EPS
Problem
You use “latex” and you want to convert a PNG file to EPS format. Using Gimp, for instance, produces an ugly output.
Solution
Try the png2eps script of Henlich. Works fine :)
Under Ubuntu 10.10, I had to install the following package:
sudo apt-get install pngcheck
Plus, I had to remove the -indexbits=… option from the script.
Credits
Thanks Mehdi for the tip.
Currency converters
Here I collect some links that are related to currency conversions.
- http://www.x-rates.com/calculator.html
- http://www.xe.com
- http://www.exchangerate-api.com (Up to 1500 queries/month, their service is free. You just need to ask for a key. However, I sent them an e-mail asking something and they didn’t reply. Hmm, not very professional…)
- Making the new Yahoo! Currency Converter accessible
- JS enabled: http://finance.yahoo.com/currency-converter/#from=CAD;to=HUF;amt=1
- JS disabled: http://finance.yahoo.com/currency/converter-results/20101209/1-cad-to-huf.html (notice that you need to specify the date here)
In another post I will explain how to get conversion rates from PHP using the Yahoo API.
Accept positive integers only (string to int) [PHP]
Problem
You have a form and in a field you want to accept positive integers only. However, in PHP the conversion from string to int is a bit strange:
$a = "1.3"; print (int)$a; // => 1, no error $a = "7 sins"; print (int)$a; // => 7, no error $a = "0"; print (int)$a; // => 0 $a = "hello"; print (int)$a; // => 0 again (Did we convert "0", or is it an error? We don't know.)
There is no exception raised if the input couldn’t be converted correctly.
Solution
if (!( is_numeric($val) and ((string)(int)$val === (string)$val) and ((int)$val > 0) ))
{
// not a positive integer
}
Read it like this: (a) $val must be numeric, and (b) the string $val must be converted into the same integer number, and (c) $val must be positive. If it’s not true (see the negation (!)), then $val is not a positive integer.
Credits
Inspired by a comment here.
Convert JPGs to PDF
Problem
You have some JPG files and you want to combine them in a single PDF.
Solution
convert *.jpg out.pdf
The program convert is part of the imagemagick package.
Notes
The program convert is very powerful. It can convert files from/to almost all kinds of formats. Check out its man page. Official home page is here.