We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Facing issue in converting image to PDF

Hi support.
I am facing issue in converting Image to PDF using aspose version 17.9.0.0.
The image is converted to PDF but on signing the converted PDF document, specially when applying certified signature.
Note: This issue is only occurring in conversion of IMAGE to PDF.
Regards
Muddassir Awan

@Muddassir_Awan

Thank you for contacting support.

We would like to request you to please upgrade to Aspose.PDF for .NET 18.6 or Aspose.PDF for Java 18.5, as per your requirements, and then share your kind feedback with us. In case the issue persists, please share the source and generated files along with a narrowed down sample application reproducing this problem so that we may investigate further to help you out.

Hi.
I have upgraded aspose.pdf version to 18.6, and check the issue. Unfortunately the issue still persists.
Please find the attached image file and converSH Logo.png (2.2 KB)
ted PDF signed file.SH Logo.pdf (270.9 KB)

@Muddassir_Awan

Thank you for sharing requested data.

Please also share the code snippet reproducing the problem you are facing. Kindly include the .pfx file and its key, if any, while elaborating the problem a little and mentioning your environment details (OS details, .NET Framework Version etc) so that we may investigate further to help you out.

Following is the code snippet. I am using .NET Framework 4.5

void Convert_IMG_to_PDF(Stream fileStream = null)
{
var tempfile = Path.GetTempFileName();
var image = (Aspose.Imaging.FileFormats.Png.PngImage)Aspose.Imaging.Image.Load(InputFileName);
using (var CompressedFileStream = new FileStream(tempfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
image.Save(CompressedFileStream, new Aspose.Imaging.ImageOptions.PngOptions());
CompressedFileStream.Seek(0, System.IO.SeekOrigin.Begin);
Convert_IMG_to_PDF(CompressedFileStream);
}
Aspose.Pdf.Document PdfDocument = new Aspose.Pdf.Document();
Aspose.Pdf.Page Sec = PdfDocument.Pages.Add();

            Bitmap TempImage = null;

            if (fileStream != null)
                TempImage = new Bitmap(fileStream);
            else
                TempImage = new Bitmap(InputFileName);

            if (TempImage.Width > TempImage.Height)
                Sec.PageInfo.IsLandscape = true;
            else
                Sec.PageInfo.IsLandscape = false;
            Aspose.Pdf.Image Image = new Aspose.Pdf.Image();
            Image.FixWidth = TempImage.Width - Sec.PageInfo.Margin.Left - Sec.PageInfo.Margin.Right;
            Image.FixHeight = TempImage.Height - Sec.PageInfo.Margin.Top - Sec.PageInfo.Margin.Bottom;
            Sec.Paragraphs.Add(Image);

            if (fileStream != null)
                Image.ImageStream = GetImageFormat(System.Drawing.Image.FromStream(fileStream)) == System.Drawing.Imaging.ImageFormat.Png ? RemoveTransparency(fileStream) : fileStream;
            else
            {
                byte[] data = File.ReadAllBytes(InputFileName);
                fileStream = new MemoryStream(data);
                Image.ImageStream = GetImageFormat(System.Drawing.Image.FromStream(fileStream)) == System.Drawing.Imaging.ImageFormat.Png ? RemoveTransparency(fileStream) : fileStream;
            }
            using (var CompressedFileStream = new FileStream(tempfile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
            {
                if (!PdfDocument.IsPdfaCompliant)
                    PdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_1B, ConvertErrorAction.None);
                PdfDocument.Save(CompressedFileStream);
                OutputFileBytes = new byte[CompressedFileStream.Length];
                CompressedFileStream.Seek(0, System.IO.SeekOrigin.Begin);
                CompressedFileStream.Read(OutputFileBytes, 0, (int)CompressedFileStream.Length);
            }
        }

@Muddassir_Awan

Thank you for contacting support.

Your code snippet includes some undefined methods like RemoveTransparency and GetImageFormat so we can not compile the code in its present form. However, we have tried to convert your image file to PDF document by using below code snippet:

                Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
                Page page = doc.Pages.Add();
                Aspose.Pdf.Image image = new Aspose.Pdf.Image();
                image.File = dataDir + "SH Logo.png";
                page.Paragraphs.Add(image);
                doc.Save(dataDir + "SH LogoTest_18.6.pdf");

We have attached the generated file for your kind reference SH LogoTest_18.6.pdf. It looks fine as the image appears transparent on the PDF as well. Also, you do not need to use Aspose.Imaging API during this conversion, unless you want to manipulate the image. In case you still face the issue, please share a narrowed down application while elaborating the problem a little more, so that we may try to reproduce and investigate it as per your requirements.