Hi
I have a piece of code that works perfectly most of the times for converting word files to PDF
public static void ConvertWordToPdf(string filename, string base64)
{
try
{
var AsposeLicense = ConfigurationManager.AppSettings["AsposeLicense"];
var license = new License();
license.SetLicense(AsposeLicense);
var content = Convert.FromBase64String(base64);
var fromMemoryStream = new MemoryStream(content, 0, content.Length);
var document = new Document(fromMemoryStream);
var toMemoryStream = new MemoryStream();
document.Save(toMemoryStream, SaveFormat.Pdf);
File.WriteAllBytes(filename, toMemoryStream.ToArray());
}
catch (Exception ex)
{
Console.WriteLine("WordHandler.ConvertWordToPdf Failed: ", ex);
}
}
I call to this method something like this:
var file_name = @"c:\temp\111.pdf";
var base64_content = ".......";
ConvertWordToPdf(file_name, base64_content);
The problem is that in some cases the word content fails to be converted to PDF - here is a link to a sample PDF file (https://www.dropbox.com/scl/fi/asasqfxnc0466jc6l8qae/Sample_Word_File.doc?dl=0&rlkey=ymuqvtcmxa5piw0squ6af20yk).
In order to create base64 from its content I opened the file using Notepad++, selected all content and chose “Plugins” => “Mime Tools” => “Base64 Encode with padding”.
The error I get when saving is simply “Object reference not set to an instance of an object.” and the stack trace is:
at x06e283fdfa5dc5f0.x5f887a65c13f569c.x413b45190f5b64bc(Single x56807c4768855de3, Border x3b886490b22eee28)|
at x06e283fdfa5dc5f0.x5f887a65c13f569c.xb1e2c9a68308ad60(RectangleF xdc901b9828d8600c, Border xdb200d0a72bd656e, Border xc55498ae473c1804, Border x39d4d9d592924ac5, Border xd1516a9a5bb6b163)|
at x99ec507695f2d4ff.x42b8c317113a56e4.x16c1fa2b17e1e8ac(x038d2057eb729fcf x5906905c888d3d98)|
at x99ec507695f2d4ff.x42b8c317113a56e4.xc57fb21ab216f7ff(x038d2057eb729fcf x5906905c888d3d98)|
at x99ec507695f2d4ff.x42b8c317113a56e4.xa2007eb3b6f579d9(x96fdc2b3abde93b1 x5906905c888d3d98)|
at x6a42c37b95e9caa1.xfef22f4f866de8d2.xaa9ea643e6d66d7b(x96fdc2b3abde93b1 x5906905c888d3d98)|
at x59d6a4fc5007b7a4.x96fdc2b3abde93b1.x7012609bcdb39574(x3adba2572f6b9747 x672ff13faf031f3d)|
at x59d6a4fc5007b7a4.x6a53cec2ada67e5c.x7012609bcdb39574(x3adba2572f6b9747 x672ff13faf031f3d)|
at x59d6a4fc5007b7a4.xbf5b03855bcdbdae.x7012609bcdb39574(x3adba2572f6b9747 x672ff13faf031f3d)|
at x59d6a4fc5007b7a4.xb850ecb8335a2e09.xa246eb87eda7b55d(x3adba2572f6b9747 x672ff13faf031f3d, x398b3bd0acd94b61 xd7e5673853e47af4)|
at x59d6a4fc5007b7a4.xc6ae5bf3fc6721e2.x7012609bcdb39574(x3adba2572f6b9747 x672ff13faf031f3d)|
at x59d6a4fc5007b7a4.x512b9a381ad7cd9c.x7012609bcdb39574(x3adba2572f6b9747 x672ff13faf031f3d)|
at x59d6a4fc5007b7a4.xdcf47a8f1807f37c.x7012609bcdb39574(x3adba2572f6b9747 x672ff13faf031f3d)|
at x6a42c37b95e9caa1.xfef22f4f866de8d2.xe406325e56f74b46(xdcf47a8f1807f37c x32eaf67d0ee57cb7, xdeb77ea37ad74c56 x1e972e751678e682)|
at Aspose.Words.Document.xaef272a322936116(Int32 xbf13a47a02af0066)|
at xf989f31a236ff98c.x6c74398bceb133f8.xa2e0b7f7da663553(x8556eed81191af11 x5ac1382edb7bf2c2)|
at Aspose.Words.Document.xf381a641001e6830(Stream xcf18e5243f8d5fd3, String xafe2f3653ee64ebc, SaveOptions xc27f01f21f67608c)|
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)|
at Aspose.Words.Document.Save(Stream stream, SaveFormat saveFormat)|
at ConsoleApp5.Program.ConvertWordToPdf(String filename, String base64) in
C:\\source\\repos\\ConsoleApp5\\ConsoleApp5\\Program.cs:line 30
If anyone can reproduce the issue and try find some workaround or fix that will be great - I’m really frustrated about this one.
Thanks