Entries tagged "PDF"

Fix for Download Issue with PDFs and Internet Explorer

Over the past few months, comments have been coming in about PDFs not opening properly. The process seems to get stuck before the download completes. However, the issue doesn't always manifest. There seems to be a correlation between it and larger PDF files. After a bit of research and eliminating some possible contributing factors, I came across a solution which worked for me. [Continue reading]

Converting PowerPoint Files to PDF: Which Option to Choose

When posting PowerPoint files online, I usually upload a PDF version of the presentation since they tend to be smaller in file size. There have been more than a few times where the PowerPoint file is over 100 megabytes (mb) and is reduced to around 15mb PDF. With that said, there are at least 3 ways to create PDFs in PowerPoint and each option may produce files of different size. [Continue reading]

Reducing the Number of Clicks When Saving Files Deep within a Website’s Structure by Using Shortcuts

When receiving lots of files via e-mail to convert to PDF and post on the website, it can be a time consuming project. Especially when the files are saved to a folder deep within a website and the software used to create the PDF doesn't remember the last folder saved to. Instead of clicking folder after folder for each file, let's look at folder shortcuts. [Continue reading]

Problems with Google Analytics Code for Tracking PDFs

After struggling for nearly a week to install the asynchronous code for Google Analytics, I thought it would be good to share what I've learned. Hopefully this will save you a few sleepless nights.

When I switched to the asynchronous tracking code, everything appeared to be working correctly. But for some reason PDF downloads and visits to external websites weren't showing up in the analytics. According to the Google help documentation (How do I track files (such as PDF, AVI, or WMV) that are downloaded from my site?), I just needed to add an "onclick" event to the downloadable file/external website link:

<a href="/newsletter/2010spr.pdf" onclick="javascript:pageTracker._trackPageview('/newsletter/2010spr.pdf');">

While searching for a solution I stumbled across a Google Chrome plug-in (Google Analytics Tracking Code Debugger) used to validate your tracking code. Using the plug-in, I discovered that the Google help documentation failed to mention one crucial piece of information; you need to define "pageTracker". After a little searching I found another page (Google Analytics Installation Guide) that talks about defining "pageTracker".

With "pageTracker" now defined, the Google Chrome plug-in said that everything was working. But for some reason the code still wasn't working. I used several computers to open PDFs and visit external links. Then I checked Google Analytics an hour or so later to see if they show up. For some reason one of the clicks went through, but that was it. After a few more days of failures and posting on the Google Analytics discussion board I finally realized that the tracking code provided by Google doesn't work.

Instead you want to call the tracking code directly:

<a href="/newsletter/2010spr.pdf" onclick="javascript:_gaq.push(['_trackPageview', '/newsletter/2010spr.pdf']);">

I have no idea why the Google Chrome plug-in said everything was fine, maybe there is a bug on Google's side that prevents the analytics service from accepting results.

Related Links

Future Proofing Your Google Analytics Code for Tracking PDFs

A few years back I started using Google Analytics to get a better idea of what people are viewing on our websites. To be prepared for future revisions of the tracking code, I thought all I needed to do was store the code in a file called "GoogleAnalytics.html" and import it into the pages we wanted to track. Then as Google releases new versions of the tracking code, I would only need to update the GoogleAnalytic.html file for each website.

Unfortunately, you can't add the tracking code to every file on the website. To track how many visitors open a PDF for example, you have to add extra code to the page that links to the PDF. Let's say you wanted to link to the Spring 2010 newsletter. The tracking code would likely be added to the anchor tag using the "onclick" attribute as follows:

<a href="/newsletter/2010spr.pdf" onclick="javascript:urchinTracker('/newsletter/2010spr.pdf');">Spring 2010 Newsletter</a>

The problem was that I didn't think about future proofing this part of the tracking code. So when the time arrived to update the analytics code, I needed to replace more than 230 onclick references throughout one website.

