I am using Aspose.pdf version(20.12.0.0) to convert JPG to pdf format. But somehow one JPG file is not working.
It is stuck at pdf.Save(PDFTargetFilePath,SaveFormat.Pdf); line and creating a PDF file in the TargetFilepath with 0KB .Its not moving forward from here.
annulation.jpg (7.5 KB)
But when I use the latest version of Aspose.pdf (24.2.0) it throws an error at pdf.Save(PDFTargetFilePath,SaveFormat.Pdf); line
Error Message: Page have not room to place a paragraphs
Can you please tell me what’s the reason behind the error and also what will be the best approach to handle these kind of scenarios for avoiding these error.
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;
}
}