Java Implementation Attachment Preview (Openoffice+pdf.js) __js

Source: Internet
Author: User

Java Implementation Attachment Preview (Openoffice+pdf.js), convert Office documents through OpenOffice tools to PDF files, use Pdf.js for front-end display

Is the upgrade version of Openoffice+swftools+flexpaper, reduce the SWF file conversion, and Flexpaper can only preview 10 page content, original: http://blog.csdn.net/z69183787/article/ details/17468039


The conversion formats currently supported are as follows:

private static string[] Docfilelayouts = {". txt", ". Doc", ". docx", ". WPs", ". xls", ". xlsx", ". et", ". ppt", ". pptx", ". DPS" };//office Office software format
private static string[] Imgfilelayouts = {". jpg", ". gif", ". jpeg", ". png", ". bmp"};//picture format
private static string[] Pdffilelayouts = {". pdf"};//pdf format

The transformation format can be extended if other formats are required.

1, installation Apache_openoffice_4.1.2_win_x86_install_en-us.exe,

Download Connection: http://www.openoffice.org/download/index.html

2, add environment variables Path=d:\program Files (x86) \openoffice 4\program

3, execute Open_office_service.bat script, and see if the process Soffice run

4, Action New method

/**
 *. parsing article content to PDF
 * @param request
 * @param modelmap
 * @param baseaddition
 /
private void Initpdf (servletwebrequest request,modelmap modelmap,
              baseadditionbaseaddition) {
       Stringpath = "";
       if ("". Equals (Baseaddition.getexpandone ()) | | Baseaddition.getexpandone () ==null) {
              path= Kapath + baseaddition.getoperationid () + "/" + Baseaddition.getadditionid () + "/";
       }
       Invokes the transformation class Docconverter and passes the file that needs to be converted to the constructor method of the class
       docconverterd = new Docconverter (baseaddition);
       Call the Conver method to start the conversion, first execute doc2pdf () convert the Office file to PDF, and then execute pdf2swf () to convert the PDF to SWF;
       D.conver ();
       Call the Getpdfpath () method to print the converted PDF file path
       Stringpdfpath = Request.getrequest (). Getcontextpath () +path+d.getpdfname ();
       Put the relative path into the Sessio
       to save the Modelmap.put ("Pdfpath", Pdfpath);
}

4. Front Jsp,pdf loading display

<!--content-->
<div class= "mim_content" > <iframe width= "100%"
height= "700px" src= "<%=basepath %>js/pdf/web/viewer.html?file=${pdfpath} "></iframe>
</div>

Note: ${pdfpath},

A.pdf file path must be a project path

B. File name cannot contain Chinese s

5, switch to demo mode, because the use of IFRAME into the PDF page, Full-screen mode can not be used, specific reasons can ask Niang, here only give a full screen display ideas. Edit Viewer.js:

A. Display the full screen button

/*if (! Pdfview.supportsfullscreen) {
    document.getElementById (' Presentationmode '). Classlist.add (' hidden ');
    document.getElementById (' Secondarypresentationmode ').
      Classlist.add (' hidden ');
  } */
B. Change button click events for custom Processing

Request:function presentationmoderequest () {
  	//reference knowledgelucenedetail.jsp
	if ( Parent.document.isfullscreen==null | | !parent.document.isfullscreen) {
		parent.launchfullscreen ();
	} else{
		Parent.exitfullscreen ();
	}
    return true;
  }
C. Functions can hide unrelated div, you can display full screen, here use the Hide div

	var dochtml = document.documentelement;
	var docbody = document.body;
	var videobox = document.getElementById (' content ');
	var Mi_main_div = $ ("#mi_main_div");
	var Module_info_div = $ ("#module_info_div");
	var Module_info_2_div = $ ("#module_info_2_div");
	Enter Full-screen
	function Launchfullscreen () {
			var csstext = ' Width:100%;height:100%;overflow:hidden; ';
			Mi_main_div.hide ();
			Module_info_2_div.hide ();
			DocHtml.style.cssText = csstext;
			DocBody.style.cssText = csstext;
			Videobox.style.cssText = Csstext + '; ' + ' margin:0px;padding:0px;
			'; Module_info_div.removeclass (' Module_info ');
			Document. IsFullScreen = true;
	}
	Exits Full-screen
	function Exitfullscreen () {
			mi_main_div.show ();
			Module_info_2_div.show ();
			DocHtml.style.cssText = "";
			DocBody.style.cssText = "";
			Videobox.style.cssText = "";
			Module_info_div.addclass (' Module_info ');
			Document. IsFullScreen = false;
	}

JS, Java code, there are some garbage code, we see the volume, there is a feeling of discomfort, you can optimize their own.

Related documents pdf.js+ source code, please super chain: http://download.csdn.net/detail/shnsvyu/9573577

Related Article

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.