Aspose.Word under mono

Hi Aspose Team,
I’m trying to resolve 2 issues with aspose.words under mono/apache. Do you have any information on this that could help me ? Thanks
1- CultureInfo, mono, mod_mono, apache and date language
template : { MERGEFIELD date @ “d MMMM yyyy”}
data : 1 column (type string), 1 row (“2011/01/01”)
When I merge my template with this data in an executable under mono, it works fine, the mergefield is replaced by “1 janvier 2011”.
Thread.CurrentThread.CurrentCulture.Name returns “fr-FR”.
The same code with an ASPNET application (mono + apache) replace the mergefield whith the date in english.
Thread.CurrentThread.CurrentCulture.Name returns string.empty.
2- pdf conversion under mono
When I try to save any .doc file as .pdf file, I’m getting this exception :
ex.Message :

An exception was thrown by the type initializer for Ø—.à±
ex.StackTrace :
at 㚮.䖝.੮ (System.String ࡋ, System.Drawing.Font ੴ) [0x00000] in :0 
at 㚮.䖝.੮ (System.String ࡋ) [0x00000] in :0 
at 㚮.ṟ.get_Თ () [0x00000] in :0 
at 㚮.ṟ.get_࣍ () [0x00000] in :0 
at 㚮.䬷.㗑 () [0x00000] in :0 
at ãš®.䛶.ã—‘ (Int32 ä"¬) [0x00000] in :0 
at 㚮.䬂.䬖 (㚮.䛶 ၅) [0x00000] in :0 
at ãš®.䬂.䬗 (ãš®.䛶 Ꮲ, Int32 ä¢") [0x00000] in :0 
at ãš®.䬂.䬍 (ãš®.⎠၅, Int32 ä¢") [0x00000] in :0 
at ãš®.䬂.ã—‘ (Int32 ä¢") [0x00000] in :0 
at 㚮.䫯.䫷 () [0x00000] in :0 
at ãš®.䫯.ã—‘ (Int32 ä¢") [0x00000] in :0 
at ãš®.äž„.ã—‘ (Int32 ä"¬) [0x00000] in :0 
at 㚮.䫗.䫙 (㚮.䞄 㥻) [0x00000] in :0 
at ãš®.ä«—.䫘 (ãš®.ä"— ⍰) [0x00000] in :0 
at ãš®.ä".ã—‘ (ãš®.ä"— ä"½) [0x00000] in :0 
at ãš®.ä"—.ã—‘ (Boolean ä"Š) [0x00000] in :0 
at ãš®.ä"‹.ã—‘ (Boolean ä"Š) [0x00000] in :0 
at ãš®.ä–¯.ã—‘ (Boolean ä"Š) [0x00000] in :0 
at Ἕ.ӧ.䒵 (Aspose.Words.Document ๗, Ἕ.Ө 㒱) [0x00000] in :0 
at Aspose.Words.Document.UpdatePageLayout () [0x00000] in :0 
at Aspose.Words.Document.get_Ó§ () [0x00000] in :0 
at Aspose.Words.Document.get_PageCount () [0x00000] in :0 
at Aspose.Words.Document.Ô" (System.IO.Stream ԍ, System.String Ô‹, SaveFormat Ô•) [0x00000] in :0 
at Aspose.Words.Document.Save (System.String fileName, SaveFormat fileFormat) [0x00000] in :0 
at Aspose.Words.Document.Save (System.String fileName) [0x00000] in :0 
at TestsAsposeMono.Program.Main (System.String[] args) [0x00000] in :0 
ex.InnerException :
System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.WindowsFormsSynchronizationContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI ---> System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (IntPtr display_handle) [0x00000] in :0 
at System.Windows.Forms.XplatUIX11..ctor () [0x00000] in :0 
at System.Windows.Forms.XplatUIX11.GetInstance () [0x00000] in :0 
at System.Windows.Forms.XplatUI..cctor () [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Windows.Forms.Theme.get_MenuAccessKeysUnderlined () [0x00000] in :0 
at System.Windows.Forms.SystemInformation.get_MenuAccessKeysUnderlined () [0x00000] in :0 
at System.Windows.Forms.Control..ctor () [0x00000] in :0 
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:.ctor ()
at System.Windows.Forms.WindowsFormsSynchronizationContext..cctor () [0x00000] in :0 
--- End of inner exception stack trace ---
at System.Windows.Forms.Control..ctor () [0x00000] in :0 
at System.Windows.Forms.ScrollableControl..ctor () [0x00000] in :0 
at System.Windows.Forms.ContainerControl..ctor () [0x00000] in :0 
at System.Windows.Forms.Form..ctor () [0x00000] in :0 
at (wrapper remoting-invoke-with-check) System.Windows.Forms.Form:.ctor ()
at Ø—.à±..cctor () [0x00000] in :0

Hi
Thanks for your request.

  1. I think you can just set current culture to get the expected result. For instance see the following code:
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
// Set German culture for testing. 
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
Document doc = new Document(@"Test001\in.doc");
doc.MailMerge.Execute(new string[] { "fieldName1" }, new object[] { 0 });
doc.Save(@"Test001\out.doc");
Thread.CurrentThread.CurrentCulture = currentCulture;
  1. I think, the problem might occur because Aspose.Word cannot find fonts. Currently, Aspose.Words expects to find fonts in /usr/share/fonts/ttf. So please make sure that this folder contains TrueType fonts.
    https://docs.aspose.com/words/net/system-requirements/
    Hope this helps.
    Best regards.

Hi
1- thank you for this workaround, but I’m trying to understand why I lost cultureinfo when i run an ASPNET application
2- Doc to pdf conversion works fine with an executable, but don’t work with my ASPNET application.
It seems that the environment variable DISPLAY isn’t correct in this case (System.ArgumentNullException: Could not open display (X-Server required. Check you DISPLAY environment variable))
When you did some tests on mono, did you try with an ASPNET application or you launched an executable ? Maybe I forget something on mod_mono or apache configuration, but it’s hard to find any information on this, and if you get these issues while testing, any infomation would be usefull for me :wink: .
Thanks for your help

Hi
Thanks for your request.

  1. This might occur if you did not specify default culture for your ASP.NET application. In this case if a specific culture is not specified (or empty string used instead of culture name), InvariantCulture is used.
    You can try specifying default culture of your ASP.NET application in web.config in globalization section:
    https://learn.microsoft.com/en-US/troubleshoot/developer/webapps/aspnet/development/set-current-culture
  2. I will configure environment with mono and apache and let you know how it goes on my side.
    Best regards,

Hi
Just tested PDF generation in ASP.NET application run under mono in apache. Here is simple code I used for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello World!!!");
doc.Save(Response, "out.pdf", ContentDisposition.Attachment, new PdfSaveOptions());

I can successfully generate and open the generated PDF document on my side.
Best regards,

Hi
I’m testing again with latest version of Aspose.Words (9.7.00)
I’m getting this exception: Cannot find black listed licenses resource. Please report this error to Aspose.
I tried to attach my license file but license files are not allowed here. Should I send it by email ?
Any idea ?
Thanks

Hi
Thanks for your request. Which of Aspose.Words dlls do you use? There are dlls for .NET 1.1, 2.0 and 3.5. I used .NET 2.0 dll for testing. Which version of mono do you use? On my side I used mono 2.6.7.
The problem also can occur if you disassembled the Aspose.Words.dll and tried to change it.
Best regards,

I used Net 2.0 dlls. I’m testing with mono 2.4.3.1.
I’ll try with mono 2.6.7
Thanks

Hi
Please let me know how it goes with Mono 2.6.7.
In addition, I would suggest you use the latest version of Aspose.Words (9.8.0). In the latest version of Aspose.Words we added an ability to specify folder(s) where Aspose.Words should look for fonts. This ability is very important if you use Aspose.Words under mono in Linux.
For instance, you can use the following code to specify fonts directory:

// Aspose.Words will look for fonts in the specified directory and all subdirectories.
FontSettings.SetFontsFolder("/usr/share/fonts", true);
Document doc = new Document("/home/alexey/Projects/in.doc");
doc.Save("/home/alexey/Projects/out.pdf");

You can download the latest version from here:
https://releases.aspose.com/words/net
Best regards,

Thank you for your quick replies.
I’ve updated mono and aspose dlls :
mono 2.6.7 (+mod_mono/apache)
Aspose.Words.dll 9.8.0
Aspose.Cells.dll 5.3.2
Aspose.Slides.dll 5.1.0
Aspose.pdf.dll 5.1.0
The same .lic file is used for each test.
Test #1 : .doc creation with Aspose.Words
Cannot load built in styles from an embedded resource.

System.NotSupportedException: CodePage 1251 not supported at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 at x0ba9768691592c95.x77d7a46711f04d5d.xfa1f0074ea24621b (System.IO.BinaryReader xe134235b3526fa75, Int32 xc1690d3515e1ed6c) [0x00000] in <filename unknown>:0 at x0ba9768691592c95.x77d7a46711f04d5d.xcab7864539e5adf4 (System.IO.BinaryReader xe134235b3526fa75, Int32 xc1690d3515e1ed6c) [0x00000] in <filename unknown>:0 at x0ba9768691592c95.x77d7a46711f04d5d..ctor (Guid fmtId, System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0 at x0ba9768691592c95.x5704d66afcf29611..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0 at xa604c4d210ae0581.xe6d08044467dd57c.x322764889cbf1e8c (xb92b7270f78a4e8d.xe7be411416cfcd54 x630baaeb4d769680) [0x00000] in <filename unknown>:0 at xa604c4d210ae0581.xe6d08044467dd57c.x06b0e25aa6ad68a9 (xb92b7270f78a4e8d.xe7be411416cfcd54 x630baaeb4d769680, Aspose.Words.Properties.BuiltInDocumentProperties xf401ea1a049007f6, Aspose.Words.Properties.CustomDocumentProperties xe92ee63fc139f521) [0x00000] in <filename unknown>:0 at x16f9a31f749b8bb1.x0f8a9a895bdf560e.x06b0e25aa6ad68a9 () [0x00000] in <filename unknown>:0 at Aspose.Words.Document.x5d4db34d48fb3129 (System.IO.Stream xcf18e5243f8d5fd3, Aspose.Words.LoadOptions x27aceb70372bde46) [0x00000] in <filename unknown>:0 at Aspose.Words.StyleCollection.get_xc6b4c6fa9a60b0fc () [0x00000] in <filename unknown>:0 at Aspose.Words.StyleCollection.xe931c242f6b9055f (System.String xc15bd84e01929885, Boolean x988fcf605f8efa7e) [0x00000] in <filename unknown>:0 at Aspose.Words.StyleCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0 at Aspose.Words.Lists.ListLabel.xa49e661f5cc91e49 (Int32 xba08ce632055a1d9) [0x00000] in <filename unknown>:0 at x28925c9b27b37a46.x684b09378db148f4.xfe91eeeafcb3026a (xf5ecf429e74b1c04 x50a18ad2656e7181, Int32 xba08ce632055a1d9) [0x00000] in <filename unknown>:0 at Aspose.Words.Font.xfe91eeeafcb3026a (Int32 xba08ce632055a1d9) [0x00000] in <filename unknown>:0 at Aspose.Words.Font.get_Underline () [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.xacc55eb1e4595209.x69b6a3483d603d62 (Aspose.Words.Paragraph x31e6518f5e08db6c, x4adf554d20d941a6.x17dcbf5fe3c0d2d2 x40c630e0786922f0) [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.xacc55eb1e4595209.x69b6a3483d603d62 (Aspose.Words.Paragraph x31e6518f5e08db6c) [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.x42f2a218ce59dafb.xb882a2219ab76498 (Aspose.Words.Node xda5bf54deb817e37) [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.x487cdc969fefe3d6.x46ed25080dd0b98f () [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.x487cdc969fefe3d6.xb61b92627231b7a8 () [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.x487cdc969fefe3d6.x47f176deff0d42e2 () [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.x487cdc969fefe3d6.x83f07df6a659e05b () [0x00000] in <filename unknown>:0 at x59d6a4fc5007b7a4.xcde671c53995c411.xd9db07500873ae98 (Aspose.Words.Document x3664041d21d73fdc, x59d6a4fc5007b7a4.xdeb77ea37ad74c56 xdfde339da46db651) [0x00000] in <filename unknown>:0 at Aspose.Words.Document.UpdatePageLayout () [0x00000] in <filename unknown>:0 at xfbd1009a0cbb9842.xe70a81b27884f7a0.xb333e1e6c01c2be2 () [0x00000] in <filename unknown>:0 at xfbd1009a0cbb9842.xbf9ddf72e1283af9.x18dfca7c5fd2402f () [0x00000] in <filename unknown>:0 at xfbd1009a0cbb9842.xfedf115fd9c03862.xdd6cf0348a23f220 (xcf417e2db4fe9ed3 xe00c282e1a49fcfb) [0x00000] in <filename unknown>:0 at xfbd1009a0cbb9842.xfedf115fd9c03862.x384c03e4298b53bf () [0x00000] in <filename unknown>:0 at Aspose.Words.Range.UpdateFields () [0x00000] in <filename unknown>:0 at Aspose.Words.Document.UpdateFields () [0x00000] in <filename unknown>:0 
Test #2 : .xls creation with Aspose.Cells
Ok
Test #3 : .ppt creation with Aspose.Slides
Invalid IL code in Aspose.Slides.License:SetLicense (string): IL_0023: stloc.1

Hi
Thank you for additional information. Could you please provide me a code and test documents you are using for testing Aspose.Words? I will check them on my side and provide you more information.
Best regards,

additional information :
Same tests (same dlls, licence file, aspnet application, template and data) on IIS serveur : tests are ok

It is hard to provide a short code.
- load .doc templat
- MailMerge.Execute(my data)
- some documentvisitor and other process
- => Save as IN.doc => I attached this file
- call document.UpdateFields()
=> error
So I suppose you could reproduce my error with loading IN.doc and calling document.UpdateFields() direcly ?
(For test #3, I have to post on Aspose.Slides forum too, or someone from the Slides Aspose team will come here ?)

Hi
Thank you for additioanl information. Unfortunately, I still cannot reproduce the problem on my side. I used the following code for testing:

using System;
using System.Web;
using System.Web.UI;
using Aspose.Words;
using Aspose.Words.Saving;
using Aspose.Words.Fonts;
namespace testaspnet
{
    public partial class Default : System.Web.UI.Page
    {
        public virtual void button1Clicked(object sender, EventArgs args)
        {
            License lic = new License();
            lic.SetLicense(Server.MapPath("Aspose.Words.lic"));
            // Aspose.Words will look for fonts in the specified directory and all subdirectories.
            FontSettings.SetFontsFolder("/usr/share/fonts", true);
            Document doc = new Document(Server.MapPath("in.doc"));
            doc.UpdateFields();
            doc.Save(Response, "out.pdf", ContentDisposition.Attachment, new PdfSaveOptions());
        }
    }
}

Regarding Aspose.Slides, it would be better if you ask your question in Aspose.Slides forum.
Best regards,

Hi Alexey
“CodePage 1251 not supported” issue has been resolved by installing “mono-locale-extras” package, wich contains I18.Other dll.
There are still one issue on ppt creation (I’ll post on Aspose.Slides forum) and on doc to pdf conversion (I’ll make other tests, and try to give you enough information to reproduce on your side).
Thanks for your help

“Cannot find black listed licenses resource” issue occurs on Aspose.pdf license loading. I’ll post on Aspose.pdf forum for this.

Hi
It is perfect that you managed to resolve the problem with Aspose.Words. Please feel free to ask in case of any issues, we will be glad to help you.
Hope my colleagues from Aspose.Slides and Aspose.Pdf team will be able to help you to resolve the problems.
Best regards,

Alexey,
I did some tests on doc to pdf conversion using Aspose.Words on mono server, it seems that it works fine now.
Thanks

Hi there,
It’s great that it’s working as expected now. If you have any further queries, please feel free to ask.
Thanks,