Implement the PDF Online Editing control and so on…… in Domino ...... (3)

Source: Internet
Author: User
Iii. itext
After OCX is developed, it is generated on the server and the PDF document in Domino is processed. Here we use the famous open-source jar package: itext. Helloworld of a generated PDF:

Package Com. lowagie. Examples. General. webapp;

Import Java. Io. ioexception;
Import Java. util. date;

Import Javax. servlet. servletexception;
Import Javax. servlet. http. httpservlet;
Import Javax. servlet. http. httpservletrequest;
Import Javax. servlet. http. httpservletresponse;

Import Com. lowagie. Text. Document;
Import Com. lowagie. Text. extends entexception;
Import Com. lowagie. Text. Paragraph;
Import Com.lowagie.text.html. htmlwriter;
Import Com.lowagie.text.html. writable writer;
Import Com. lowagie. Text. rtf. rtfwriter2;

/***/ /**
* Hello world example as a servlet.
*
*@ AuthorBlowagie
 */
Public   Class Helloworldservlet Extends Httpservlet {

Private   Static   Final   Long Serialversionuid =   - 6033026500372479591l ;

/***/ /**
* Returns a PDF, RTF or HTML document.
*
*@ SeeJavax. servlet. http. httpservlet # doget (javax. servlet. http. httpservletrequest, javax. servlet. http. httpservletresponse)
*/
Public   Void Doget (httpservletrequest request, httpservletresponse response)
Throws Ioexception, servletexception {

// We retrieve the presentationtype
String presentationtype = Request. getparameter ( " Presentationtype " );

// Step 1
Document document =   New Document ();
Try   {
// Step 2: we set the contenttype and create an instance of the corresponding writer
If ( " PDF " . Equals (presentationtype )) {
Response. setcontenttype ("Application/PDF");
Using writer. getinstance (document, response. getoutputstream ());
}
Else   If ( " Html " . Equals (presentationtype )) {
Response. setcontenttype ("Text/html");
Htmlwriter. getinstance (document, response. getoutputstream ());
}
Else   If ( " RTF " . Equals (presentationtype )) {
Response. setcontenttype ("Text/RTF");
Rtfwriter2.getinstance (document, response. getoutputstream ());
}
Else   {
Response. sendredirect ("Http://itextdocs.lowagie.com/tutorial/general/webapp/index.html#HelloWorld");
}

// Step 3
Document. open ();

// Step 4
Document. Add ( New Paragraph ( " Hello World " ));
Document. Add ( New Paragraph ( New Date (). tostring ()));
}
Catch (Documentexception de) {
De. printstacktrace ();
System. Err. println ("Document:" +De. getmessage ());
}

// Step 5: We close the document (the outputstream is also closed internally)
Document. Close ();
}
}

Iv. servlet and ghost screen restrictions
For details about how to deploy Servlet and related jar packages, see deploy servlet in Domino.
For details about how to Retrieve Domino attachments in servlet, refer to Java's access to Domino objects.
PDF encryption: PDF files can be encrypted to implement permission restrictions, such as control printing, windowui, menu, and other functions.
Screen restrictions: I think this is a very idiotic function, but many project managers of Party A want this symbolic thing that is more meaningful than the actual one, I really don't know where their concept of this information security comes from. There are too many methods for readable documents to retain their content, such as manual copying, software screen capture, and photo taking. Method:
There is one way to disable screen copy, but I have to tell you that you want to block other applications.ProgramIt is impossible to copy pixel content from your window. Many third-party programs can capture screen content, which is not hard to write. To intercept pixels on the screen, you only need to use bitblt to copy them from the context of the screen device. For example:

 

 

 
Cwindowdc DC (null); // use null to obtain the entire screen CDC memdc ;... // create and initialize memdcmemdc. bitblt (..., & DC); // copy the Screen Content

To copy the content of the current active window, you only need to obtain the cwnd pointer of the window and use it to construct a cwindowdc to extract the content from it.
In short, you cannot prevent other programs from intercepting the pixels in your window. So, if you just want to disable "Screen Copy" or stop the function from doing something, it is actually very easy. In Windows, the Screen Copy function is implemented by registering a hotkey. In my December 2000 topic, I demonstrated how to use registerhotkey to register application hotkeys (See C ++ Q & A: sending messages in windows, adding hot keys to your application ), windows uses the predefined hotkeys idhot_snapdesktop and idhot_snapwindow to process "Screen Copy ". These two hotkeys correspond to "print screen" and "Alt + print screen" respectively. The former is used to copy the entire screen, while the latter is used to copy only the current active window. To disable these functions, you only need to register these hotkeys. When you press these hotkeys, ask windows to send wm_hotkey messages to your program. In this case, you can ignore these messages, you can bypass the default Screen Copy behavior. Your mainframe class is the most suitable place to do this.

// Hotkey Handling Method
// Mainframe. h # include "folderframe. H "# include" resource. H "/////////////// typical MFC main frame window, override to disable printscreen. // class cmainframe: Public cframewnd {protected :... afx_msg int oncreate (publish success); // disable printscreenafx_msg void onactivate (uint nstate, cwnd * pwndother, bool bminimized); afx_msg lresult onhotkey (wparam WP, lparam LP ); afx_msg void ondestroy (); declare_message_map ()}; mainframe. CPP # include "stdafx. H "# include" mainfrm. H "# include" view. H "implement_dyncreate (cmainframe, cframewnd) begin_message_map (cmainframe, cframewnd )... // disable printscreen: on_wm_create () publish () on_wm_activate () on_message (wm_hotkey, onhotkey) end_message_map () ...int cmainframe: oncreate (extends lpcreatestruct ){... registerhotkey (m_hwnd, idhot_snapdesktop, 0, vk_snapshot); Return 0;} void cmainframe: ondestroy () {unregisterhotkey (m_hwnd, idhot_snapdesktop );} //////////////// handle hotkey: shocould be printscreen or Alt-printscreen. // do nothing (bypass Windows screen capture) // lresult cmainframe: onhotkey (wparam WP, lparam) {unreferenced_parameter (WP); Return 0; // ignore} // when window is activated/deactivated, disable/enable alt-printscreen. // (optional) // void cmainframe: onactivate (uint nstate, cwnd * pwndother, bool bminimized) {cframewnd: onactivate (nstate, pwndother, bminimized); If (nstate) registerhotkey (m_hwnd, idhot_snapwindow, mod_alt, vk_snapshot); elseunregisterhotkey (m_hwnd, idhot_snapwindow );}

the Code section shows a typical MFC cmainframe class implementation. The oncreate/ondestroy function is used to register/deregister the idhot_snapdesktop hotkey. The onactivate function is used to register/deregister the idhot_snapwindow hotkey when the application is in the active/non-active state. When your window is inactive, you can re-enable idhot_snapwindow. When other applications have focus, you can still use Alt + print screen to copy the screen.
you may think of using the cs_owndc pattern to register the window class to prevent screen copying (which causes windows to allocate a private device context for the window class), but that won't work. Windows will still copy the pixels in the private DC to the screen DC, so that any program that accesses the screen DC can see your pixels.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.