Pdf

Table Header in PDFs with Visualforce

by Patrick Connelly posted on November 15, 2016

One of the problems I had with the way that we generated the PDFs in previous Battle Station Invoice posts was that the table header wasn’t repeated for long lists of supplies or resources that continued on the next page. There’s a simple way to add the table header for PDFs generated in Salesforce using the flying saucer mark-up but that won’t generate the table header correctly for us. It seems that the -fs-table-paginate tag does not play well when combined with a Visualforce component so we’ll need to take a bit more of a native CSS approach.

If you are doing this with plain Visualforce and apex:pageBlockTable, the -fs-table-paginate is the way to go.

Watermarking PDFs in Visualforce

by Patrick Connelly posted on May 09, 2016

Keeping on the PDF and Trailhead theme, lets take a look at adding watermarks to our PDFs. There was recently a developer boards post about watermarking a PDF and it dovetailed nicely into the previous posts.


Field Sets and Dynamic Visualforce

by Patrick Connelly posted on April 25, 2016

One of the downsides of the code I posted a couple of weeks ago to generate PDFs is that if you want to add new fields to your invoices, you have to edit the Visualforce page. By updating our Visualforce and using field sets, we can dynamically add fields to our invoices


PDF Attachment with Visualforce

by Patrick Connelly posted on April 18, 2016

After last weeks post, let’s take a look at how we can send a PDF attachment via a Visualforce email template. Our goal is to be able to automatically send an invoice to our customer whenever their Battle Station is fully operational. We will be taking the Battle Station Invoice PDF and making it something we can attach to an email and then create a workflow to send that email when the status changes to complete.


PDF Headers and Footers with Visualforce

by Patrick Connelly posted on April 04, 2016

Over the past couple of months, I’ve seen several posts on the Developer forums asking how to set PDF headers and footers with Visualforce. I decided to sit down and try my hand at it. If you have done the Battle Station app on Trailhead, you can try this out on your own sandbox! We will be generating a PDF invoice for the Battle Station app that includes a first page header image and a dynamically generated footer.


Combining pdf with linux via the command-line

by Patrick Connelly posted on January 06, 2009

I’ve always found a need for this, and with some digging, I’ve found a couple of ways to do this. The simplist is with ImageMagik, but I’ve found the default values leave the quality a little lacking. However, I’ve found an article that uses GhostScript to do it, and it does a wonderful job.

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf

They suggest putting it in an alias, but I’ve gone a step further and just put it in a bash script in ~/bin/combinepdf

#!/bin/bash

if [ $# -le 1 ]
then
     echo "usage: combinepdf output.pdf input1.pdf ... inputN.pdf"
exit -1
fi

OUTPUT=$1

if [ -e $OUTPUT ]
then
     echo "Output file \"$OUTPUT\" exists"
exit -1
fi

fnum=2

INPUT="$2"
ARGV=( $@ )

while [ $fnum -lt $# ]
do
     INPUT=`echo $INPUT" "${ARGV[$fnum]}`
     let "fnum += 1"
done

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$OUTPUT $INPUT

Then chmod a+x ~/bin/combinepdf and then run it.