Travailler avec les titres dans un PDF

Appliquer un style de numérotation dans les titres

Les titres sont des parties importantes de tout document. Les rédacteurs essaient toujours de rendre les titres plus proéminents et significatifs pour leurs lecteurs. S’il y a plus d’un titre dans un document, un rédacteur a plusieurs options pour organiser ces titres. L’une des approches les plus courantes pour organiser les titres est d’écrire les titres dans un style de numérotation.

Aspose.PDF for .NET propose de nombreux styles de numérotation prédéfinis. Ces styles de numérotation prédéfinis sont stockés dans une énumération, NumberingStyle. Les valeurs prédéfinies de l’énumération NumberingStyle et leurs descriptions sont données ci-dessous :

Types de titres Description
NumeralsArabic Type arabe, par exemple, 1,1.1,…
NumeralsRomanUppercase Type romain majuscule, par exemple, I,I.II, …
NumeralsRomanLowercase Type romain minuscule, par exemple, i,i.ii, …
LettersUppercase Type anglais majuscule, par exemple, A,A.B, …
LettersLowercase Type anglais minuscule, par exemple, a,a.b, …
La propriété Style de la classe Aspose.Pdf.Heading est utilisée pour définir les styles de numérotation des titres.
Figure : Styles de numérotation prédéfinis
Le code source, pour obtenir la sortie montrée dans la figure ci-dessus, est donné ci-dessous dans l’exemple.

Le prochain extrait de code fonctionne également avec la bibliothèque Aspose.Drawing.

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ApplyNumberStyleToPdf()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

    // Create PDF document
    using (var document = new Aspose.Pdf.Document())
    {
        document.PageInfo.Width = 612.0;
        document.PageInfo.Height = 792.0;
        document.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
        document.PageInfo.Margin.Left = 72;
        document.PageInfo.Margin.Right = 72;
        document.PageInfo.Margin.Top = 72;
        document.PageInfo.Margin.Bottom = 72;

        // Add page
        var pdfPage = document.Pages.Add();
        pdfPage.PageInfo.Width = 612.0;
        pdfPage.PageInfo.Height = 792.0;
        pdfPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
        pdfPage.PageInfo.Margin.Left = 72;
        pdfPage.PageInfo.Margin.Right = 72;
        pdfPage.PageInfo.Margin.Top = 72;
        pdfPage.PageInfo.Margin.Bottom = 72;

        // Create a floating box with the same margin as the page
        var floatBox = new Aspose.Pdf.FloatingBox();
        floatBox.Margin = pdfPage.PageInfo.Margin;

        // Add the floating box to the page
        pdfPage.Paragraphs.Add(floatBox);

        // Add headings with numbering styles
        var heading = new Aspose.Pdf.Heading(1);
        heading.IsInList = true;
        heading.StartNumber = 1;
        heading.Text = "List 1";
        heading.Style = Aspose.Pdf.NumberingStyle.NumeralsRomanLowercase;
        heading.IsAutoSequence = true;
        floatBox.Paragraphs.Add(heading);

        var heading2 = new Aspose.Pdf.Heading(1);
        heading2.IsInList = true;
        heading2.StartNumber = 13;
        heading2.Text = "List 2";
        heading2.Style = Aspose.Pdf.NumberingStyle.NumeralsRomanLowercase;
        heading2.IsAutoSequence = true;
        floatBox.Paragraphs.Add(heading2);

        var heading3 = new Aspose.Pdf.Heading(2);
        heading3.IsInList = true;
        heading3.StartNumber = 1;
        heading3.Text = "the value, as of the effective date of the plan, of property to be distributed under the plan on account of each allowed";
        heading3.Style = Aspose.Pdf.NumberingStyle.LettersLowercase;
        heading3.IsAutoSequence = true;
        floatBox.Paragraphs.Add(heading3);

        // Save PDF document
        document.Save(dataDir + "ApplyNumberStyle_out.pdf");
    }
}