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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

convert txt,bmp,gif,png files to pdf

Thread ID:

Created:

Updated:

Platform:

Replies:

129827 Apr 5,2017 11:15 AM UTC Jan 9,2018 09:57 AM UTC ASP.NET Web Forms 3
loading
Tags: PDF
Sarath Babu Kola
Asked On April 5, 2017 11:15 AM UTC

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

Sarath.

Chinnu Muniyappan [Syncfusion]
Replied On 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 


ashish jayara
Replied On 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".

Sowmiya Loganathan [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;