What happened to the PDF Module?

Back in April 2007 i told about the PDF Module for Sitecore, but since then things got quiet around the topic. What happened?
Well, the module is finished, including a manual and API descriptions. It’s just isn’t available through the official Sitecore channels. Here in Pentia A/S we are using it, and it’s running fine.
 
You can use the module for 2 different things. The simple mode is to generate PDF documents from HTML content. This is done by creating a PDF layout (a Sitecore item) and calling the layout with the ID of the page to render as PDF. The layout then uses the “PDF” device of the item to render as input for the text to generate.
A PDF layout contains the paper size, margins and layers for one PDF page. Layers are used for creating headers, footers and watermarks as they are rendered on each page. A layer can be a text, page numbers, a line, an image, an URL and so on.
From HTML to PDF
From HTML to PDF
The advanced mode is used for creating customized PDF books, where the web site user choose the chapters to include in his own book. The book is then compiled from the choices made and a PDF complete with front page, table of contents, page numbers a.s.o is generated.
In the advanced mode, chapters are pre-rendered on publish time together with a table of contents for that chapter. Generating a book is therefore very fast. We create 800 page books in less than 10 seconds. Downloading the book is the slow part here. 
PDF Book Generator

PDF Book Generator

I hope that the module will be available through Sitecore some day. Untill then, you’ll have to contact Pentia A/S if you are interested in hearing more.

What the wap? Linking to phone numbers in WAP applications

I was doing a WAP application (not entirely the truth – I was doing a WEB site with a layout that matches the small screen on a mobile phone) for a customer.
The application is a simple integration to their contacts database. My customer then asks: “Isn’t it possible to make the phone numbers linkable so when I click them, my phone automatically rings up the selected number?”
The answer is: Yes you can. And it’s pretty simple. And it works both on my old Nokia 6021 and on the new IPhone. In fact, any phone conforming to the WTAI (Wireless Applicaton Protocol Interface) can use this.
This is a link to a phone number:

<a href="wtai://wp/mc;+4533743330">Call Pentia A/S</a>

The prefix wtai://wp/mc; WAP-enables the link so you can click on it.
There are other prefixes available:

  • wtai://wp/mc; – Dial number
  • wtai://wp/ap; – Put number in your contacts list
  • wtai://wp/sd; – Send DTMF sequence trough voice call. For example wtai://wp/sd;555*1234

Add and Remove cookies

Creating cookies is no problem:

// Create the cookie
HttpCookie cookie = new HttpCookie("MyCookie", "MyValue");
// Let the cookie expire in 1 year
cookie.Expires = DateTime.Now.AddYears(1);
// Add the cookie to the response header
HttpContext.Current.Response.Cookies.Add(cookie);

But have you ever tried to remove a cookie, but nothing happens? It seemes that the “Remove” have no effect:

//Why does this not remove my cookie?
HttpContext.Current.Request.Cookies.Remove("MyCookie");

Setting a cookie is a dialog between the client and server. Adding a cookie is done by adding it to the response header. It is the client (IE, FIrefox, Opera) who will write the cookie, usually to disk.

Next time the client requests a page from the domain, any un-expired cookies is written to the request headers, where you can read the information from within client side code.

Removing the cookie with Request.Cookies.Remove() only removes the cookie from the request collection, not from disk.

Instead you can let the cookie expire. The client will then leave the cookie when requesting a page from your domain:

// Find the cookie
HttpCookie cookie = HttpContext.Current.Request.Cookies["MyCookie"];
// If found, let the cookie expire
if (cookie != null)
  cookie.Expires = DateTime.Now.AddYears(-1);

Large files upload

By default, the maximum size of a file that can be uploaded in Sitecore is 16 mb. In standard .net it is 4 mb. How did Sitecore achieve this difference?

Easy. The maximum size (or the maximum request length) is defined in the web.config. Look at the bottom of your web.config:

<system.web>
  <httpRuntime maxRequestLength="16384" executionTimeout="600" />
</system.web>

Altering the maxRequestLength will alter the upload size. The number defines how many kliobytes can be sent.

Searching in multiple columns in Sitecore Ankiro Search

Sitecore Ankiro Search is a nightmare and a blessing. Once you have it going you have one of the most advanced search engines available.

One of the cool features is that seperate fields of one Sitecore template can be indexed seperately. This gives you an execllent method to index metadata along with your contents.

But what if you wish to search for one sentence in one field and another sentence in another field? Well, you’ll need some c# code for that. Use the SearchBuilder. With the SearchBuilder you construct your search query before you execute the search. In this example I construct my SearchBuilder and searches for “a” in column “Title” and “b” in column “Text”:

using Sitecore.Ankiro.Search;
using Sitecore.Ankiro.Search.SearchConstruction;

SearchBuilder builder = SearchFactory.Instance.CreateSearchBuilder("MyIndex");
SearchOperatorNode andOperator = builder.CreateOperatorNode(ESearchOperation.AndOperation);
SearchNode searchNode1 = builder.CreateIndexColumnsSearchNode("a", EPropertyInterpretation.Normal, 1.0, 0.8, "MyIndex", "Title");
SearchNode searchNode2 = builder.CreateIndexColumnsSearchNode("b",
EPropertyInterpretation.Normal, 1.0, 0.8, "MyIndex", "Text");
andOperator.AppendChild(searchNode1);
andOperator.AppendChild(searchNode2);
builder.RootNode = andOperator;
System.Xml.XmlDocument doc = SearchFactory.Instance.ExecuteSearch("", builder, 10, 0);