Page 1 of 1

Adding text to a document

Posted: Sun Jul 22, 2012 1:28 pm
by franciscus
At the time of displaying/printing the document, I'd like to add some custom text to the footer of the document. I will use this to put the name or login-id of the user who prints the document. The purpose is to discourage people from sharing printed documents with other people who haven't paid for access to my website.

Is there an API that allows me to do that? If I could add a custom watermark at the time my Flash file is displayed, that would also allow me to do this. Or if I could reuse and change the string that the unregistered version Print2Flash prints out.

Any ideas?

Re: Adding text to a document

Posted: Mon Jul 23, 2012 1:03 pm
by staff
There is a watermark feature in Print2Flash. You may add an image to all document pages at document conversion time. See this help topic for more information:

Re: Adding text to a document

Posted: Wed Jul 25, 2012 9:21 pm
by franciscus
Yes, at conversion time. I would like to add it dynamically, when the document is being displayed by a user.

Could I do something like this:
- Generate my document without template (i.e. for "External viewer")
- Load the document into some kind of "envelope" swf (which I would write) and which would add the extra text
- Make DocViewer read that envelope swf

Or, if that can't be done:
- Generate my document with a custom template
- Design that template to not be a viewer, but an envelope, as defined above

Am I out to lunch?

Re: Adding text to a document

Posted: Thu Jul 26, 2012 4:04 am
by staff
You may employ the following approach:
1. Load Print2Flash documents in your own envelope Flash movie as described in this help topic: ... ashCS3.php
2. Obtain a reference to the page represented by MovieClip class instance using getPage Document API function (see this help topic:
3. Use properties and methods of Graphics class (the reference to which you may obtain from graphics property of MovieClip class) to draw any additional content on document pages (see this help topic: http:// ... phics.html)

You may also develop your own document viewer template as described here:

Re: Adding text to a document

Posted: Sat Jul 28, 2012 2:37 pm
by franciscus
Thanks! Whereas I tried to put code between the viewer and the document, you are saying I should write an envelope around the document-with-integrated-viewer. Sounds like a good idea and I almost got it to work.

That is, the added text displays in the viewer but when I print it, it is not included in the printout. Am I missing something?

Here is my code:

Code: Select all

import Print2Flash.*;

var P2FDocLoader:Print2FlashDoc3=new Print2FlashDoc3("FlashDoc.swf",0,0,500,350,this);
P2FDocLoader.addEventListener(Print2FlashDoc3.ONLOADEVENT, OnLoaded);

var P2FDoc:MovieClip;

function OnLoaded(e:Event) {
	P2FDoc.addEventListener("onPageLoaded", OnPageLoaded);

function OnPageLoaded(e:Object)
	var page:MovieClip = P2FDoc.getPage(;

	var fmt:TextFormat = new TextFormat();
	fmt.size = 100;
	var text:TextField = new TextField(); 
	text.text = "hello world"; 
	text.width = 500;
	text.height = 300;
	text.x = 100;
	text.y = 100;
I also tried adding the text to the first child of the page, because I noticed that each page object has a single child called PageX. But the results are the same

Code: Select all

	// Replaced  page.addChild(text);  with the following
	var c:MovieClip = page.getChildAt(0) as MovieClip;	

Re: Adding text to a document

Posted: Sun Jul 29, 2012 4:00 am
by staff
If you want to include additional content on printed pages, you need to develop your own printing algorithm. You need to add your own Print button invoking this algorithm beside the document. The standard Print button can be hidden by clearing Print Button option in the Interface tab of Document Options window. Your algorithm may be like the following:

Code: Select all

function Print(e:MouseEvent) {
	var printJob:PrintJob = new PrintJob();		
	if (printJob.start()) {
		for (var i:int=1;i<=totalPages;i++) {
			var page:MovieClip=AttachPageMovie(i);
                        // Draw additional content on the page here
			var pageAdded:Boolean=PrintPage(printJob,page);
			if (!pageAdded) break;

function PrintPage(printJob:PrintJob, page:MovieClip):Boolean {
	var pageAdded:Boolean=false

	var paWidth:Number=printJob.pageWidth/72*P2FDoc.Resolution
	var paHeight:Number=printJob.pageHeight/72*P2FDoc.Resolution

	// Create white "paper" corresponding to printable area size
	var pageMovie:MovieClip=new MovieClip()
	// Put page on "paper" centering it
	var printArea:Rectangle=new Rectangle(0,0,paWidth,paHeight)				  
	try {
	  printJob.addPage(pageMovie,printArea,new PrintJobOptions(P2FDoc.PrintAsBitmap))
	catch(e:Error) {
	return pageAdded

function AttachPageMovie(pageNum:int):MovieClip {
	var movie:MovieClip
	try {
		var AssetClass:Class = P2FDocLoader.contentLoaderInfo.applicationDomain.getDefinition("Page"+pageNum) as Class;
		movie = new AssetClass();
	 catch(e:Error) {
	 return movie	

function DrawRect(movie:Sprite,x1:Number,y1:Number,x2:Number,y2:Number,fillColor:uint,lineColor:Number) {
Print function should be invoked when a user presses your Print button. Other variables used here have the following meanings:
• P2FDocLoader - the value returned by the Print2FlashDoc3 class constructor;
• P2FDoc - reference to the document returned by getDoc() function;
• totalPages - total number of pages as returned by the getNumberOfPages() function.

You should place any additional content on pages at the place indicated by "Draw additional content on the page here" comment in the code.

Re: Adding text to a document

Posted: Wed Aug 01, 2012 9:12 pm
by franciscus
Thanks!!! I got it working.

You have been very very helpful. I am impressed by the support you give even before I purchase. I'll definitely buy a license before my trail expires.

Thanks again.