Klassische Textköpfe- und -füße hinzufügen Erfahren Sie, wie Sie Textüberschriften und -fußzeilen zu einem PDF-Dokument hinzufügen, wenn Sie HTML-Inhalte rendern. Um Textüberschriften und -fußzeilen einzuschließen, müssen Sie diese im Rendering-Optionsobjekt angeben. Define the header content with a divider line, centered text displaying the HTML title, font settings, and font size. Similarly, define the footer with the textFooter property. You can utilize fields like {page}, {total-pages}, {url}, {date}, {time}, {html-title}, and {pdf-title} to personalize the content. Passen Sie die Ränder an, um die Kopf- und Fußzeile angemessen zu berücksichtigen. Utilize the PdfDocument.fromHtml method to convert your HTML content into a PDF. Pass the renderOptions object as an option. Für eine detaillierte Dokumentation zur Erstellung von PDFs aus HTML besuchen Sie die IronPDF-Dokumentation. Das resultierende PDF-Dokument, komplett mit Kopf- und Fußzeilen, wird unter dem Namen "header_footer.pdf" gespeichert. // Import the necessary namespace using IronPdf; class Program { static void Main() { // Define your HTML content string htmlContent = @"<html><body><h1>Hello, World!</h1><p>This is a PDF document with headers and footers.</p></body></html>"; // Create the rendering options for the PDF var renderOptions = new PdfPrintOptions() { // Specify header settings with fields Header = new SimpleHeaderFooter() { CenterText = "{pdf-title}", FontFamily = "Arial", FontSize = 14, DrawDividerLine = true, Height = 50 // Customize height based on needs }, // Specify footer settings with fields Footer = new SimpleHeaderFooter() { CenterText = "Page {page} of {total-pages}", FontFamily = "Arial", FontSize = 12, DrawDividerLine = true, Height = 50 // Customize height based on needs }, MarginTop = 50, // Adjust top margin for header MarginBottom = 50 // Adjust bottom margin for footer }; // Create a PDF document from HTML with the specified options var pdfDocument = PdfDocument.FromHtml(htmlContent, renderOptions); // Save the PDF document with headers and footers pdfDocument.SaveAs("header_footer.pdf"); } } // Import the necessary namespace using IronPdf; class Program { static void Main() { // Define your HTML content string htmlContent = @"<html><body><h1>Hello, World!</h1><p>This is a PDF document with headers and footers.</p></body></html>"; // Create the rendering options for the PDF var renderOptions = new PdfPrintOptions() { // Specify header settings with fields Header = new SimpleHeaderFooter() { CenterText = "{pdf-title}", FontFamily = "Arial", FontSize = 14, DrawDividerLine = true, Height = 50 // Customize height based on needs }, // Specify footer settings with fields Footer = new SimpleHeaderFooter() { CenterText = "Page {page} of {total-pages}", FontFamily = "Arial", FontSize = 12, DrawDividerLine = true, Height = 50 // Customize height based on needs }, MarginTop = 50, // Adjust top margin for header MarginBottom = 50 // Adjust bottom margin for footer }; // Create a PDF document from HTML with the specified options var pdfDocument = PdfDocument.FromHtml(htmlContent, renderOptions); // Save the PDF document with headers and footers pdfDocument.SaveAs("header_footer.pdf"); } } $vbLabelText $csharpLabel Entdecken Sie den Headers & Footers Beispielcode auf GitHub Verwandte Doku-Links Auf Github ansehen Verwandtes Tutorial Verwandte Anleitung Klassendokumentation Sprachpakete herunterladen IronPDF DLL herunterladen Ein Problem auf dieser Seite melden Bereit anzufangen? Version: 2025.12 gerade veröffentlicht Kostenlose npm-Installation Lizenzen anzeigen
In einer Live-Umgebung testen Testen Sie ohne Wasserzeichen in der Produktion.Funktioniert dort, wo Sie es brauchen.
Voll funktionsfähiges Produkt Erhalten Sie 30 Tage voll funktionsfähiges Produkt.In wenigen Minuten einsatzbereit.
24/5 technischer Support Voller Zugriff auf unser Support-Engineering-Team während Ihrer Produktprobe
Alle Ihre Fragen werden beantwortet, um sicherzustellen, dass Sie alle Informationen erhalten, die Sie benötigen. (Völlig unverbindlich.)