Tuesday, April 16, 2013

Disable print option in flexpaper 4.1

Recently I have been working with Flexpaper as a way to display pdf document in the AIR application / Flash Web application. This is a neat library with lots of good features, control on whether to enable print or copy or search features and so on.

The flex SDK we used is 4.1. Flexpaper released a version for Flex SDK 4.1 which was available for download at Google Code before they upgraded it to Flex 4.6 version. Not many code can make a quick jump from 4.1 to 4.5 or 4.6 SDK. They do have a separate release for SDK 3.5

So, when they released the version 4.1 for Flexpaper, they had disabled printEnabled property which allows the applicatoon to control the printing property. We downloaded the commercial version and had the same issue there.

The following is a fix that I had put up to circumvent this issue:


<?xml version="1.0" encoding="utf-8"?>
<flexpaper:FlexPaperViewer xmlns:fx="http://ns.adobe.com/mxml/2009"
                           xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="flexpaperviewer1_creationCompleteHandler(event)"
                           xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:flexpaper="com.devaldi.controls.flexpaper.*" width="400" height="300">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
       
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.containers.Panel;
            import mx.controls.Alert;
            import mx.events.FlexEvent;

            private var customContextMenu:ContextMenu;
            override public function searchText(text:String):void {
                Alert.show("Not allowed to Search", "", 0,this);
            }
            override public function printPaper(e:Event):void {
                Alert.show("Not allowed to Print", "", 0,this);
                e.stopImmediatePropagation();
                e.stopPropagation();
            }
           
            protected function flexpaperviewer1_creationCompleteHandler(event:FlexEvent):void
            {
                this.customContextMenu = new ContextMenu();
                this.contextMenu = customContextMenu;
            }
           
        ]]>
    </fx:Script>
</flexpaper:FlexPaperViewer>


I was able to catch the print and search control and effectively stop the flow before it processes further and allows the printing of the document.
The context menu changes further disabled another way to copy or print the document.

This is not fool proof and any document on the web or application level can be easily taken screen print but that is out of the scope for this problem. The main aim here was to not allow the users to print or copy whole pdf documents.

Update: The latest release seems to have streamlined many of these features and is performing slightly better than earlier releases. However, the print option that is outlined here still is a useful function to have for printing pdfs using FlexPaperViewer.

1 comment:

Hugo said...

como faço pra baixar, copiar ou imprimir esse documento? me jude por favor :(
http://www.artmedpanamericana.com.br/file.php/1/biblioteca/SESCAD/PRO-ODONTO%20-%20Cirurgia/ciclo%201/odocirc1m1-01.pdf