One bitmap for viewing, another for printing (PDF)

When we render a chart to PDF (using iText), we want to render at 96dpi when displayed on the screen. If we use even 300dpi then when viewing on the screen very thin lines disappear. This makes the chart look all wrong. But when printing we want 600dpi, a 96dpi image looks really bad when printed.

Fortunately PDF has this functionality. You can make displaying a bitmap conditional on printing, zoom level, and more. The iText book demonstrates how to display print only and for zoom levels. But it does not demonstrate the display if not printing mode. So here’s how to do it where you display one image if printing and another if viewing. (Note: I did not put them at the same location so I could verify that one was not rendering over the other.) (source code)

static void Main(string[] args)

    Document document = new Document(new Rectangle(0, 0, 8.5f * 72.0f, 11 * 72));

    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Path.GetFullPath(@”..\..\test_dotnet.pdf”), FileMode.OpenOrCreate, FileAccess.ReadWrite));


    document.Add(new Paragraph(“Visibility test”));


    // not displayed on printer

    PdfLayer layer = new PdfLayer(“screen”, writer);

    layer.OnPanel = false;

    layer.SetPrint(“Print”, false);

    layer.View = true;

    PdfContentByte cb = writer.DirectContent;


    Image img = Image.GetInstance(Path.GetFullPath(@”..\..\building_01.png”));

    img.SetAbsolutePosition(72, 72 * 7);




    // not displayed on screen

    layer = new PdfLayer(“print”, writer);

    layer.OnPanel = false;

    layer.SetPrint(“Print”, true);

    layer.View = false;

    cb = writer.DirectContent;


    img = Image.GetInstance(Path.GetFullPath(@”..\..\building_02.png”));

    img.SetAbsolutePosition(72, 72 * 3);





    Console.Out.WriteLine(“all done”);


Posted in Uncategorized | Comments Off on One bitmap for viewing, another for printing (PDF)

The 9 Best Computer Science Schools in the World

In our recent Code War competition, something struck me about the schools participating. The contest is a very good measure of the depth of community within a school. And not just community, but also the depth of love of programming for the pure joy of programming to be found in these schools. If you’re looking to attend a school where the students love programming, and where the students have a strong sense of community, these 9 schools should absolutely be on your list.

I’m not saying this should be your only measure. And for many people it may not be an important one. If you’re going into computer science for the money, then having fellow students there for the love of programming is irrelevant. If you want to be left alone a strong community among the students could be a negative for you.

Also not appearing on this list does not mean a school does not have programmers who love programming and/or a strong sense of community. CMU participated last year but this year they had a major hackathon on the same weekend and so they might well have appeared on the above list.

On the flip side we’re reached out to MIT every year and the response has been zero interest by the students in anything like this. So a school can be a very good academic institution and yet have a student body with no strong sense of community and no deep love of coding for the pure joy of it.

What’s really interesting about the above list is 5 of the 9 are on many of the top 10 C.S. schools lists (Mudd, Maryland, Georgia Tech, Purdue, & Penn). My guess is that students visiting Colleges do see that these schools have students that have created a community and love programming. And if that is really important to the prospective student, they’ll also attend one of these schools. And if these traits are not important, then they’ll also consider the other top schools.

There are also 4 hidden gems in the above list, Victoria, Mines, Alberta, and CSU. They’re not top 10 schools, but not every student is going to get in a top 10 school (nor is a top 10 school the best place for many students). But what these other 4 clearly offer is a student body with a strong sense of community and students that love programming for the pure joy of programming.

If you love programming. And if you want a school that is a community, not just a set of classes you attend, some of the above schools should absolutely be on your list.

If I was applying today this would be at the top of my list. Many schools can teach you the fundamentals of Computer Science. A school like the above ones makes the 4 years a lot more fun.

One of the best interview answers I’ve ever heard

This past weekend I was interviewing three students at Harvey Mudd (awesome school) for summer internship positions at Windward. One of the questions I gave was the following:

In the Code War (held the previous weekend), let’s say you realized the provided pathfinding algorithm was providing poor routes. Winning requires a better pathfinder. However there is only 2½ hours left in the contest so there isn’t time to find and port a good A* implementation.

One of the students gave me one of the best replies to any question I have ever heard in an interview:

I would go ask the other teams if they had a good implementation for the contest. And if so, would they share their code.

Yes, Yes, YES! This is such a good answer in so many ways. First, it is looking to make use of available resources rather than re-invent the wheel. Second it shows a clear focus on solving the problem quickly with any and all means available. Third it shows the candidate is considering solutions well outside the assumed parameters of the question.

Of course it was an interview so I then told him that all the other teams said no. (And he then went on to find the solution.)

Very very impressive.

Posted in Uncategorized | Comments Off on One of the best interview answers I’ve ever heard

I am not responsible for every software glitch, hardware failure, and technical failure

My mom calls saying she can’t connect to the Internet and then waits. Because of course I know exactly what is wrong and can fix it instantly over the phone.

My wife tells me she can’t print and then asks me why printing under Windows fails half the time. And I need to fix this instantly.

My daughter’s iPhone is too slow and it’s now my fault that the latest bloated version of iOS has degraded her experience.

And in all these cases, and all too many more, apparently saying that I had nothing to do with that software is not an excuse. Somehow because I write code for a living I am responsible for the quality of every program written and have the knowledge to instantly fix any issue anyone hits.

When the truth is I have a hard enough time just getting the code I write to run well and without problems.

Posted in Uncategorized | Comments Off on I am not responsible for every software glitch, hardware failure, and technical failure