Ajouter des en-têtes et pieds de page texte classiques Apprenez à ajouter des en-têtes et pieds de page à un document PDF lors du rendu de contenu HTML. Pour inclure des en-têtes et pieds de page, vous devez les spécifier dans l'objet des options de rendu. 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. Personnalisez les marges pour accommoder correctement l'en-tête et le pied de page. Utilize the PdfDocument.fromHtml method to convert your HTML content into a PDF. Pass the renderOptions object as an option. Pour une documentation détaillée sur la création de PDFs à partir de HTML, visitez la Documentation d'IronPDF. Le document PDF résultant, complet avec en-têtes et pieds de page, est enregistré sous le nom "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"); } } // 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 Explorer l'exemple de code Headers & Footers sur GitHub Liens de documentation associés Voir sur Github Tutoriel connexe Guide pratique connexe Documentation de classe Obtenir des packs linguistiques Télécharger IronPDF DLL Signaler un problème sur cette page Prêt à commencer? Version : 2025.12 vient de sortir Installation npm gratuite Voir Licences
Testez dans un environnement en direct Testez en production sans filigranes.Fonctionne où que vous en ayez besoin.
Produit entièrement fonctionnel Profitez de 30 jours de produit entièrement fonctionnel.Configurez-le et faites-le fonctionner en quelques minutes.
Nous répondons à toutes vos questions afin de nous assurer que vous disposez de toutes les informations dont vous avez besoin. (Sans aucun engagement)