Archive for the ‘Mono’ Category
I had a problem with my libapache2-mod-mono install freezing during install when trying to run ASP.NET applications on Ubuntu.
The workaround for this is to open another session and restart/reload apache:
root@xyzio:/home/xyzio# service apache2 reload root@xyzio:/home/xyzio# service apache2 restart
This is what I would see and the session would freeze at the [OK]:
apt-get install libapache2-mod-mono Setting up libapache2-mod-mono (2.11+git20130708.6b73e85-2) ... Using mono-apache-server4... apache2_invoke: Enable module mod_mono * Restarting web server apache2 [ OK ] apache2_invoke: Enable module mod_mono_auto * Restarting web server apache2 [Sun Dec 08 23:03:01.698809 2013] [so:warn] [pid 4455] AH01574: module mono_module is already loaded, skipping [ OK ]
I was looking for a .NET pdf generator so that I could add online bingocard generation to my side project, BingoWords. The code and website are built using .NET and I run the site under Mono on a VPS at Linode. So, it was important that the PDF generator run under Mono without issues. Being cheap and full featured were two other desired features. After some research, I found that there were two major players that satisfied this criteria, PDFSharp and iTextSharp. Both are open source, free, and are fully featured.
Although some posts on the web indicated that PDFSharp would run under Mono, it was a no-go from the beginning. It failed the mono compatibility tool – Mono Migration Analyzer or M0MA almost right away. I still decided to try out PDFSharp with Mono after reading a few posts stating that it may work if my code avoided the non-Mono compatible portions of the code but that was a total failure.
So, I had no choice but to use iTextSharp. iTextSharp passed under MoMA and it worked great on my Linode VPS under Mono. With iTextSharp, I can generate PDFs that comply with the PDF standard and are viewable on every major platform. So, if you are planning to generate PDFs under Mono, I would highly recommend iTextSharp. Or to get a better sense of the features, try out my free Online Bingo Card Generator!
I noticed that weren’t many code samples available while doing my research and coding the Bingo Card Generator. So, here are some samples from my code for those that are just getting started:
Creating a new PDF document:
MemoryStream ms = new MemoryStream();
Document document = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(document, ms);
Creating a BaseFont. A BaseFont contains the parameters of the font that is written to the PDF document:
BaseFont bf = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Writing center-aligned text to 400pts from the left and 400pts from the top:
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, “Title Text”, (int)(Math.Abs(400, 400, 0);
Getting the width of a string in points:
titleWidth = (int)cb.GetEffectiveStringWidth(“Hello World!”, false);
Setting the font size of a BaseFont:
Draw a line from the top left to the bottom left of the document:
Editing the document’s properties:
document.AddTitle(“Designed by BingoWords.com”);
document.AddAuthor(“Author goes here!”);
document.AddSubject(“Subject Goes Here!”);
document.AddKeywords(“Keyword1, keyword2, …”);
Closing your document:
Put this after the “document.Close()” to return your document with the name “file.pdf” when a user clicks on a link:
Response.ContentType = “application/pdf”;
Response.Buffer = true;
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
I hope this comes in handy. Feel free to contact me if you have any questions or comments.
- Create arbitrary sized Wordsearch puzzles
- Create Bingo Cards up to 5×5 squares in size
- Save your wordlists for future use and to share with co-workers
- Print an unlimited number of Bingo Cards and Word Search Puzzles
- Print up to 8 Bingo Cards per page
- Quick access to common word lists using the built in Word Wizard
For more details, read on.
Why is it Free?
Originally, I was planning to sell Bingo Words Puzzle Designer but then I realized that I’d rather spend my free time working on new code instead of on marketing and all the hassle that comes with running a business. Besides, putting together something like this only took me a couple weeks of part-time work and it annoys me that some people are charging over $30/copy for something that is this simple to make.
My hope is that it will be useful to someone and that they will pay it forward some day.
BingoWords Puzzle Designer is a project I worked on in order to teach myself C#/ASP.NET. The application is made with C# and Winforms. The website is build using ASP.NET and is hosted using Mono on a virtual server at Linode. I was able to learn every aspect of creating an app with this project – from drawing on the screen to printing and to saving files to generating serial numbers.
Feel free to contact me with questions or suggestions for improvement!
I’m looking into moving one of my ASP.NET projects to Mono and had trouble getting Mono working on Ubuntu 9.10. Turns out the steps to set it up were simple, but they took some digging around so here they are:
apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
Enable the Universe repositories. To do this, uncomment the universe repositories in /etc/apt/sources.list so it looks like this:
Run ‘apt-get update’ to get the latest sources.
Finally, follow the steps listed in the Ubuntu ModMono guide:
Install the mod_mono packages: libapache2-mod-mono mono-apache-server2-
apt-get install libapache2-mod-mono mono-apache-server2
Enable the Apache module:
Place a .aspx page where Apache can see it, for example at ‘/var/www/’