Protecting PDFs using FlexPaper

Download the compiled ReadOnly FlexPaperViewer.swf
*Note: Limited Functionality – see http://www.vigrond.com/flexpaper for ‘what you get’ – See tutorial below for which parameters work

Click here for Example

_____

Once Scribd made their switch to HTML5 for greater compatibility, it actually lost its great function to protect PDFs from being downloaded or printed.

On the search for some new technology, I found FlexPaper.

FlexPaper, in their own words, “… displays documents in your favorite browser using flash. Its way of reusing display containers makes it possible to view large documents and books.”

FlexPaper is programmed using a mix of Flash’s Flex & JavaScript, and is open-source under the GNU GPL license v3.

Natively, FlexPaper does not protect PDFs from being printed or copied.  It actually lacks options for doing so on the JavaScript front-end.  However in its Commercial License (to take the branding off for 1 domain) contains a ReadOnly parameter to disable printing & copying.

I am going to show you how to re-enable that ReadOnly parameter in the free GPL version using Flash Builder 4, disable the Flash container’s print option in the right-click context menu, and basically recompile the Flex build in the same original fashion as the Pre-compiled build of FlexPaper.

Note: This is not a hack.  It is actually suggested by FlexPaper’s developer (Eric) as a solution, albeit undocumented.

  1. Download both the Flex 4.0 & Pre-compiled (Flash) versions of FlexPaper:
    http://flexpaper.devaldi.com/download/
  2. Create a new Flex Project in Flash Builder 4 with default options (application type: Web)
  3. Once you get to the Library Path in the creation wizard, add the SWC file you got from FlexPaper’s Flex 4.0 build.
  4. Set “Framework linkage” to Merged into Code
    This will compile everything into a compacted SWF file, instead of having many different library files.
  5. Hit Finish
  6. Now you should be seeing your mxml file that looks something like this:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application 
    	xmlns:fx="http://ns.adobe.com/mxml/2009" 
    	xmlns:s="library://ns.adobe.com/flex/spark"
    	xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
    	xmlns:flexpaper="com.devaldi.controls.flexpaper.*">
    	<fx:Declarations>
    		<!-- Place non-visual elements (e.g., services, value objects) here -->
    	</fx:Declarations>

     

  7. First we need to add the FlexPaperViewer component.  With your mxml file open, go into “Design” mode.  Then at the bottom left open up the Components tab.  Under the “Custom” folder drag  the FlexPaperView component into the project.
  8. Go back into “Source” mode.  You will now see your tag.
    Go ahead and set the following attributes

    <flexpaper:FlexPaperViewer id="viewer" ReadOnly="true" width="100%" height="100%" x="0" y="0">
    </flexpaper:FlexPaperViewer>

    id:

    our id variable we can reference later to set parameters

    ReadOnly:

    Set to “true” to disable Printing & Copying.  Note:  It is not recommended to set this parameter in the JavaScript as it presents a security hole on the client side.  If you have PDF files you want people to be able to print as well, create two versions – one with and one without ReadOnly

    width:

    Set to 100% to fill our HTML Element container

    height:

    Set to 100% to fill our HTML Element container

    x:

    set x-coordinate position to zero

    y:

    set y-coordinate position to zero

  9. Next we will create an Event Handler to read in flashvars from the JavaScript
  10. In our Application tag, add a creationComplete event handler
    <s:Application 
    	xmlns:fx="http://ns.adobe.com/mxml/2009" 
    	xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()" 
    	xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
    	xmlns:flexpaper="com.devaldi.controls.flexpaper.*">
    </s:Application>
  11. Now add a <fx:Script> tag, import the flashvars, and create the init() function for our event handler:
    	<fx:Script>
    		<![CDATA[
    			//import flashvars
    			import mx.core.FlexGlobals;	
     
    			//set our viewer parameters to the flashvars (not all included)
    			private function init():void{
     
                            }
                    ]]>
            </fx:Script>
  12. Inside this init() function is where the magic happens.  We will set all the parameters for our FlexPaperViewer depending on the flashvars.  We will also disable the Print option in the Flash context menu.Set the FlashPaperViewer parameters in this style:
    viewer.SwfFile = FlexGlobals.topLevelApplication.parameters.SwfFile;
    viewer.Scale = FlexGlobals.topLevelApplication.parameters.Scale;
    viewer.ZoomTransition = FlexGlobals.topLevelApplication.parameters.ZoomTransition;	
    viewer.ZoomTime = FlexGlobals.topLevelApplication.parameters.ZoomTime;	
    viewer.ZoomInterval = FlexGlobals.topLevelApplication.parameters.ZoomInterval;	
    viewer.FitPageOnLoad = FlexGlobals.topLevelApplication.parameters.FitPageOnLoad;	
    viewer.FitWidthOnLoad = FlexGlobals.topLevelApplication.parameters.FitWidthOnLoad;	
    viewer.FullScreenAsMaxWindow = FlexGlobals.topLevelApplication.parameters.FullScreenAsMaxWindow;	
    viewer.ProgressiveLoading = FlexGlobals.topLevelApplication.parameters.ProgressiveLoading;	
    viewer.switchMode(FlexGlobals.topLevelApplication.parameters.InitViewMode);

    This format will work for the following parameters:

    • SwfFile
    • Scale
    • ZoomTransition
    • ZoomTime
    • ZoomInterval
    • FitPageOnLoad
    • FitWidthOnLoad
    • FullScreenAsMaxWindow
    • ProgressiveLoading

    Non-native parameters (will have to be programmed into JavaScript flexpaper_flash.js library):

    • ReadOnly *Not recommended due to security hole presented by giving the client control
    • width / height *Setting to anything other than 100% will break Fullscreen mode

    Note: Other parameters and Event Handler methods for the Pre-Compiled Flash Build’s javascript functions are NOT provided here.  These are undocumented and will have to be additionally discovered.  It should not be hard given a look at the function list for the FlexPaperViewer component.  Connecting Flex applications to Javascript is also well-documented on Adobe’s site.

  13. To disable the Print option in the Flash container’s right-click Context menu is pretty easy:
    var customContextMenu:ContextMenu = new ContextMenu();
    //disable the default options
    customContextMenu.hideBuiltInItems();
    this.contextMenu = customContextMenu;
  14. Go to Project->Export Release Build, and now you got your project SWF in the bin-release folder, all-inclusive.  Flash Builder also includes a playerProductInstall.swf & an unneeded html container file to test with.
  15. Remember the Pre-Compiled Flash Build of FlexPaper we downloaded?  Go ahead and extract that.  Replace FlexPaperViewer.swf with the new one.
  16. Congratulations, now you have a read-only flash PDF viewer. Full Code:
    <!--?xml version="1.0" encoding="utf-8"?-->
     
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application 
    	xmlns:fx="http://ns.adobe.com/mxml/2009" 
    	xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()" 
    	xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
    	xmlns:flexpaper="com.devaldi.controls.flexpaper.*">
    	<fx:Declarations>
    		<!-- Place non-visual elements (e.g., services, value objects) here -->
    	</fx:Declarations>
    	<flexpaper:FlexPaperViewer id="viewer" ReadOnly="true" width="100%" height="100%" x="0" y="0">
    	</flexpaper:FlexPaperViewer>
     
    	<fx:Script>
    		<![CDATA[
    			//import flashvars
    			import mx.core.FlexGlobals;	
     
    			//set our viewer parameters to the flashvars (not all included)
    			private function init():void{
    				viewer.SwfFile = FlexGlobals.topLevelApplication.parameters.SwfFile;
    				viewer.Scale = FlexGlobals.topLevelApplication.parameters.Scale;
    				viewer.ZoomTransition = FlexGlobals.topLevelApplication.parameters.ZoomTransition;	
    				viewer.ZoomTime = FlexGlobals.topLevelApplication.parameters.ZoomTime;	
    				viewer.ZoomInterval = FlexGlobals.topLevelApplication.parameters.ZoomInterval;	
    				viewer.FitPageOnLoad = FlexGlobals.topLevelApplication.parameters.FitPageOnLoad;	
    				viewer.FitWidthOnLoad = FlexGlobals.topLevelApplication.parameters.FitWidthOnLoad;	
    				viewer.FullScreenAsMaxWindow = FlexGlobals.topLevelApplication.parameters.FullScreenAsMaxWindow;	
    				viewer.ProgressiveLoading = FlexGlobals.topLevelApplication.parameters.ProgressiveLoading;	
    				viewer.switchMode(FlexGlobals.topLevelApplication.parameters.InitViewMode);
     
    				//disable Print option in Flash Context Menu
    				var customContextMenu:ContextMenu = new ContextMenu();
    				//disable the default menu options
    				customContextMenu.hideBuiltInItems();
    				this.contextMenu = customContextMenu;
     
    			}
     
    		]]>
    	</fx:Script>
     
    </s:Application>
  17. If there’s anyone out there who would just like the readonly SWF, just comment below and I’ll update the article


