GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / CreateFromText Method
A member of the PdfConformance enumeration. Specifies the required conformance to the PDF or PDF/A standard of a newly created PDF document.

If you use the value of the PdfConformance.PDF, the toolkit will create the PDF document conformed to the lowest PDF version (version 1.3 is the minimum) based on what the output PDF document will contain.

Please note that the fonts are always embedded in a PDF/A compliant file regardless of what you specify in the Embedded parameter.

Sets the page width of a new PDF document in points.
Sets the page height of a new PDF document in points.
Sets the width of the left margin on pages in points.
Sets the height of the top margin on pages in points.
Sets the width of the right margin on pages in points.
Sets the height of the bottom margin on pages in points.
A member of the TextAlignment enumeration. Specifies the horizontal alignment of the text within the bounding box.
Contains the input text as a string. This text will be set as a content of a new PDF document.
Sets the text size in points.
Specifies the name of the font to write the input text in.
Sets the font weight. Set this parameter to true if you want to use bold font, otherwise set it to false.
Sets the font style. Set this parameter to true if you want to use italic font, otherwise set it to false.
Specifies the font embedding. Set this parameter to true if you want to embed the font into a newly created PDF document, otherwise set it to false.

Please note that embedding the font inside the PDF document always increases the document's size. But for a better portability of PDF documents it is recommended to embed the fonts into the files. The fonts are always embedded in a PDF/A compliant file regardless of the Embedded parameter.

Also the font you specify needs to allow copying to be embedded into a PDF file. The fonts under copyright cannot be copied.

Specifies if the font's bounding box should be used to determine the height of the font. It is set to false by default. You can set it to true for better calculation of the line spacing.
Example





In This Topic
CreateFromText Method (GdPicturePDF)
In This Topic
Converts text input, defined as a string, into a multipage (if required) PDF document.
Syntax
'Declaration
 
Public Function CreateFromText( _
   ByVal Conformance As PdfConformance, _
   ByVal PageWidth As Single, _
   ByVal PageHeight As Single, _
   ByVal MarginLeft As Single, _
   ByVal MarginTop As Single, _
   ByVal MarginRight As Single, _
   ByVal MarginBottom As Single, _
   ByVal TextAlignment As TextAlignment, _
   ByVal Text As String, _
   ByVal TextSize As Single, _
   ByVal FontName As String, _
   ByVal FontBold As Boolean, _
   ByVal FontItalic As Boolean, _
   ByVal Embedded As Boolean, _
   ByVal UseFontBBox As Boolean _
) As GdPictureStatus
public GdPictureStatus CreateFromText( 
   PdfConformance Conformance,
   float PageWidth,
   float PageHeight,
   float MarginLeft,
   float MarginTop,
   float MarginRight,
   float MarginBottom,
   TextAlignment TextAlignment,
   string Text,
   float TextSize,
   string FontName,
   bool FontBold,
   bool FontItalic,
   bool Embedded,
   bool UseFontBBox
)
public function CreateFromText( 
    Conformance: PdfConformance;
    PageWidth: Single;
    PageHeight: Single;
    MarginLeft: Single;
    MarginTop: Single;
    MarginRight: Single;
    MarginBottom: Single;
    TextAlignment: TextAlignment;
    Text: String;
    TextSize: Single;
    FontName: String;
    FontBold: Boolean;
    FontItalic: Boolean;
    Embedded: Boolean;
    UseFontBBox: Boolean
): GdPictureStatus; 
public function CreateFromText( 
   Conformance : PdfConformance,
   PageWidth : float,
   PageHeight : float,
   MarginLeft : float,
   MarginTop : float,
   MarginRight : float,
   MarginBottom : float,
   TextAlignment : TextAlignment,
   Text : String,
   TextSize : float,
   FontName : String,
   FontBold : boolean,
   FontItalic : boolean,
   Embedded : boolean,
   UseFontBBox : boolean
) : GdPictureStatus;
public: GdPictureStatus CreateFromText( 
   PdfConformance Conformance,
   float PageWidth,
   float PageHeight,
   float MarginLeft,
   float MarginTop,
   float MarginRight,
   float MarginBottom,
   TextAlignment TextAlignment,
   string* Text,
   float TextSize,
   string* FontName,
   bool FontBold,
   bool FontItalic,
   bool Embedded,
   bool UseFontBBox
) 
public:
GdPictureStatus CreateFromText( 
   PdfConformance Conformance,
   float PageWidth,
   float PageHeight,
   float MarginLeft,
   float MarginTop,
   float MarginRight,
   float MarginBottom,
   TextAlignment TextAlignment,
   String^ Text,
   float TextSize,
   String^ FontName,
   bool FontBold,
   bool FontItalic,
   bool Embedded,
   bool UseFontBBox
) 

