byte[] pdfAsByteArray = File.ReadAllBytes(@"D:\a_images\2_b.jpg");
Stream stream = new MemoryStream(pdfAsByteArray);
radPdfViewer.LoadDocument(stream);
There is no issue with the image or with the image permissions but it is not displaying in the radpdfviewer
1 Answer, 1 is accepted
0
Dimitar
Telerik team
answered on 09 Mar 2020, 09:46 AM
Hello, Kunal,
I would like to clarify that RadPdfViewer is a control that natively visualize PDF documents straight in your application. However, you cannot add an image using the LoadDocument(Stream stream) method because this method loads a PDF document from a specified stream.
If you provide a PDF document to your stream instead of an image file ("2_b.jpg") it will work as expected.
Alternatively, you can use RadPdfProccessing to add an Image in the Content collection of a IContainerElement such as RadFixedPage. Then you can add an image to the mentioned page and create a PDF document which you can load with LoadDocument method. You can achieve that as follows:
privatevoidradButton1_Click(object sender, EventArgs e)
{
byte[] imageAsByteArray = File.ReadAllBytes(imagePath);
Stream stream = new MemoryStream(imageAsByteArray);
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = new RadFixedPage();
page.Content.AddImage(new ImageSource(stream));
document.Pages.Add(page);
document.DocumentInfo.Author = "Author1";
document.DocumentInfo.Title = "RadFixedDocument";
PdfFormatProvider provider = new PdfFormatProvider();
using (FileStream fs = new FileStream("..\\..\\test.pdf", FileMode.Create))
{
provider.Export(document, fs);
}
this.radPdfViewer1.LoadDocument("..\\..\\test.pdf");
}
You might also wanna checkout our RadRichTextEditor control which is able to insert images, display and edit rich-text content including formatted text arranged in pages, paragraphs, spans (runs), tables, etc. You can find more information here.
Please don't hesitate to ask if you have further questions.
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.Learn More.