several methods fail after calling pdf.newPage(). Add a utility function to cd2 and call it from needed functions.