Chrome as default PDF reader

Let me start by venting a bit and expressing my deep displeasure with the latest Foxit reader 6 release. I originally installed Foxit as a lightweight replacement for Adobe reader, but the latest release lacks the main advantage earlier versions had – quick instantaneous PDF access. A colleague of mine recommended using Chrome’s built in PDF reader as a default reader instead since I’m already using Chrome either way. As you might have experienced when opening PDFs from the web, it’s lightning fast in Chrome. This post isn’t just about how to set up Google Chrome as your default PDF reader, which is rather straightforward; I’ll gladly refer you to How-To Geek for help with that. However, once you have done so you might notice some undesirable behavior which differs from using a dedicated PDF reader.

PDF file with gray borders on the sides.

  • When you already have a browser window open, the PDF opens as a new tab in that browser. This might actually be considered a feature by some, but as I blogged before, I rather move away from application-specific tab management entirely.
  • The chrome ‘PDF window’ doesn’t retain its own size when opening PDFs, but shares it with regular browser usage. PDFs are generally not that wide, and maximizing the window results in gray borders on the sides.

After some hacking around I found a solution around this. By placing a custom executable (download here) in the same folder as chrome.exe and using this executable as the default application to open PDF files, both before mentioned issues are solved. Double clicking a PDF file results in a new chrome window, having the same size as the last PDF file you opened.

The chrome executable by default is located in: C:\Users\<user>\AppData\Local\Google\Chrome\Application\

How it works

The executable simply calls the original chrome.exe, but additionally adds two command line arguments.

  • –user-data-dir: Specifies the user data directory, which is where the browser will look for all of its state.
  • –new-window: Launches URL in new browser window.

The user data directory besides other settings also seems to contain the last set window size. Passing any non existing path here results in a new directory being created for it under “C:\Users\<user>\AppData\Local\Google\Chrome\Application\<version_number>”, containing the settings which will be reused the next time the executable is called. In case you want to adjust the behavior (e.g. disable opening the PDFs in a new window) what follows is the C# source code for the executable. Originally I tried creating a shortcut and setting that as the default application to open PDFs, but the executable to which the shortcut points ends up being used instead, hence losing the command line arguments.

static void Main( string[] args )
{
	string chromeDir =
		new FileInfo( Assembly.GetEntryAssembly().Location ).DirectoryName;
	string chrome = Path.Combine( chromeDir, "chrome.exe" );
	string arguments =
		"\"" + args[ 0 ] + "\"" + " --user-data-dir=pdf_dir --new-window";

	var proc = new Process
	{
		StartInfo =
		{
			FileName = chrome,
			Arguments = arguments,
			WorkingDirectory = chromeDir
		}
	};

	proc.Start();
}
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: