GrabzIt
Tools to Capture and Convert the Web

How to add headers and footers to DOCX and PDF documents?

Header

To add headers and/or footers to DOCX or PDF documents you first need to create a template, with a specified identifier. In this case report. The template can include all of the text, images and tables you want to display, along with rules for when to show the headers and footers.

Additionally templates can include built in variables or custom template variables as shown below. For instance this could be the text for the header, were {number} is a custom variable.

Report number: {number}

You can then pass this template identifier to GrabzIt to add the specified header to any DOCX or PDF document. In the examples shown below the above header is displayed in each generated PDF document, for every programming language we support. However this can code can be easily adapted to add headers and footers to DOCX documents as well.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
PDFOptions options = new PDFOptions();
options.TemplateId = "report";
options.MarginTop = 30;
options.MarginBottom = 30;
options.AddTemplateParameter("number", "12345");

grabzIt.URLToPDF("http://www.google.com", options);
grabzIt.Save("http://www.example.com/handler.ashx");
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
PDFOptions options = new PDFOptions();
options.setTemplateId("report");
options.setMarginTop(30);
options.setMarginBottom(30);
options.AddTemplateParameter("number", "12345");

grabzIt.URLToPDF("http://www.google.com", options);
grabzIt.Save("http://www.example.com/handler");
<script src="grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").AddTemplateVariable("number", "12345").ConvertURL("http://www.google.com", 
{"format": "pdf", 
"mtop":30, 
"mbottom":30, 
"templateid":"report"}).Create();
</script>
var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
var options = {"marginTop":30,"marginBottom":30,"templateId":"report",
"templateVariables":"number=12345"};

client.url_to_pdf("http://www.google.com", options);
client.save("http://www.example.com/handler");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItPDFOptions->new();
$options->marginTop(30);
$options->marginBottom(30);
$options->templateId("report");
$options->AddTemplateParameter("number","12345");

$grabzIt->URLToPDF("http://www.google.com", $options);
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = new GrabzItPDFOptions();
$options->setMarginTop(30);
$options->setMarginBottom(30);
$options->setTemplateId("report");
$options->AddTemplateParameter("number","12345");

$grabzIt->URLToPDF("http://www.google.com", $options);
$grabzIt->Save("http://www.example.com/handler.php");
grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzItPDFOptions.GrabzItPDFOptions()
options.marginTop = 30
options.marginBottom = 30
options.templateId = "report"
options.AddTemplateParameter("number","12345")

grabzIt.URLToPDF("http://www.google.com", options)
grabzIt.Save("http://www.example.com/handler.py")
grabzIt = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
options = GrabzIt::PDFOptions.new()
options.marginTop(30)
options.marginBottom(30)
options.templateId("report")
options.add_template_parameter("number","12345")

grabzIt.url_to_pdf("http://www.google.com", options)
grabzItClient.save("http://www.example.com/handler/index")

Header or footer isn't appearing in PDF

When generating PDF documents you must ensure that there is sufficient space for your header or footer to appear. To do this specify a large enough top margin for the header to appear and a large enough bottom margin for a footer to appear. To get the margin size right may require some trial and error.

Back to SupportMore screenshot questions
Try all our premium features for free with a 7 day free trial. Then from $5.99 a month, unless cancelled.
  • More Captures
  • More Features
  • More API's
  • Bigger Scrapes
  • Bigger Screenshots
  • Bigger Everything
Start Free Trial