I am using Aspose.pdf to convert png to pdf format. But somehow one strange file is not working.
It is stuck at pdf.Save(PDFTargetFilePath,SaveFormat.Pdf); line .Its not moving forward from here. vasco733.png (22.7 KB)
Also i am attaching source code here.
public static class PDFConverterTest
{
public static void ConvertPNGTOPDF(string PNGImageFilePath,string PDFTargetFilePath)
{
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document();
Bitmap bitmap = new Bitmap(PNGImageFilePath);
int width = bitmap.Width;
int height = bitmap.Height;
string tmpJpg = GetTempFileName();
bitmap.Save(tmpJpg, ImageFormat.Png);
bitmap.Dispose();
//Create a section in the Pdf object
Page sec2 = pdf.Pages.Add();
//Create an image object in the section
Aspose.Pdf.Image image2 = new Aspose.Pdf.Image();
//Add image object into the Paragraphs collection of the section
sec2.Paragraphs.Add(image2);
//Set the path of image file
image2.File = tmpJpg;
sec2.PageInfo.Width = width + 2.04f;
sec2.PageInfo.Height = height + 2.04f;
pdf.Save(PDFTargetFilePath,SaveFormat.Pdf);
}
static string GetTempFileName()
{
string Temp = “”;
do
{
Temp = Path.GetTempPath() + Path.GetRandomFileName();
} while (File.Exists(Temp));
return Temp;
}
}