Added custom header/footer support for file export, some error checking.