mardi 24 février 2015

image to pdf conversion without using third party library in C#

I have an urgent requirement in my project that i need to convert image files to PDF without using third party libraries in C#. The images can be in any format like (.jpg,.png,.jpeg,.tiff).


I am successfully able to do this with the help of itextsharp. here is the code.



string value = string.Empty;//value contains the data from a json file
List<string> sampleData;
public void convertdata()
{
//sampleData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(value);
var jsonD = System.IO.File.ReadAllLines(@"json.txt");
sampleData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(jsonD[0]);
Document document = new Document();

using (var stream = new FileStream("test111.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfWriter.GetInstance(document, stream);
document.Open();

foreach (var item in sampleData)
{
newdata = Convert.FromBase64String(item);
var image = iTextSharp.text.Image.GetInstance(newdata);
document.Add(image);
Console.WriteLine("Conversion done check folder");

}
document.Close();
}


But now i need to perform the same without using third party library.


I have searched the internet but i am unable to get something that can suggest a proper answer. All i am getting is to use it with either "itextsharp" or "PdfSharp" or with the "GhostScriptApi".


please suggest...??


Aucun commentaire:

Enregistrer un commentaire