I have a program that uses WebClient
to download a file from a remote server. I am using DownloadData
rather than DownloadFile
because I don't really need the physical file. I am just taking the byte array and converting it to a base64 string for submission through an API as part of the payload. For some files, I will download them as RTF, but they need to be converted to a searchable PDF before I send them through the API. I'd rather handle this conversion with just the byte arrays in memory, rather than saving files to disk, then converting. Is there a way for me to take the RTF byte array and convert it to a (searchable) PDF byte array?
I tried just saving the rtf byte array to a pdf, but that does not work. Here's my code for that: System.IO.File.WriteAllBytes(@"C:\\temp\\pdfTest.pdf", fileBytes);
The following solution requires a Telerik subscription, but I am using it to convert an rtf byte array to a pdf byte array:
byte[] bOutput;
Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider RTFprovider = new Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider();
string strRTF = System.Text.Encoding.ASCII.GetString(bInput);
Telerik.Windows.Documents.Flow.Model.RadFlowDocument document = RTFprovider.Import(strRTF);
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider PDFprovider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
bOutput = PDFprovider.Export(document);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.