So instead of hard-coding the onclick attribute like before, I wanted to create a PHP function that writes the tracking code for me. In addition to being able to create tracking code for PDFs, Word documents, PowerPoint files, etc., the function should be able to handle links to other websites.

Building the Function

First I defined a PHP function called "addTrackingCode". The function accepts one argument ($link) which is used to send the link to track.

//FUNCTION USED TO ADD TRACKING CODE TO DOWNLOADABLE FILES (SUCH AS PDFs) AND TO EXTERNAL WEBSITE LINKS
function addTrackingCode($link) {
}

Inside the function, I want optimize the link for Google Analytics.

//FUNCTION USED TO ADD TRACKING CODE TO DOWNLOADABLE FILES (SUCH AS PDFs) AND TO EXTERNAL WEBSITE LINKS
function addTrackingCode($link) {
     //IF THE LINK LEADS TO MY WEBSITE (http://www.mywebsite.com/newsletter/2010spr.pdf), REMOVE THE "http://" AND THE DOMAIN NAME
     if(substr($link, 0, 24)=='http://www.mywebsite.com') {
          $link = substr($link, 24);
          
     //ELSE…IF THE LINK STARTS WITH "http", IT'S AN EXTERNAL LINK
     } elseif(substr($link, 0, 4)=='http') {
          //IF THE LINK STARTS WITH "https://", REMOVE IT
          if(substr($link, 0, 8)=='https://')  {
               $link = substr($link, 8);
          
          //ELSE…IF THE LINK STARTS WITH "http://", REMOVE IT
          } elseif(substr($link, 0, 7)=='http://') {
               $link = substr($link, 7);
          }
          
          //ADD "/external/" TO THE BEGINNING OF THE LINK SO THAT ALL THE EXTERNAL LINKS ARE GROUPED INTO THE SAME FOLDER IN GOOGLE ANALYTICS
          $link = '/external/' . $link;
     
     //ELSE…IF THE LINK DOESN'T LEAD WITH A SLASH, ADD ONE (note that if the link doesn't begin with a slash, Google Analytics groups it under a folder labeled "/../")
     } elseif(substr($link, 0, 1) != '/') {
          $link = '/' . $link;
     }
}

Now we need to return the "onclick" attribute containing the tracking code for the formatted link.

     …
     } elseif(substr($link, 0, 1) != '/') {
          $link = '/' . $link;
     }
    
     //RETURN THE FORMATTED LINK
     return " onclick=\"javascript:urchinTracker('$link');\"";
}

Where Does the Function Go?

Since the standard Google Analytics code is already being imported, I added the function to the "GoogleAnalytics.html" page:

<?php
//STANDARD GOOGLE ANALYTICS TRACKING CODE (note that the "UA-XXXXXXX-X" needs to be replaced with your tracking code ID)
?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXXX-X";
urchinTracker();
</script>
<?php
//FUNCTION USED TO ADD TRACKING CODE TO DOWNLOADABLE FILES (SUCH AS PDFs) AND TO EXTERNAL WEBSITE LINKS
function addTrackingCode($link) {
     //IF THE LINK LEADS TO MY WEBSITE (http://www.mywebsite.com/newsletter/2010spr.pdf), REMOVE THE "http://" AND THE DOMAIN NAME
     if(substr($link, 0, 24)=='http://www.mywebsite.com') {
          $link = substr($link, 24);
          
     //ELSE…IF THE LINK STARTS WITH "http", IT'S AN EXTERNAL LINK
     } elseif(substr($link, 0, 4)=='http') {
          //IF THE LINK STARTS WITH "https://", REMOVE IT
          if(substr($link, 0, 8)=='https://')  {
               $link = substr($link, 8);
          
          //ELSE…IF THE LINK STARTS WITH "http://", REMOVE IT
          } elseif(substr($link, 0, 7)=='http://') {
               $link = substr($link, 7);
          }
          
          //ADD "/external/" TO THE BEGINNING OF THE LINK SO THAT ALL THE EXTERNAL LINKS ARE GROUPED INTO THE SAME FOLDER IN GOOGLE ANALYTICS
          $link = '/external/' . $link;
     
     //ELSE…IF THE LINK DOESN'T LEAD WITH A SLASH, ADD ONE (note that if the link doesn't begin with a slash, Google Analytics groups it under a folder labeled "/../")
     } elseif(substr($link, 0, 1) != '/') {
          $link = '/' . $link;
     }
    
     //RETURN THE FORMATTED LINK
     return " onclick=\"javascript:urchinTracker('$link');\"";
}
?>

