捕獲和轉換Web的工具

如何在DOCX和PDF文檔中添加頁眉和頁腳?

頭

要將頁眉和/或頁腳添加到DOCX或PDF文檔中,首先需要 創建一個模板,並帶有指定的標識符。 在這種情況下 report。 該模板可以包括您要顯示的所有文本,圖像和表格,以及何時顯示頁眉和頁腳的規則。

此外,模板可以包含內置變量,例如頁碼。 或自定義模板變量,如下所示。 例如,這可能是標題的文本, {number} 是一個自定義變量。

Report number: {number}

然後,您可以將此模板標識符傳遞給GrabzIt,以將指定的標頭添加到任何DOCX或PDF文檔中。 在下面顯示的示例中,對於我們支持的每種編程語言,上面的標題都顯示在每個生成的PDF文檔中。 但是,此代碼可以很容易地修改為在DOCX文檔中添加頁眉和頁腳。

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 = 50;
options.MarginBottom = 50;
options.AddTemplateParameter("number", "12345");

grabzIt.URLToPDF("http://www.spacex.com", options);
grabzIt.Save("http://www.example.com/Home/Index");
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(50);
options.setMarginBottom(50);
options.AddTemplateParameter("number", "12345");

grabzIt.URLToPDF("http://www.spacex.com", options);
grabzIt.Save("http://www.example.com/handler");
<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@3.4.7/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").AddTemplateVariable("number", "12345").ConvertURL("http://www.spacex.com", 
{"format": "pdf", 
"mtop":50, 
"mbottom":50, 
"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":50,"marginBottom":50,"templateId":"report",
"templateVariables":"number=12345"};

client.url_to_pdf("http://www.spacex.com", options);
client.save("http://www.example.com/handler", function (error, id){
    if (error != null){
        throw error;
    }
});
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$options = GrabzItPDFOptions->new();
$options->marginTop(50);
$options->marginBottom(50);
$options->templateId("report");
$options->AddTemplateParameter("number","12345");

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

$grabzIt->URLToPDF("http://www.spacex.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 = 50
options.marginBottom = 50
options.templateId = "report"
options.AddTemplateParameter("number","12345")

grabzIt.URLToPDF("http://www.spacex.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 = 50
options.marginBottom = 50
options.templateId = "report"
options.add_template_parameter("number","12345")

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

頁眉或頁腳未顯示在PDF中

生成PDF文檔時,必須確保有足夠的空間來顯示頁眉或頁腳。 為此,請指定足夠大的頂部空白以顯示頁眉,並指定足夠大的底部空白以顯示頁腳。 要獲得正確的邊距大小,可能需要反复嘗試。