Parameters

Conformance
A member of the PdfConformance enumeration. Specifies the required conformance to the PDF or PDF/A standard of a newly created PDF document.

If you use the value of the PdfConformance.PDF, the toolkit will create the PDF document conformed to the lowest PDF version (version 1.3 is the minimum) based on what the output PDF document will contain.

Please note that the fonts are always embedded in a PDF/A compliant file regardless of what you specify in the Embedded parameter.

PageWidth
Sets the page width of a new PDF document in points.
PageHeight
Sets the page height of a new PDF document in points.
MarginLeft
Sets the width of the left margin on pages in points.
MarginTop
Sets the height of the top margin on pages in points.
MarginRight
Sets the width of the right margin on pages in points.
MarginBottom
Sets the height of the bottom margin on pages in points.
TextAlignment
A member of the TextAlignment enumeration. Specifies the horizontal alignment of the text within the bounding box.
Text
Contains the input text as a string. This text will be set as a content of a new PDF document.
TextSize
Sets the text size in points.
FontName
Specifies the name of the font to write the input text in.
FontBold
Sets the font weight. Set this parameter to true if you want to use bold font, otherwise set it to false.
FontItalic
Sets the font style. Set this parameter to true if you want to use italic font, otherwise set it to false.
Embedded
Specifies the font embedding. Set this parameter to true if you want to embed the font into a newly created PDF document, otherwise set it to false.

Please note that embedding the font inside the PDF document always increases the document's size. But for a better portability of PDF documents it is recommended to embed the fonts into the files. The fonts are always embedded in a PDF/A compliant file regardless of the Embedded parameter.

Also the font you specify needs to allow copying to be embedded into a PDF file. The fonts under copyright cannot be copied.

UseFontBBox
Specifies if the font's bounding box should be used to determine the height of the font. It is set to false by default. You can set it to true for better calculation of the line spacing.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
Please note that 1 point = 1/72 inch.

This method requires the PDF Processing component to run.

Example
How to create a PDF file from the text input.
Dim myFile As New System.IO.StreamReader("MyTextFile.txt")
Dim content As String = myFile.ReadToEnd()
myFile.Close()
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.CreateFromText(PdfConformance.PDF_A_1b, 595, 842, 10, 10, 10, 10, TextAlignment.TextAlignmentNear, content, 12, "Arial", False, False, True, False)
If status = GdPictureStatus.OK Then
    status = gdpicturePDF.SaveToFile("PDFfromText.pdf", False)
    If status = GdPictureStatus.OK Then
        MessageBox.Show("Your new PDF has been created successfully.", "Example: CreateFromText")
    Else
        MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: CreateFromText")
    End If
Else
    MessageBox.Show("The CreateFromText() method has failed with the status: " + status.ToString(), "Example: CreateFromText")
End If
gdpicturePDF.Dispose()
System.IO.StreamReader myFile = new System.IO.StreamReader("MyTextFile.txt");
string content = myFile.ReadToEnd();
myFile.Close();
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.CreateFromText(PdfConformance.PDF_A_1b, 595, 842, 10, 10, 10, 10, TextAlignment.TextAlignmentNear, content, 12, "Arial", false, false, true, false);
if (status == GdPictureStatus.OK)
{
    status = gdpicturePDF.SaveToFile("PDFfromText.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        MessageBox.Show("Your new PDF has been created successfully.", "Example: CreateFromText");
    }
    else
    {
        MessageBox.Show("The file can't be saved. Status: " + status.ToString(), "Example: CreateFromText");
    }
}
else
{
    MessageBox.Show("The CreateFromText() method has failed with the status: " + status.ToString(), "Example: CreateFromText");
}
gdpicturePDF.Dispose();
See Also