The movieclip printing problem that has plagued me for many days has finally been solved. After converting a PDF file to a SWF file, the user can still print the file (that is, print the SWF file) after obtaining authorization! It is a happy thing. "There is no difficulty in the world, but you are afraid of people." As long as you focus on any problem, you can solve it step by step.
My print function implementation:
I have solved the problem of printing: printing all documents; printing a single page (I .e. a frame of movieclip); Full Screen Printing by default, in Zoom mode, supports automatic adjustment and reproduction before printing to ensure that the document is full of pages.
Unimplemented printing function: 1. User-Defined multi-page printing (not single-page printing or full-page printing). This is very simple, but I did not add this function without this requirement. 2. preview when printing 3. print custom settings (I implement page self-adaptation, whether it is A4 or B5, it is automatically filled with pages ), if you are interested, you can study these aspects on the basis of me.
Unfortunately, no progress has been made in generating thumbnails for movieclip frames and no relevant information has been found on the Internet. However, I have solved some minor problems of this task. If I have time, I will continue to study. After all, the leadership is also very much looking forward to supporting this job, which can indeed improve the user experience.
My tasks have the following minor problems: Moving documents (moving up and down buttons), dragging documents (translating documents), and auto-restoring document positions (automatically filling the display page) and Central Position Control when files are zoomed in or out.Note:The document here refers to the SWF generated by PDF conversion, that is, the movieclip to be controlled.
The following describes the network resources that have helped me a lot in implementing the movieclip printing function.
First of all, Chris gave the solution: as3 using printjob to print a movieclip (URL: http://stackoverflow.com/questions/1422259/as3-using-printjob-to-print-a-movieclip) he helped me a lot and I am very grateful. Although hisCodeThe feature did not completely solve my printing problem, but it gave me some ideas and pointed out a feasible path for me. He first took a great first step, my improvements are entirely based on his code and combined with my actual problems. It is recommended that users who encounter the same problem should first read and understand hisSource code. His code is reproduced as follows:
Print movieclip
Function printmovieclip (CLIP: movieclip)
{
VaR printjob: printjob = New Printjob ();
VaR numpages: Int = 0 ;
VaR printarea: rectangle;
VaR printheight: number;
VaR printy: Int = 0 ;
If (Printjob. Start ())
{ /* Resize movie clip to fit within page width */
If (Clip. Width > Printjob. pagewidth)
{
Clip. Width = Printjob. pagewidth;
Clip. scaley = Clip. scalex;
}
/* Store reference to print area in a new variable! Will save on Scaling calculations later */
Printarea = New Rectangle ( 0 , 0 , Printjob. pagewidth / Clip. scalex, printjob. pageheight / Clip. scaley );
Numpages = Math. Ceil (clip. Height / Printjob. pageheight );
/* Add pages to print job */
For (Var I: Int = 0 ; I < Numpages; I ++ )
{
Printjob. addpage (clip, printarea );
Printarea. Y + = Printarea. height;
}
/* Send print job to printer */
Printjob. Send ();
/* Delete job from memory */
Printjob = Null ;
}
}
Printmovieclip (testmc );
It mainly uses flash. Printing. printjob. The printjob class is used to create content and print it as one or more pages. This class allows you to display content that is visible, dynamic, or out of the screen to the user. A "print" dialog box prompts the user, and print documents that are not scaled in proportion to the content. This feature is especially useful for rendering and printing dynamic content, such as database content and dynamic text.
I personally think that printjob is more flexible (I am referring to the flexibility of printing content and the flexibility of printing settings), which is originally the class in flash. Flex as3 can still be used. In Flex, The flexprintjob class is rewritten to this class, And the flexprintjob class is the packaging object of the Flash. Printing. printjob class. It supports automatic slicing and paging of the output on multiple pages, and zooming the grid content to fit the page size of the printer. I originally wanted to use this type of object to implement my printing. However, flexprintjob is not flexible enough and only supports printing uicomponent objects. The key method addobject (OBJ: iuicomponent, scaletype: String = "matchwidth"): void adds the uicomponent object to the list of objects being printed.
The following is an example of using flexprintjob. It is very convenient to print General UI controls in flex. Reproduced from Adobe http://www.adobe.us/livedocs/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm? Context?livedocs_book_parts&file=printing_085_07.html
Flexprintjob
<? XML version = "1.0" ?>
<! -- Printing \ duplint. mxml -->
< MX: Application Xmlns: MX = "Http://www.adobe.com/2006/mxml" >
< MX: script >
<! [CDATA [
Import MX. Printing .*;
// Create a printjob instance.
Private function doprint (): void {
// Create an instance of the flexprintjob class.
VaR printjob: flexprintjob = new flexprintjob ();
// Start the print job.
If (printjob. Start ()! = True) return;
// Add the object to print. Do not scale it.
Printjob. addobject (mydatagrid, flexprintjobscaletype. None );
// Send the job to the printer.
Printjob. Send ();
}
]>
</ MX: script >
< MX: vbox ID = "Myvbox" >
< MX: DataGrid ID = "Mydatagrid" Width = "300" >
< MX: dataprovider >
< MX: Object Product = "Flash" Code = "1000" />
< MX: Object Product = "Flex" Code = "2000" />
< MX: Object Product = "ColdFusion" Code = "3000" />
< MX: Object Product = "JRun" Code = "4000" />
</ MX: dataprovider >
</ MX: DataGrid >
< MX: button ID = "Mybutton"
Label = "Print"
Click = "Doprint ();" />
</ MX: vbox >
</ MX: Application >
The above two resources are my main reference resources. You can search for more print examples and make good use of Internet resources.
Finally, I will introduce and analyze my code. The most important improvement of my code is to solve the problem of multi-page connections (that is, all frames of movieclip are fully played at a time ).
My Mc Print Code
1 // Print the Function
2 Private function printmovieclip (CLIP: movieclip): void
3 {
4 VaR printjob: printjob = new printjob ();
5 VaR printarea: rectangle;
6 If (! Printjob. Start ())
7 Return;
8 // Obtain the print page
9 VaR printpage: Int = selectpages. selecteditem. Data;
10 If (printpage = 0) // print all pages, that is, all frames of movieclip
11 {
12 For (var I: Int = 1; I < = Clip. totalframes ; I ++)
13 {
14 Clip. gotoandstop (I );
15 /* Resize movie clip to fit within page width */
16 Clip. Width = Printjob. pagewidth;
17 Clip. scaley = Clip. scalex;
18 /* Store reference to print area in a new variable! Will save on Scaling */
19 Printarea = New Rectangle (0, 0, printjob. pagewidth, printjob. pageheight );
20 // Numpages = Math. Ceil (clip. Height /Printjob. pageheight );
21 /* Add pages to print job */
22 Printjob. addpage (clip, printarea );
23 }
24 }
25 Else // print the specified page separately, that is, printing a frame of movieclip.
26 {
27 Clip. gotoandstop (printpage );
28 /* Resize movie clip to fit within page width */
29 Clip. Width = Printjob. pagewidth;
30 Clip. scaley = Clip. scalex;
31 Printarea = New Rectangle (0, 0, printjob. pagewidth, printjob. pageheight );
32 /* Add pages to print job */
33 Printjob. addpage (clip, printarea );
34 }
35
36 /* Send print job to printer */
37 Printjob. Send ();
38 /* Delete job from memory */
39 Printjob = NULL;
40
41 }