Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.Net中的文本转换为PDF_Vb.net_String_Pdf - Fatal编程技术网

VB.Net中的文本转换为PDF

VB.Net中的文本转换为PDF,vb.net,string,pdf,Vb.net,String,Pdf,有人知道如何获取字符串并将其保存到PDF文件吗 Dim str As String 'Put it into PDF Document 'Save to PDF DOcument 谢谢 初学者您可以使用itextSharp库创建pdf文档。我正在使用C#: 你的绳子是 str="Hello World!" 使用图书馆: using iTextSharp.text; using iTextSharp.text.pdf; 将文档创建为: Document pdfDocument = new D

有人知道如何获取字符串并将其保存到PDF文件吗

Dim str As String
'Put it into PDF Document
'Save to PDF DOcument
谢谢


初学者

您可以使用itextSharp库创建pdf文档。我正在使用C#:

你的绳子是

str="Hello World!"
使用图书馆:

using iTextSharp.text;
using iTextSharp.text.pdf;
将文档创建为:

Document pdfDocument = new Document(PageSize.A4, 20f, 20f, 20f, 20f);
将文档写入磁盘:

PdfWriter.GetInstance(pdfDocument, new FileStream(filePathToDisk, FileMode.Create));
设置字符串:

Paragraph newParagraph = new Paragraph(str);

pdfDocument.Open();
pdfDocument.Add(newParagraph);
pdfDocument.Close();
pdfDocument.Dispose();
这将创建您的Pdf文件。

尝试使用此文件(免责声明:我是该库的开发人员之一)

下面是一个示例,演示如何在指定的矩形中绘制一行文字或多行文字

Imports System.Diagnostics
Imports System.Drawing

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class DrawText
        Public Shared Sub Main()
            Dim pathToFile As String = "DrawText.pdf"

            Using pdf As New PdfDocument()
                Dim canvas As PdfCanvas = pdf.Pages(0).Canvas

                canvas.DrawString(10, 50, "Hello, world!")

                Const longString As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
                canvas.DrawString(longString, New RectangleF(10, 70, 40, 150), PdfTextAlign.Left, PdfVerticalAlign.Top)
                canvas.DrawText(longString, New RectangleF(70, 70, 40, 150), PdfTextAlign.Left, PdfVerticalAlign.Top)

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace