public static bool Convert2(string image, string pdf) { try { using Document doc = new Document { OptimizeSize = true, IgnoreCorruptedObjects = true }; Page p = doc.Pages.Add(); Rectangle rect = p.TrimBox; using Stream input = File.OpenRead(image); using MemoryStream stream = new MemoryStream(); p.AddImage(input, rect); doc.OptimizeResources(); doc.Optimize(); doc.Save(pdf); return true; } catch (Exception) { return false; } }
the codes can execute successfully.
but I got a WARNING on console,as following(when the image is pngformat):
** (process:17336): WARNING **: 08:56:48.434: Unknown metafile format: key 1196314761
or (when the image is jpeg format)
** (process:17336): WARNING **: 08:56:48.434: Unknown metafile format: key -520103681