Paragraphe - Champ d’application, global
Crée un objet Paragraphe représentant un bloc de texte dans un PDF.
Cette API fait partie du module d’extension ServiceNow PDF Generation Utilities (com.snc.apppdfgenerator) et est fournie dans l’espace de noms sn_pdfgeneratorutils . Le module d’extension est activé par défaut.
Cette API est un composant utilisé avec l’API Document pour générer un PDF.
Paragraphe - Paragraphe(String text)
Instancie un nouvel objet Paragraph contenant une chaîne.
| Nom | Type | Description |
|---|---|---|
| Texte | Chaîne | Bloc de texte de paragraphe. |
L’exemple suivant montre comment créer un objet Paragraphe . Pour obtenir un exemple d’utilisation de document, consultez API Document .
var para = new Paragraph("hello");
Paragraphe – addNewLine()
Ajoute une ligne vide après un paragraphe dans un document.
| Nom | Type | Description |
|---|---|---|
| Aucun |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment ajouter une nouvelle ligne après un paragraphe dans un document. Pour obtenir un exemple d’utilisation de document, consultez API Document .
var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var myPara = new sn_pdfgeneratorutils.Paragraph("This is a paragraph.");
myPara.addNewLine();
document.addParagraph(myPara);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "addText.pdf");
Paragraphe – addParagraph(Paragraphe paragraphe)
Ajoute un paragraphe. Vous pouvez utiliser cette méthode pour créer un bloc de paragraphes avec des sauts de ligne automatiques.
| Nom | Type | Description |
|---|---|---|
| Paragraphe | Paragraphe | Objet de paragraphe. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment ajouter une section de paragraphes à un document. Pour obtenir un exemple d’utilisation de document, consultez API Document .
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var sectionPara = new sn_pdfgeneratorutils.Paragraph("This is the first paragraph.");
var subPara1 = new sn_pdfgeneratorutils.Paragraph("Pellentesque nec neque interdum turpis ultricies tristique at ut lacus. Nam eget sollicitudin.");
var subPara2 = new sn_pdfgeneratorutils.Paragraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel ultrices erat.");
var subPara3 = new sn_pdfgeneratorutils.Paragraph("Aenean fermentum lorem congue metus faucibus, vitae viverra quam eleifend. Donec sed risus quis eros suscipit efficitur.");
sectionPara.addParagraph(subPara1);
sectionPara.addParagraph(subPara2);
sectionPara.addParagraph(subPara3);
document.addParagraph(sectionPara);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "filename.pdf");
Paragraphe – addString(contenu de la chaîne)
Ajoute une chaîne de texte à un paragraphe. Cette méthode n’insère pas automatiquement d’espace avant le contenu.
| Nom | Type | Description |
|---|---|---|
| contenu | Chaîne | Informations à inclure dans un paragraphe. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment ajouter une nouvelle phrase à un paragraphe. Pour obtenir un exemple d’utilisation de document, consultez API Document .
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var myPara = new sn_pdfgeneratorutils.Paragraph("This is the first sentence.");
myPara.addString(" This is the second sentence in the same paragraph. Spaces are not inserted automatically.")
document.addParagraph(myPara);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "filename.pdf");
Paragraphe – addStyle(Style style)
Applique un style prédéfini au texte du paragraphe.
| Nom | Type | Description |
|---|---|---|
| Style | Style | Style à appliquer à cet élément. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment appliquer un style à un paragraphe. Pour obtenir un exemple d’utilisation de document, consultez API Document .
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
// Create a font color (result is purple)
var fontColor = new sn_pdfgeneratorutils.Color([0.5,0.0,0.5]);
// Create a style for your paragraph
var paraStyle = new sn_pdfgeneratorutils.Style();
paraStyle.setFontColor(fontColor);
paraStyle.setFontSize(10);
var myPara = new sn_pdfgeneratorutils.Paragraph("This paragraph has style.");
myPara.addStyle(paraStyle);
document.addParagraph(myPara);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "addStyle.pdf");
Paragraphe – setFixedPosition(Nombre à gauche, Nombre en bas, Nombre en largeur)
Définit un élément de paragraphe à une position fixe sur la page.
| Nom | Type | Description |
|---|---|---|
| Gauche | Numéro | Indentation à partir du côté gauche de la page PDF en points. |
| bas | Numéro | Position à partir du bas de la page PDF en points. |
| largeur | Numéro | Largeur de l’élément de paragraphe en points. Cette valeur détermine la longueur à laquelle la ligne s’interrompt. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir une position fixe sur une page. Pour obtenir un exemple d’utilisation de document, consultez API Document .
var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
// Create a style
var paraStyle = new sn_pdfgeneratorutils.Style();
paraStyle.setFontSize(48);
paraStyle.setBold();
// my paragraph
var para = new sn_pdfgeneratorutils.Paragraph("Document Title");
para.setFixedPosition(204,400,240);
para.setTextAlignment("text-center");
para.addStyle(paraStyle);
document.addParagraph(para);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "fileName.pdf");
Paragraphe – setMargin(Marge numérique)
Définit la marge de chaque paragraphe.
Pour définir les quatre marges avec une ou plusieurs valeurs uniques, utilisez setMargins().
| Nom | Type | Description |
|---|---|---|
| marge | Numéro | Valeur des marges supérieure, droite, inférieure et gauche en points. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir toutes les marges du paragraphe sur 48 points.
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var margins = 48.0;
var myPara = new sn_pdfgeneratorutils.Paragraph("Paragraph text with all margins set to the same value.");
myPara.setMargin(margins);
document.addParagraph(myPara);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "docName.pdf");
Paragraphe – setMarginBottom(Marge du nombre)
Définit la marge inférieure d’un paragraphe.
| Nom | Type | Description |
|---|---|---|
| marge | Numéro | Hauteur de la marge inférieure en points. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir la marge inférieure d’un paragraphe sur un point.
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var marginVal = 1.0;
var paraMarginBottom = new sn_pdfgeneratorutils.Paragraph("Paragraph text with bottom margin set.");
paraMarginBottom.setMarginBottom(marginVal);
document.addParagraph(paraMarginBottom);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "docName.pdf");
Paragraphe – setMarginLeft(Marge numérique)
Définit la marge gauche d’un paragraphe.
| Nom | Type | Description |
|---|---|---|
| Marge gauche | Numéro | Largeur de la marge de gauche en points. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir la marge gauche d’un paragraphe sur un point.
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var marginVal = 1.0;
var paraMarginLeft = new sn_pdfgeneratorutils.Paragraph("Paragraph text with left margin set.");
paraMarginLeft.setMarginLeft(marginVal);
document.addParagraph(paraMarginLeft);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "docName.pdf");
Paragraphe – setMarginRight(Marge numérique)
Définit la marge droite d’un paragraphe.
| Nom | Type | Description |
|---|---|---|
| marge | Numéro | Largeur de la marge de droite en points. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir la marge droite d’un paragraphe sur un point.
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var marginVal = 1.0;
var paraMarginRight = new sn_pdfgeneratorutils.Paragraph("Paragraph text with right margin set.");
paraMarginRight.setMarginRight(marginVal);
document.addParagraph(paraMarginRight);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "docName.pdf");
Paragraphe – setMargins(Number marginTop, Number marginRight, Number marginBottom, Number marginLeft)
Définit une taille pour chaque marge de paragraphe.
Pour définir chaque marge sur la même valeur, utilisez setMargin().
| Nom | Type | Description |
|---|---|---|
| Marge supérieure | Numéro | Hauteur de la marge supérieure en points. |
| Marge droite | Numéro | Largeur de la marge de droite en points. |
| Marge inférieure | Numéro | Hauteur de la marge inférieure en points. |
| Marge gauche | Numéro | Largeur de la marge de gauche en points. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir les marges des paragraphes.Pour obtenir un exemple d’utilisation de document, consultez API Document .
var para = new sn_pdfgeneratorutils.Paragraph("Paragraph text.");
var topMargin = 1.0;
var rightMargin = 1.0;
var bottomMargin = 1.0;
var leftMargin = 1.5;
para.setMargins(marginTop, marginRight, marginBottom, marginLeft);
Paragraphe – setMarginTop(Marge numérique)
Définit la marge supérieure d’un paragraphe.
| Nom | Type | Description |
|---|---|---|
| marge | Numéro | Hauteur de la marge supérieure en points. |
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir la marge supérieure d’un paragraphe sur un point.
var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
var marginVal = 1.0;
var paraMarginTop = new sn_pdfgeneratorutils.Paragraph("Paragraph text with top margin set.");
paraMarginTop.setMarginTop(marginVal);
document.addParagraph(paraMarginTop);
// save pdf as attachment to target record in the Incident table
document.saveAsAttachment("incident", "<record_sys_id>", "docName.pdf");
Paragraphe – setTextAlignment(Alignement des chaînes)
Définit l’alignement du texte de ce paragraphe.
| Nom | Type | Description |
|---|---|---|
| Alignement | Chaîne | Position d’alignement du texte. Valeurs valides :
|
| Type | Description |
|---|---|
| Néant |
L’exemple suivant montre comment définir le texte du paragraphe sur l’alignement à gauche.
var paragraph = new sn_pdfgeneratorutils.Paragraph("This paragraph text is centered.");
var alignment = "text-center";
paragraph.setTextAlignment(alignment);