سؤال

I am trying to generate pdf file using Byte Array. The code is used is:

Public Sub SavePdf(ByVal bytes() As Byte)
    Dim filePath As String = HttpContext.Current.Server.MapPath("~/ClientBin/file1.pdf")
    Dim byteData() As Byte = bytes
    File.WriteAllBytes(filePath,byteData)
End Sub

The byte array is generated using richEditControl. The code is as follows:

 Public Sub generateByte_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim ms As MemoryStream = New MemoryStream()
    ms.Flush()
    richEditControl1.SaveDocument(ms, DocumentFormat.Rtf)
    client.SavePdf(ms.ToArray())
    MessageBox.Show("FileSaved")
End Sub

The file so generated can't be open.

هل كانت مفيدة؟

المحلول

I don't think .Rtf (Rich Text Format) data is equivalent to .Pdf (Portable document format).

It appears you are using the DevExpress RichEditControl which doesn't appear to support saving PDF files directly, see the documentation for available document formats.

I'd recommend either saving the RTF data with the .Rtf extension and use an RTF to PDF document converter after writing, or using a Pdf document writer library like PDFsharp.

To convert a .Rtf file to .Pdf you could either automate Microsoft Word (if you can assume it will be on the target machine) or use a standalone .Net library, e.g.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top