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

Free Support Forum - aspose.com

Exception when converting EMF(consist of a lot sharps) to PDF

We are using the following code to convert EMF to PDF:

In most case, it works perfectly.(2000 - 3000 lines)
But when the EMF contain a lot of sharps(4000 - 6000 lines), it throw exception at the CacheData().

I search this forum and found a similar topic, but I still encounter this problem after I upgraded Imaging to the latest version.

        private void EmfToPdf(MemoryStream msEmf, Stream outStream)
            msEmf.Seek(0, SeekOrigin.Begin);

            using (var img = Aspose.Imaging.Image.Load(msEmf) as Aspose.Imaging.FileFormats.Emf.EmfImage)

                var emfRasterizationOptions = new Aspose.Imaging.ImageOptions.EmfRasterizationOptions
                    BackgroundColor = Aspose.Imaging.Color.White,
                    PageSize = img.SizeF,
                    RenderMode = Aspose.Imaging.FileFormats.Emf.EmfRenderMode.EmfOnly

                var pdfOptions = new Aspose.Imaging.ImageOptions.PdfOptions
                    VectorRasterizationOptions = emfRasterizationOptions

                // save in different formats
                img.Save(outStream, pdfOptions);

@weibanban, please attach the file in which the problems are observed.
The CacheData method can be omitted in this case. It makes sense to call this method only if you are make changes to the emf.

the exception info:

$exception {“Unable to read beyond the end of the stream.”} System.IO.EndOfStreamException
at System.IO.__Error.EndOfFile()
at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
at System.IO.BinaryReader.ReadSingle()
at .(Int32 , BinaryReader )
at . ​ (EmfPlusRecord& , BinaryReader , )
at .(Int32 )
at ​ .(EmfRecord& , BinaryReader , Int32 , Int32 , )
at ​ . ​ (EmfRecord& , BinaryReader , )
at .(EmfImage )
at Aspose.Imaging.FileFormats.Emf.EmfImage.CacheData()

If comment CacheData, the exception occur at the Save line.
Since the image contain sensitive info, I cannot upload it here.

@weibanban, please attach the file in which the problems are observed.

Add Reg into the loop

Could you upload and transfer the file to me via a private message?
Without the file, I won’t be able to help you.

data.zip (243.5 KB)

BTW: I generated the data file by System.IO.File.WriteAllBytes(@"C:\\data", msEmf.ToArray());

ConsoleApp7.zip (4.2 KB)
@weibanban, CacheData () is really a bug, but if you remove this line, then everything works as it should.
I checked on the latest version - 21.12.0
Please see the attached project.

The issues you have found earlier (filed as IMAGINGNET-5044) have been fixed in this update. This message was posted using Bugs notification tool by samer.el-khatib4aspose