76 thoughts on “Protecting PDFs using FlexPaper

      1. Dist

        I use Flash’. What does that mean? Does he use Flash pro or does he have some SWF files on his web page, or does he mean Flash related tools usage in gnaerel?As I’ve said this may seem obvious to some. It may even be considered trivial but I won’t agree with that.For effective communication, and less confusion, meaning of terms must be agreed on.I’m no Flash newbie, but until some hours ago, Flash’ by itself, first meant Flash Pro’ to me.Best,Burak

    1. vigrond Post author

      I wasn’t able to get this to work with the Flex 3 swc. I experienced the same issue you had, and even after fixing it by switching the compiler to Flex 3.5, I wasn’t able to get FlexPaper to load the Paper.swf

      Anyway. I have updated the article with a ReadOnly FlexPaperViewer.swf. (See top)

      This one is limited in the respect that it doesn’t support the Javascript functions and control, as I didn’t program in the event handlers.

  1. Jim

    I just came across flexpaper yesterday, found it a good idea but got a little upset that the only feature why I wanted to use it, is only supported for “commercial clients”. Thanks for sharing this, it really helped me out!

  2. ricr

    hi,
    Thanks vigrond, its work perfectly in my internal website.
    but can you help me how to implement it in “split_document.php”?
    coz i want to load the swf file from different folder (not in flexpaper folder e.g. “C:\swf” )

    thanks for your help. GBU

  3. Afatac

    Hi Vigrond,

    Thank you for the Read-Only viewer. Some questions here.

    1. So if I want to have the option of enable/disable Print or Copy, I need to create different versions of the viewer? I am not familiar with software programming. It would be great if there are parameters available for enabling/disabling them.

    2. I wonder what other ways a user can ‘steal’ the swf document.

    a. In Firefox, I have tried using Tools > Page Info > Media, but the swf document is not shown there, which is good.

    b. User can press PrtSc button to capture the page one by one and OCR them later. Tedious but it works.

    1. vigrond Post author

      Hi Afatac,

      To have the option of enabling/disabling is a security issue, as this is being set in Javascript. Javascript runs client-side, so, anyone with a little bit of programming knowledge could ‘copy’ the page, and alter the javascript to ‘enable’ print & copy, hit your server with their false page and download / print the document.

      So I recommend just having two versions of the SWF for that purpose.

      Also a security issue is having the actual SWF available to the public. In the above demo, by viewing the flashvars in the flash object html, you can see that the file is located here http://vigrond.com/flexpaper/Paper.swf

      As you can see, you can view it there and print each page as it slides by. In order to fix this, you would need to have a PHP script to serve the file. For example, in your javascript instead of pointing to /flexpaper/Paper.swf, you would point to /flexpaper/getFile.php. This script would have access to private directories given the proper credentials, while the public would not. Credentials would need to be obscured, random and generated under certain circumstances in order to prevent the public from mimicking them.

      But yes, all this is defeated by the print screen button. For that, unfortunately, we cannot control the user’s environment.

      Vigrond

      1. Afatac

        Hi Vigrond,

        Thanks for the reply. I have a better understanding of securing the swf file now.

        But how about the browser cache? Is the swf file cached in the browser and can be located by user easily?

        Or is there a SWF capture software that can capture the swf file?

        Any other way that will be used by an expert to ‘steal’ the swf file?

        Pardon me if my questions are too dump…. trying to have an idea of how safe is this method of protecting the document.

        1. vigrond Post author

          Hi Afatac,

          In server side languages such as PHP, you may send headers that tell the browser not to cache the SWF file the script returns.

          As for protecting a document against experts, it’s nill impossible. The best way to protect a document is to not show it in the first place. Any data transferred to a user’s computer is available in one way or another.

          Adobe offers Encrypted PDFs, which may be a helpful solution worth looking into, but even then there are hackers working day and night to break them.

          These methods are to deter casual users.

  4. Mark Beeby

    Vigrond,

    Excellent of you to post this, many thanks. I’ve got an issue though, I’ve followed your tutorial using the Builder 4.5 from adobe, and on compilation I get a much smaller (100kb) file that just seems to get stuck on loading the doc, giving up on that I just tried your own read only version as it was going to suit, but no luck either (just loads the doc still). Does this method support split page docs:

    e.g: SwfFile :”{thesis/thesis[*,0].swf,200}”

  5. meister

    Hi, vigrond!

    It’s so nice of you to explain how read only version is done. I really need your help, so please if you have a couple of minutes…
    I used your instructions to build print free version of flexpaperviewer.swf. But unfortuntely it won’t load any document.
    http://fsf.tsu.ru/docs/delete/index_fsf.html
    Could you please, provide a correct swf or any guidelines on how to compile it correctly?

  6. Elmer

    Hi, vigrond!

    Nice blog, I’ve tried the compiled SWF at the top of the article, it works fine with simple documents; but when triying with split documents, it does not load the document. I’ve also tried compiling following your instructions and the same happens.

    any help would be much appreciated, thanks in advance.

    1. vigrond Post author

      Hi Elmer. You are correct, your params are right. The SWF I compiled doesn’t contain the code necessary for split documents.

      Unfortunately FlexPaper is not completely open-source, so I cannot see the code necessary to support split documents when I am recompiling the SWF.

      To add this support I would have to dig into the code deeper and figure it out myself. While I would love to do this to support those like you, I do not have time at the moment!

      However this guide is kind of psuedo-meant to provide a starting hold of FlexPaper so that people with programming skills might be able to compile it themselves with the features that they need.

      Thanks for stopping by and I hope this answers your question.

    1. vigrond Post author

      Hi Ben. I went to your link and I cannot see a print button. Perhaps try clearing your cache! Thanks for visiting my blog.

  7. Kevin

    Hello Vigrond,
    Firstly, thanks for your artical!
    If I want to allow user to copy the content and disable the print function at the same time, how to do?
    And how about just print, no copy.

  8. Gayan

    Hi!

    This post is looking nice!.But i have a problem with downloading the file you provided on the top.please
    can you give a link which downloads the FlexPaperViewer.swf file.

    thanks!

  9. Bryant

    This is great. Solves a problem I’ve been trying to figure out for a while. Thanks. 🙂 The only question I have about this is that it seems to ignore all the JS params I send now. Specifically I can’t get the viewing modes and the search box to go away as I had them before. Any idea why it won’t accept these anymore? Thanks again.

  10. karthic

    hi,

    I am using FlexPaper to view docs online. I am facing issues when trying the same for accessing .swf files from shared folder on the network. On this scenario, the swf does not get loaded. Can some help me with a solution for shared file access in FlexPaper…. thank you in advance….

  11. Jared

    hi vigrod can u give me alink on your FlexPaperViewer version with readonly, because i can’t download it 🙁
    😀

  12. Pingback: Course project for Telerik academy

  13. popping pimples

    Τhis esѕentіal deep-cleaning stеp of your natuгal acne treatment will ensure the remoνаl of аnу reѕіdual impuritieѕ
    the Cleanseг mіght hаve misseԁ.
    Thе preventative measurеs of thе Ѕkin – B5 acnе tгeatmеnt аre ρrovideԁ by the hоlistic formulаtions of theiг Aсnе
    Cοntrοl Timе Releаse Tаblets anԁ Acne Contrоl Ϲаρѕules – those highly acclаimed Skіn – B5
    acne trеаtment ρгoduсts.

    The ԁеrmаtologist can preѕсrіbe аntibiotics like erythromуcin,clinԁamycin οr minocylіnе
    for supeгfiсial aсne anԁ ѕtrongеr mеԁicines foг deеp аcne.
    If you try to find goοd acnе treatment on your oωn this may be veгy hard.
    So that you cаn gіѵe the appropriate treatment and finԁ the ideal гemеԁy, it
    ωill likelу bе imperatiνe that
    уoulеarn about the nature of thіs іllnеѕѕ
    аnd what сauses суѕtіc acne too.

  14. zknight

    Hi,
    I’m trying to follow the tutorial with no success! 😥
    I’m using an old read-only version but I need the version with rotation function that is present already in the free version.
    can someone share the FlexPaperViewer.swf? thanks a lot.
    zk

  15. rose brand

    Thanks for the auspicious writeup. It actually was
    once a enjoyment account it. Glance advanced
    to far brought agreeable from you! However, how could we
    keep in touch?

  16. Pingback: 仿百度文库、遇到的一些问题? - 开发者问答

  17. newbie

    Hey, might seem like a stupid comment, but in case someone’s looking for some codeless solution…

    FlexPaper will:

    1. Feed PDF to FlexPaper (standalone app or web server)
    2. FlexPaper gives you SWF
    3. You use the above to display the SWF (your “PDF”)

    A little misleading as it is NOT the same as

    1. Use some addins with SWF front end to load PDF docs.

  18. Plumbing in Hartland

    I’d like to thank you for the efforts you’ve put in writing this site.
    I am hoping to check out the same high-grade content by
    you in the future as well. In truth, your creative
    writing abilities has inspired me to get my very own site now 😉

  19. Pest Control

    I will right away take hold of your rss feed as I can not to find your email subscription link or newsletter service.
    Do you have any? Please allow me understand so that I may just
    subscribe. Thanks.

  20. whatsapp

    Please let me know if you’re looking for a article author for your site. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I’d love to write some articles for your blog in exchange for a link back to mine.
    Please blast me an e-mail if interested. Kudos!

  21. Prasad

    Hi i Want to disable print button i am downloading web server package i could not understand how to install that one please anybody helps me
    Thank you all

  22. phytolife

    My coder is trying to convince me to move to .

    net from PHP. I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using WordPress on various websites for about a year and am worried about switching to another platform.
    I have heard great things about blogengine.
    net. Is there a way I can transfer all my wordpress posts into it?
    Any kind of help would be really appreciated!

  23. tejas

    in the 2 page mode when we zoom the page after that we cannot drag the page . what can be done for it?

  24. Louisa

    This is particularly true if your breasts are heavy if though
    you are over weight. It is a communion of two bodies in one physical act.
    I did feel a slight momentary boost in overall sex drive, but not enough to match the advertised results or the cost
    in comparison to some other supplements I tried.

  25. Tuyen

    Hi everybody. I have problem in flexpaper viewer: I want to create break page line in “ReadOnly FlexPaperViewer.swf” the same to FlexPaperViewer. who can help me? Thanks a lot!

  26. Anonymous

    Hello, is there any way that someone could compile the updated FlexPaperViewer.swf with the latest version of Flex Paper? I would greatly appreciate this.

  27. KFR

    Hi,
    Im a bit week in programming, can u please help me in implementing this.

    My requirement is…
    I have pdfs in my website which im displaying dynamically n i dont want users to download or copy those pdfs..

    i tried by downloading flexreader for php but i could not implement..so please could u send me an example of pages with opening pdfs dyanamically with flex reader

  28. Brenton

    I see a lot of interesting articles on your blog. You have to spend a lot of time writing, i know how to save
    you a lot of time, there is a tool that creates unique,
    SEO friendly posts in couple of minutes, just type in google – laranita’s free content source

  29. nagrania lektorskie

    We are a group of volunteers and starting a new scheme in our community.
    Your site provided us with valuable info to work
    on. You’ve done an impressive job and our entire community will be grateful to
    you.

  30. meble bielsko

    It’s appropriate time to make some plans for the future and it’s time to be happy.
    I have read this post and if I could I desire to suggest you few interesting things or advice.

    Maybe you could write next articles referring to this article.
    I want to read even more things about it!

  31. K Vijay

    Hai Vigrod i tried a lot to remove the print option and make swf as readonly, but failed. Can u give me alink on your FlexPaperViewer version with readonly, to download it.

    With regards,

    K Vijay

  32. Marisa

    I’m now not sure where you’re getting your info,
    however good topic. I needs to spend a while finding out much more or working out more.
    Thank you for great information I used to be searching for this info for my mission.

  33. http://issuu.com

    I love your blog.. very nice colors & theme.
    Did you design this website yourself or did you hire someone
    to do it for you? Plz reply as I’m looking to construct my
    own blog and would like to know where u got this from.
    kudos

  34. rebelmouse.com

    They can be happening for a number of reasons, but the
    most common ones are software bugs. Hoje em dia, podemos optar entre
    muitos tipos de suporte. First of all, you need to understand that if your computer
    is really low on RAM to run certain programs, then you will constantly be having issues and freeze-ups.

  35. affiliate marketing for dummies pdf

    Attractive part of content. I just stumbled upon your
    site and in accession capital to assert that I
    acquire in fact enjoyed account your weblog posts. Any way I’ll be subscribing to your
    augment or even I achievement you get right of entry to constantly quickly.

  36. toddler sleep training

    Lots of consider that pajamas are just for young children and
    not for grown ups. Your child’s changeover from a crib to a toddler bed lets you make a
    choice not only regarding cost but also regarding a layout
    or favourite character from your child’s selection of toys.
    It is one of the most sought after cots in Australia.

  37. VPN Service

    Every weekend i used to pay a quick visit this website, for
    the reason that i wish for enjoyment, as this this website conations in fact fastidious funny stuff too.

  38. Mariel

    This design is spectacular! You definitely know how to keep a reader amused.
    Between your wit and your videos, I was almost moved
    to start my own blog (well, almost…HaHa!) Wonderful job.
    I really enjoyed what you had to say, and more than that, how you presented it.

    Too cool!

  39. steroids Canada

    Great goods from you, man. I have bear in mind your
    stuff prior to and you are simply too excellent. I actually like
    what you’ve obtained right here, really like what you are stating and the way in which in which you are saying it.

    You are making it entertaining and you still care for to stay it sensible.
    I can’t wait to read much more from you. That is actually a
    terrific website.

Comments are closed.