Check me out on Twitter.


Technology


29
Jan 12

Create a Simple Document Viewer with ExtJS

A Report or Document Viewer

As I always do… let’s cut to the chase… looking for the downloads or source code?
Simple Document Viewer Example Application (48)

Before we start, I’ll also point you to the working demo / example.

A west region with a treeview control and a center panel with details that change as you select items from the treeview. This type of interface is ubiquitous and yet creating something like this to simply view documents may seem very difficult for folks that haven’t worked with javascript. The document viewer application was created to provide a mechanism for viewing collections of sample reports.  A design goal for this application was for it to be completely standalone – not requiring any additional software or web server to view the documents.

At the heart of this system is a perl script – parse_csv.pl. This is a perl script that was written to create a javascript object notation assignment (JSON) used to populate a treeview control for the purpose of displaying example pdf reports with previews. In order to use this package to create your own custom file or report viewer, you must create a comma separated value (CSV) file with the following values.

REPORTFILE,PREVIEW,GROUP,TITLE,DESCRIPTION

Column 1 – Report file specifies the name of the PDF report file that will be downloadable from within the viewer.

Column 2 – Preview file specifies the name of the preview or thumbnail image that will be presented in the details pane of the viewer application.

Column 3 – Group specifies the treeview group where this report will be grouped.  You should sort your csv file so that groups are stored together.

Column 4 – Title specifies the title of the report and will be displayed in the details pane of when the user clicks on the report in the treeview.

Column 5 – Description specifies the details of what the report will show.

Example

REPORTFILE,PREVIEW,GROUP,TITLE,DESCRIPTION
reportfile_number_one.pdf,preview_of_report_file_one.png,Group One, Example of a Report File One,This report shows some serious stuff.
reportfile_number_two.pdf,preview_of_report_file_two.png,Group One, Example of a Report File Two,This report shows some more serious stuff.
reportfile_number_three.pdf,preview_of_report_file_three.png,Group Two, Example of a Report File Three,This report shows some more serious stuff.
reportfile_number_four.pdf,preview_of_report_file_four.png,Group Two, Example of a Report File Four,This report shows some more serious stuff.
reportfile_number_five.pdf,preview_of_report_file_five.png,Group Two, Example of a Report File Five,This report shows some more serious stuff.
reportfile_number_six.pdf,preview_of_report_file_six.png,Group Three, Example of a Report File Six,This report shows some more serious stuff.
reportfile_number_seven.pdf,preview_of_report_file_seven.png,Group Three, Example of a Report File Seven,This report shows some more serious stuff.

You may include the column headers in your file – however, ensure that you use the --skipheader flag when executing the parse_csv.pl script.

Requirements
Perl.  The parse_csv.pl script is written in perl so you will need an environment were you can execute perl scripts.  A subrequirement is that I’m using some libraries that you may not have installed in your perl environment.

Checkout http://search.cpan.org if you get some errors about missing libraries.

Here’s an overview of the process to create your own custom document viewer.

  1. Download the Simple Document Viewer Example Application (48) package.  This will contain everything you need to

create and customize your own self contained document viewer.  Self contained

means that you don’t even need to host these documents and the viewer on a web

server… you can simply open the index.html file from a browser.

  1. Review the directory tree for the example package.

.

|– css     Style Sheets

|– extjs    Javascript Library for the treeview and panel components

|– images    Various supporting image files (like icons, etc.)

|– js    Javascript source files

|– reports    Report directory – this is where you’ll place the reports, pdfs and preview thumbnail files that will be displayed in the viewer.

