Sometimes you want to use a vanilla Ruby method like a block. You can use
Object#method to obtain a method reference that responds to
foo_plus = "foo".method(:+) foo_plus.call("bar") # => "foobar"
The method reference also understands
#to_proc so you can feed it to block-taking methods by prefixing it with
printer = method(:puts) [1, 2, 3].each(&printer) # will print one line per number
I believe that when WEBrick has trouble bringing up your Rails application, the WEBrick component that is supposed to print you a pretty error message has a bug and sometimes fails with this message:
"undefined method `bytesize' for #<Array>"
Starting the application in Passenger gave me a stacktrace in
log/development.log that pointed to the actual problem.
Possible causes discovered by looking at the logs —————————————————–…
Note that converting from RGB to CMYK will usually degrade your colors because no exact mapping is possible. Anyway, this Stackoverflow post worked for me:
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \ -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK \ -sOutputFile=output.pdf input.pdf
Use the PDF toolkit:
sudo apt-get install pdftk
To rotate page 1 by 90 degrees clockwise:
pdftk in.pdf cat 1E output out.pdf # old pdftk pdftk in.pdf cat 1east output out.pdf # new pdftk
To rotate all pages clockwise:
pdftk in.pdf cat 1-endE output out.pdf # old pdftk pdftk in.pdf cat 1-endeast output out.pdf # new pdftk
E (old pdftk) or
east (new pdftk) is meaningful if you want other rotations. From the
The page rotation setting…
Pdfposter is a Python script that allows to convert large PDFs into a PDF with multiple pages that can be printed and turned into one big poster.
In Ubuntu, you can install it with
sudo apt-get install pdfposter
Scaling to the desired size is a bit cumbersome. If you want to split
large.pdf, I suggest you run
pdfposter -vns 0.5 large.pdf larger.poster.pdf
which will tell you into how many pages the file would be split. Then simply tweak the
-s value till you get the desired number of pages, and remove the
-n to generate the r…
You can unpack a
.tar.gz file into the current directory like this:
tar -xzvf archive.tar.gz
The options used are
tar xzvf ...works as well).
-cflag instead of
This will install a printer called "PDF":
sudo apt-get install cups-pdf
Files will be put into
~/PDF/ without any questions asked.
Sometimes PDF cucumber tests fail at the first test run and succeed at the second run. You can fix this with this step:
When PDF generation is ready And I follow "Save as PDF" # Checks for PDF contents go here
Here is the step definition:
When /^PDF generation is ready$/ do Then 'I should see ""' end
Automatically convert bitmap images like JPEGs, GIFs and PNGs to the crisp, clean, scalable vector art of EPS, SVG, and PDF with the world's best auto-tracing software.
The trick is this: send a low-resolution version of your image to the screen, and a high-resolution version to the printer.
PhantomJS is a minimalistic headless WebKit.
It has fast and native support for various web standards:
DOM handling, CSS selector, JSON, Canvas, and SVG.
If you plan to insert an existing PDF into a new LaTeX document that you will compile to PDF, you can use
\includegraphics for this. Although, be prepared to get tons of errors complaining about overfill hboxes and the like.
You can use this package that takes care:
In order to insert a PDF, use:
See the external link for more options.
If you run specs or your application and get an error like:
ActionController::MissingFile in 'ProductsController#show, should render PDF'
Cannot read file /some/file.pdf
You may be missing the HTMLDOC binary on your system. Install it like this on Debian/Ubuntu:
sudo apt-get install htmldoc
The step definitions below allow you to write this in both Webrat and Capybara:
When I follow "Download as PDF" Then I should get a response with content-type "application/pdf"
Then /^I should get a response with content-type "([^"]*)"$/ do |content_type| page.response_headers['Content-Type'].should == content_type end
Then /^I should get a response with content-type "([^"]*)"$/ do |content_type| response.content_type.should == content_type end
Unfortunatly this do…
Gallery of fonts you can use without much hassle in LaTeX. The license of the fonts vary, but are all free. Note that the fonts not necessarily are free to distribute, and some fonts are available for non-commercial use only.
If a controller action responds to other formats than HTML (XML, PDF, Excel, JSON, …), you can reach that code in a controller spec like this:
describe UsersController do describe '#index' do it 'should be able to send an excel file' do # stubs and expectations go here get :index, :format => 'xls' end end end
Remember that both the
:format parameter and the
HTTP_ACCEPT header can m…
We use RTeX for PDF exports.
While converting LaTeX to PDF, RTeX opens a temporary file which has problematic permissions: Both group and world can read those files.
Although the temp files should go away they sometimes live longer than one would expect.
We patched RTeX to fix this (and have more secure permissions). Place the code below into