Using the Function

Now that the function is imported along with the standard Google Analytics code, it can be used when linking to files like PDFs. So instead of hard-coding the tracking code like earlier:

<a href="/newsletter/2010spr.pdf" onclick="javascript:urchinTracker('/newsletter/2010spr.pdf');">Spring 2010 Newsletter</a>

We can now utilize the PHP function:

<a href="/newsletter/2010spr.pdf"<?php echo addTrackingCode('/newsletter/2010spr.pdf'); ?>">Spring 2010 Newsletter</a>

Updating the Analytics Code

Now that all the Google-specific tracking code is located in the "GoogleAnalytics.html" page, we can easily modify the code as Google releases new versions. We just need to replace the standard tracking code and the return statement at the end. The code below shows the newest tracking code provided by Google:

<?php
//STANDARD GOOGLE ANALYTICS TRACKING CODE (note that the "UA-XXXXXXX-X" needs to be replaced with your tracking code ID)
?>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
<?php
//FUNCTION USED TO ADD TRACKING CODE TO DOWNLOADABLE FILES (SUCH AS PDFs) AND TO EXTERNAL WEBSITE LINKS
function addTrackingCode($link) {

     //RETURN THE FORMATTED LINK
return " onclick=\"javascript:_gaq.push(['_trackPageview', '$link']);\"";
}
?>

Feedback

Do you use Google Analytics to track visits to external websites from your website? If so, do you do anything special to group those visits together? Also, don't hesitate to ask if you have any questions about the analytics function or if you have suggestions.

Related Resources

  • PHP.net – the online PHP manual which is helpful for finding out more information on the PHP substr() function for example
  • Google Analytics Help – the help section for Google Analytics which may be able to answer your questions about the service

Creating Accessible PDFs with Word 2010

The other day I needed to post a Word document online as a PDF. After opening Microsoft Word to make the conversion I discovered that the Acrobat tab (used to create tagged PDF documents) was missing. The problem is that I’m now using Word 2010 and the process for making a tagged PDF has changed.

What is a Tagged PDF?

When you’re tagging a PDF, you’re identifying what each thing is in the document. For example, you define what elements are headers, paragraphs, graphics, etc. In the end, you should have a PDF document that is more accessible to those viewing the file with an assistive technology device such as a screen reader. As a bonus, those tagged PDF documents are also more accessible to search engines (Google, Yahoo, etc.).

Creating a Tagged PDF in Word 2010

To convert a Word document into a tagged PDF, follow these steps:

  • Open the document in Word 2010
  • Click File
  • Click Save As
  • In the Save As dialog box, change the "Save as type" to PDF (See Figure 1)
  • Click Options… (See Figure 2)
  • Make sure the “Document structure tags for accessibility” option is checked (See Figure 3)
  • Click OK and finish saving the document
Word 2010 - Save As Dialog Box
Figure 1. Save As Type Selection
Word 2010 - Save As Options Button
Figure 2. Save As Options Button
Word 2010 - PDF Options Box
Figure 3. PDF Options Dialog Box

Once Microsoft Word has finished processing the document and added the tags, you should open the PDF file in Adobe Acrobat to verify that everything was tagged properly. Depending on how well the Word document was formatted and a number of other factors (such as document length), the verification process may take some time. The verification process is a little beyond the scope of this post, but I may post something on the topic in the future.

Related Resources

  • PDF Accessibility – a WebAIM article providing an overview of the tools available in Adobe Acrobat to increase the accessibility of a PDF