CreateFromText Method (GdPicturePDF)
Converts text input, defined as a string, into a multipage (if required) PDF document.
public GdPictureStatus CreateFromText(
PdfConformance ,
float ,
float ,
float ,
float ,
float ,
float ,
TextAlignment ,
string ,
float ,
string ,
bool ,
bool ,
bool ,
bool
)
public function CreateFromText(
: PdfConformance;
: Single;
: Single;
: Single;
: Single;
: Single;
: Single;
: TextAlignment;
: String;
: Single;
: String;
: Boolean;
: Boolean;
: Boolean;
: Boolean
): GdPictureStatus;
public function CreateFromText(
: PdfConformance,
: float,
: float,
: float,
: float,
: float,
: float,
: TextAlignment,
: String,
: float,
: String,
: boolean,
: boolean,
: boolean,
: boolean
) : GdPictureStatus;
public: GdPictureStatus CreateFromText(
PdfConformance ,
float ,
float ,
float ,
float ,
float ,
float ,
TextAlignment ,
string* ,
float ,
string* ,
bool ,
bool ,
bool ,
bool
)
public:
GdPictureStatus CreateFromText(
PdfConformance ,
float ,
float ,
float ,
float ,
float ,
float ,
TextAlignment ,
String^ ,
float ,
String^ ,
bool ,
bool ,
bool ,
bool
)
'Declaration
Public Function CreateFromText( _
ByVal As PdfConformance, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single, _
ByVal As Single, _
ByVal As TextAlignment, _
ByVal As String, _
ByVal As Single, _
ByVal As String, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean, _
ByVal As Boolean _
) As GdPictureStatus
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.
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();