I have a function to create a pdf which should return bitarray. Below is the code
Public Function GenPDF() As BitArray
Dim pdfdoc1 As BitArray
Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
Try
Dim MemStream As New MemoryStream
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, MemStream)
'Open Document to write
doc.Open()
'Write some content
Dim paragraph As New Paragraph("This is my first line using Paragraph.")
Dim pharse As New Phrase("This is my second line using Pharse.")
Dim chunk As New Chunk(" This is my third line using Chunk.")
' Now add the above created text using different class object to o开发者_如何学Cur pdf document
doc.Add(paragraph)
doc.Add(pharse)
doc.Add(chunk)
pdfdoc1 = MemStream.GetBuffer()
Catch dex As DocumentException
'Handle document exception
Catch ex As Exception
'Handle Other Exception
Finally
'Close document
doc.Close()
End Try
But it is throwing an error at this line pdfdoc1 = MemStream.GetBuffer() value of type 1-dimensional array cannot be converted to system.collections.bitarray Please help
From the MSDN documentation of BitArray the BitArray class represents something similar to an array of Booleans:
Manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).
Although you might interpret this to mean that it stores 1s and 0s, what it is really saying is that it stores True and False.
On the other hand, MemoryStream.GetBuffer() returns an array of Byte. So, the two are not compatible, because a Byte is not a Boolean.
Try this:
Public Function GenPDF() As Byte() ' Don't forget to change your return type.
Dim pdfdoc1 As Byte() ' Changed this to the correct type.
Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
Try
Dim MemStream As New MemoryStream
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, MemStream)
'Open Document to write
doc.Open()
'Write some content
Dim paragraph As New Paragraph("This is my first line using Paragraph.")
Dim pharse As New Phrase("This is my second line using Pharse.")
Dim chunk As New Chunk(" This is my third line using Chunk.")
' Now add the above created text using different class object to our pdf document
doc.Add(paragraph)
doc.Add(pharse)
doc.Add(chunk)
pdfdoc1 = MemStream.GetBuffer()
Catch dex As DocumentException
'Handle document exception
Catch ex As Exception
'Handle Other Exception
Finally
'Close document
doc.Close()
End Try
精彩评论