We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

convert txt,bmp,gif,png files to pdf

How can we convert txt,bmp,gif,png files to pdf?
Please provide samples.

Sarath.

3 Replies

CM Chinnu Muniyappan Syncfusion Team April 6, 2017 12:35 PM UTC

Hi Sarath, 
 
Thank you for contacting Syncfusion support. 
 
Please refer the below documentation link for drawing text and images to the PDF document 
 
 
Please let us know if you have any concern. 
 
Regards, 
Chinnu 



AJ ashish jayara January 8, 2018 03:28 PM UTC

HI 

 Is the above link working for core 2 As well? i am getting error while saving Document "Can't convert string to System.IO.Stream".


SL Sowmiya Loganathan Syncfusion Team January 9, 2018 09:57 AM UTC

Hi Sarath, 

Yes, the documentation link for drawing text and images to the PDF document works in dot net Core 2 also. It is not possible to save PDF document directly to specified file location in dot net core platform, instead we can save using memory stream. 

Please find the below code snippet for more details : 

            //Create a new PDF document. 
 
            PdfDocument doc = new PdfDocument(); 
 
            //Add a page to the document. 
 
            PdfPage page = doc.Pages.Add(); 
 
            //Create PDF graphics for the page 
 
            PdfGraphics graphics = page.Graphics; 
 
            string imagePath = _hostingEnvironment.WebRootPath + "image.jpg"; 
            Stream imageStream = new FileStream(imagePath, FileMode.Open); 
 
            //Load the image from the disk. 
 
            PdfBitmap image = new PdfBitmap(imageStream); 
 
            //Draw the image 
 
            graphics.DrawImage(image, 0, 0); 
 
            //Saving the PDF to the MemoryStream 
            MemoryStream stream = new MemoryStream(); 
 
            doc.Save(stream); 
            doc.Close(true); 
 
            //If the position is not set to '0' then the PDF will be empty. 
            stream.Position = 0; 
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); 
            fileStreamResult.FileDownloadName = "Sample.pdf"; 


Please let us know if you need further assistance. 

Regards, 
Sowmiya L 


Loader.
Live Chat Icon For mobile
Up arrow icon