`– scripts    Scripts used to create and customize your viewer

  1. Since you’ll be creating your own document or report viewer, you’ll probably want to delete the contents of the reports directory.
  1. Create the report files that you’ll be displaying in the document viewer.  Report files can be PDF, PowerPoint (ppt) or Word Document (doc) files.  Typically, the report file examples are multi-page pdf files.  Once you have the report files, copy them into the reports directory in the base of the example package.
  1. Create a screenshot, or preview image that will be displayed in the preview section of the details panel when viewing the report.  zScreen is a great, free utility that lets you capture portions of your screen and save them to files.  I prefer ‘png’ format because of smaller size.  You’ll need to create one preview image for each report you plan to display in the document viewer.  Copy or place these preview image files into the reports directory along side the actual pdf or ppt report files.
  1. Now you’ll need to create a comma-separated file that contains the names of your report files, the groups they’ll be displayed in, the document titles and a description of each.  As previously mentioned the format for this file is REPORTFILE, PREVIEW, GROUP, TITLE, and DESCRIPTION.  You can find an example in the scripts directory in a file called example.csv.
  2. Create the documents.js file.  This is the file which contains the Javascript Notation (JSON) which is used to populate the treeview control as seen in this image.  The package contains a script named parse_csv.pl and can be found in the scripts directory of the example package.  This script should be run from the main directory of the archive and must be provided several command line options in order to execute properly.  The following is an example execution of the script:

scripts/parse_csv.pl --csvfile scripts/example.csv --outputfile js/documents.js

This was executed from the base directory of the example archive file.  The –csvfile argument tells parse_csv.pl where to file the csv file that you created in step 5.  The –outputfile argument tells parse_csv.pl where to write the json.

It is important to note that the script assumes that you have not modified the directory layout and that you are storing your reports and previews or thumbnails in the “reports” directory.  You may run the script with “—help” to obtain additional information and options.

$ scripts/parse_csv.pl --help


Usage: scripts/parse_csv.pl --csvfile <filename> [--outputfile <filename.js>]
[--outputfile <outputfilename>] controls the output javascript filename - defaults to stdout
[--reportdir <reportdirectory>] specifies the directory where the pdf files may be stored
[--thumbdir <thumbnailedirectory>] specifies the directory where the thumbnail or preview image files may be stored
[--htmltitle <htmltitle>] specifies the title to be used in the report viewer html file
[[--overwrite] | [--nooverwrite]] - controls whether the output file will be overwritten

The following is an example of the resultant documents.js file that is created.


var json=[{"iconCls":"group","text":"Group One","children":[{"content":"reports/reportfile_number_one.pdf","description":"This report shows some serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_one.png","text":"Example of a Report File One","id":"1","leaf":"true"},{"content":"reports/reportfile_number_two.pdf","description":"This report shows some more serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_two.png","text":"Example of a Report File Two","id":"2","leaf":"true"}],"id":0.0960750988024337},{"iconCls":"group","text":"Group Three","children":[{"content":"reports/reportfile_number_six.pdf","description":"This report shows some more serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_six.png","text":"Example of a Report File Six","id":"6","leaf":"true"},{"content":"reports/reportfile_number_seven.pdf","description":"This report shows some more serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_seven.png","text":"Example of a Report File Seven","id":"7","leaf":"true"}],"id":0.119647523478733},{"iconCls":"group","text":"Group Two","children":[{"content":"reports/reportfile_number_three.pdf","description":"This report shows some more serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_three.png","text":"Example of a Report File Three","id":"3","leaf":"true"},{"content":"reports/reportfile_number_four.pdf","description":"This report shows some more serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_four.png","text":"Example of a Report File Four","id":"4","leaf":"true"},{"content":"reports/reportfile_number_five.pdf","description":"This report shows some more serious stuff.","size":"16.23 KB","published":"01-29-2012","iconCls":"pdf","preview":"reports/preview_of_report_file_five.png","text":"Example of a Report File Five","id":"5","leaf":"true"}],"id":0.423250772097287}]

var htmltitle='Example Report Viewer;'

Notice that the script determines the proper filetype and assigns the appropriate icon class – pdf for pdfs, ppt for ppts, etc.  Also note that the script determines the file size and date created.  These attributes are displayed in the details panel when viewing the documents.

Again… here’s the goods:
Simple Document Viewer Example Application (48)


1
Jul 11

Graceful Sidebar Version 1.0.13 Released!

Support for the popular qTranslate plugin has been implemented inside the Graceful Sidebar Plugin. qTranslate enables bloggers to internationalize their content directly in the wordpress administrative console. qTranslate has a support forum that appears to be active with some good suggestions for using the plugin on your site. Cheers to Ozden for the suggestion to support this helpful plugin!


1
Jul 11

WP Geocode WordPress Geolocation Plugin Version 1.0.0 Released!

I’ve always been fascinated by the possibility of understanding and leverage as much data as possible about a web site visitor or blog reader. The fact of the matter is that there is a lot of data available if you’re willing to dig a bit and use the tools available. You’re probably aware that information is transmitted to the web sites you visit as part of the conversation between your browser and the web server. However, what’s not readily known is the amount of data that can be derived from other sources such as your IP Address (which, incidentally is also a component of the browser-web server exchange.)

Maxmind is a geolocation server provider that publishes a database of information related to specific blocks of IP Addresses. This information is refreshed regularly and can be leveraged to provide information about the city, state, zip code and other information about your web site visitors. Maxmind offerstwo classes of product offerings – free and paid. The free and paid versions of their databases differ only in the granularity of detail.

The WPGeocode Geolocation Plugin that I just released relies on the free database and can be leveraged by wordpress bloggers to customize content based on geographic information for their visitors. The plugin can be used to incorporate geo-data into posts or pages and can also be used to display content conditionally based on these geographic details.

The plugin implements wordpress shortcodes that provide these data elements. For a complete listing of the shortcodes and additional details on the plugin, please visit WPGeocode.com. You can download the latest version of the plugin from the WordPress Plugin Site.


30
Jun 11

Graceful Sidebar Version 1.0.12 Released!

Some kind folks commented on the wordpress extend plugin page for the Graceful Sidebar Plugin requesting support for shortcodes. Ask and ye shall receive! Version 1.0.12 has been release with support for shortcodes. Shortcodes are tags that can be incorporated in wordpress pages or posts which get translated into different content. For example, I can include a shortcode which tells me what city you live in by leveraging my WP Geocode Plugin. This plugin populates a number of shortcodes that get translated into geography based information about the reader.

Your City: Glendora
Your State: CA
Your IP: 38.107.179.226


28
Jun 11

Gantter Project – A Great, Free Way to Manage Projects

I’ve used OpenProj for several years. It’s a nice, free alternative to MS Project. The only problem is sharing the project plans with folks – rarely do people I work with have OpenProj installed. Fortunately, OpenProj gives you the option of saving as a MS Project XML file. This makes it easier but I was still looking for the ability to save the projects in PDF format. This is possible, but only with the paid version of OpenProj. This is when I found the Gantter Project.

Gantter is written to work with Google Apps. It enables you to import MS Project project plans, save them as PDF and even save them directly to Google Docs.

For me, Google Docs and the Gantter Project work best with my custom domain – mlynn.org – but you can use it even if you don’t have a custom domain. Visit Gantter.com to find out more information about this great, free tool to help you manage your projects.


27
Jun 11

Graceful Sidebar Version 1.0.11 Released

I received a note today from a user of my Graceful Sidebar Plugin. He mentioned that his theme worked perfectly without the plugin in use. However, when he activated the plugin and displayed a custom sidebar for a specific page, the footer of his theme displayed incorrectly. It turns out that I had some funky logic in the plugin which cased wordpress to display an extra closing DIV tag. I’ve fixed the code and submitted the update which is available at WordPress.org.


22
Jan 11

WP-ExtJS Version 1.0.4 – ExtJS Pivot Grid Example

In honor of Version 1.0.4 of the WP-ExtJS Plugin being committed this morning, I decided to post a new example. This example shows the powerful pivot grid capabilities in the latest version of ExtJS from Sencha.

 

Grab the Plugin from WordPress.org

 

Please note that you must upgrade to the latest version of ExtJS – Currently 3.3.1.

 

Pivot Grid Example

This example shows how to create a Pivot Grid backed by an Ext.data.Store.

 

Continue reading →


12
Jan 11

Create a Custom Sidebar for Each Post or Page on Your WordPress Blog

Update: June 27th, 2011
Graceful Sidebar Plugin Version 1.0.11 Released

If you’ve been here before, this will be a review.  However, I think it bares mentioning in a new post.  Have you ever wanted to customize your blog such that the sidebar content displayed a different bit of content for each page on your site?  Well that’s the story behind the Graceful Sidebar Plugin.

The plugin works by extending the post and page editing screens with two additional fields.  Title, and Content.  The title field stores the content that will be displayed in the title of a widget on the post or page you’re editing.

Once you’ve installed the plugin, and have dragged the Graceful Sidebar Widget to the sidebar, you’ll begin to see this content displayed on your blog.

You may edit these fields for each post or page that you want to display different sidebar details or content.

To obtain this plugin, either visit the ; site and download, or you can install the plugin directly from within your administrative console.  Simply click Plugins->Add New->Search for “Graceful Sidebar”.

Efficiency / Wordpress1 Comment
9
Jan 11

Minimizing Hacks and Spams on Your WordPress Blog

As long as there’s money to be had by gaining exposure on the web, we’ll have to suffer with the less than reputable out there trying to game the system by filling up your blog with lame comments and links to their crappy porn, drug or adult dating web sites. You can minimize the impact of these n’er do wells, however by implementing several plugins and taking certain actions in response to their attempts.

Continue reading →


6
Jan 11

A Simple Excel Decision Matrix | The Lynn Decision Tool

Here’s a very simple Excel based decision tool which I’ve used in many different forms for both personal and business use over the years. In this basic format, this tool will enable you to list work through a decision process between two major choices.

The tool lets you provide two basic choices (cell C2 and cell E2), features of the overall decision (these are typically outcomes or impacts of your decision between the two choices), weights for each feature and a grade for each decision by feature.

The tool also provides a calculated score based on your grades and weights and a nice little chart showing which decision came out on top.

To use the tool follow these basic instructions:

1. Provide your two choices in cell C2 and cell E2. eg: Join Army, and Go to College
2. List the features of the decision as a whole in column A rows 3 through 16. You don’t need to complete a rows. You’ll want to focus on outcomes or impacts of your decision when listing these features. eg: Long term impact on life goals.
3. Weight each feature on a scale of 1-5 based on how much you value this feature in column B, rows 3 through 16.
4. Provide a grade for each decision as it pertains to the feature. For many decisions, this will be highly subjective… don’t give too much thought initially to your scores. Try to record your immediate reaction.

Note: Don’t put anything in the “Score” columns… these are computed fields.

That’s it – very simple as I said. This tool can be built upon in many ways. I wanted to keep it simple initially and provide a Simple Decision tool. If you have other tools you use to help you make decisions, please use the comments field and let me know.

Simple Excel Decision Tool (601)