How to generate a pdf without pushing a button

I want to generate a pdf with pdf-writer. All the pdfs I have generated in past were like:

format.pdf do         send_data IncidenceDrawer.draw(@incidence, @logs, @relincs), :filename => 'incidences/@incidence.id.pdf', :type => 'application/pdf', :disposition => 'inline' end

So, in that view, I had the link <%= link_to _('PDF Format'), formatted_incidence_path(@incidence, :pdf) %>

Only once I have pushed the link I generated the pdf. I want to generate it without pushing that button. I think I need some background magic, so I'm using BackgroundFu, but I can't use the same code anymore, because it needs the button to be pushed.