linux编程pdf百度网盘linux编程pdf

如题所述

linux命令模式下如何看pdf文件?

linux命令模式下查看pdf文件需要借助evince命令,如打开当前目录下的a.pdf文件的命令是evincea.pdf注意:在Linux的文本模式下是不能使用该命令并查看pdf文件的。可以实施fbgs,但只能查看部分pdf文档。说明:Evince原本是GNOME环境中一个简单的文档查看器,可以查看PDF、Postscript、djvu、tiff、dvi等文档。

java如何实现在web工程中用OpenOffice生成带有图片水印的pdf?

需要itext2.1.5,

以下是对pdf加水印的代码,包括文字水印和图片水印

publicintfileCopy(StringsrcPath,StringdestPath){ FileOutputStreamfos=null; FileInputStreamfis=null; try{ fos=newFileOutputStream(destPath); fis=newFileInputStream(srcPath); bytebuffer=newbyte; intlen=0; while((len=fis.read(buffer))>0){ fos.write(buffer,0,len); } return1; }catch(FileNotFoundExceptione){ e.printStackTrace(); }catch(IOExceptione){ e.printStackTrace(); }finally{ try{ fis.close(); fos.flush(); fos.close(); }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } return0; } /** *为pdf文件加文字水印 * *@paramsrcPath *源文件路径 *@paramdestPath *目标文件路径 *@paramwaterText *水印文字 *@throwsDocumentException *@throwsIOException */ publicvoidwordWaterMark(StringsrcPath,StringdestPath,StringwaterText)throwsDocumentException,IOException{ intresult=fileCopy(srcPath,destPath); if(result==1){ //待加水印的文件 PdfReaderreader=newPdfReader(destPath); //加完水印的文件 PdfStamperstamper=newPdfStamper(reader,newFileOutputStream(srcPath)); inttotal=reader.getNumberOfPages()+1; PdfContentBytecontent; //设置字体 BaseFontbase=BaseFont.createFont(fontPath,BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); //水印文字 intj=waterText.length();//文字长度 charc=0; inthigh=0;//高度 //循环对每页插入水印 for(inti=1;itotal;i++){ //水印的起始 high=60; content=stamper.getUnderContent(i); PdfGStategs=newPdfGState(); gs.setFillOpacity(0.1f);//设置透明度为0.2 content.setGState(gs); //开始 content.beginText(); //设置颜色 //content.setColorFill(newColor()); //设置字体及字号 content.setFontAndSize(base,88); //设置起始位置 content.setTextMatrix(120,333); //开始写入水印 for(intk=0;kj;k++){ content.setTextRise(high); c=waterText.charAt(k); content.showText(c+""); high+=20; } content.endText(); } stamper.close(); System.out.println("添加成功++++++++++++++++++++++++++++++++++++++++++"); }else{ System.out.println("复制pdf失败===================="); } } publicvoidpicWaterMark(StringsrcPath,StringdestPath,StringimageFilePath) throwsDocumentException,IOException{ intresult=fileCopy(srcPath,destPath); if(result==1){ //待加水印的文件 PdfReaderreader=newPdfReader(destPath); //加完水印的文件 PdfStamperstamper=newPdfStamper(reader,newFileOutputStream(srcPath)); Imageimg=Image.getInstance(imageFilePath); img.setAbsolutePosition(50,400);//坐标 img.setRotation(20);//旋转弧度 img.setRotationDegrees(45);//旋转角度 //image.scaleAbsolute(200,100);//自定义大小 img.scalePercent(50);//依照比例缩放 intpageSize=reader.getNumberOfPages(); for(inti=1;i=pageSize;i++){ PdfContentByteunder=stamper.getUnderContent(i); under.addImage(img); PdfGStategs=newPdfGState(); gs.setFillOpacity(0.2f);//设置透明度为0.2 under.setGState(gs); } stamper.close();//关闭 System.out.println("添加成功++++++++++++++++++++++++++++++++++++++++++"); }else{ System.out.println("复制pdf失败===================="); } }

linux下转pdf可以用libreoffice,需要安装,这个是免费的,具体代码如下:

Stringcommand="libreoffice5.0--invisible--convert-topdf:writer_pdf_Export--outdir"+destFilepath +""+source; try{ p=Runtime.getRuntime().exec(command); p.waitFor(); }catch(InterruptedExceptione){ e.printStackTrace(); }catch(IOExceptione){ e.printStackTrace(); }

温馨提示:答案为网友推荐,仅供参考
相似回答