導航:首頁 > 文字圖片 > javaweb圖片文字

javaweb圖片文字

發布時間:2022-05-27 05:14:29

『壹』 java如何實現在web工程中用OpenOffice生成帶有圖片水印的pdf

需要itext2.1.5,

以下是對pdf加水印的代碼,包括文字水印和圖片水印


public int fileCopy(String srcPath, String destPath) {
FileOutputStream fos = null;
FileInputStream fis = null;
try {
fos = new FileOutputStream(destPath);
fis = new FileInputStream(srcPath);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
return 1;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
fos.flush();
fos.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return 0;
}

/**
* 為pdf文件加文字水印
*
* @param srcPath
* 源文件路徑
* @param destPath
* 目標文件路徑
* @param waterText
* 水印文字
* @throws DocumentException
* @throws IOException
*/
public void wordWaterMark(String srcPath, String destPath, String waterText) throws DocumentException, IOException {
int result = fileCopy(srcPath, destPath);
if (result == 1) {
// 待加水印的文件
PdfReader reader = new PdfReader(destPath);
// 加完水印的文件
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(srcPath));

int total = reader.getNumberOfPages() + 1;
PdfContentByte content;
// 設置字體
BaseFont base = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

// 水印文字
int j = waterText.length(); // 文字長度
char c = 0;
int high = 0;// 高度
// 循環對每頁插入水印
for (int i = 1; i < total; i++) {
// 水印的起始
high = 60;
content = stamper.getUnderContent(i);
PdfGState gs = new PdfGState();
gs.setFillOpacity(0.1f);// 設置透明度為0.2
content.setGState(gs);
// 開始
content.beginText();
// 設置顏色
// content.setColorFill(new Color());
// 設置字體及字型大小
content.setFontAndSize(base, 88);
// 設置起始位置
content.setTextMatrix(120, 333);
// 開始寫入水印
for (int k = 0; k < j; 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失敗====================");
}

}

public void picWaterMark(String srcPath, String destPath, String imageFilePath)
throws DocumentException, IOException {
int result = fileCopy(srcPath, destPath);
if (result == 1) {
// 待加水印的文件
PdfReader reader = new PdfReader(destPath);
// 加完水印的文件
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(srcPath));
Image img = Image.getInstance(imageFilePath);
img.setAbsolutePosition(50, 400);// 坐標
img.setRotation(20);// 旋轉 弧度
img.setRotationDegrees(45);// 旋轉 角度
// image.scaleAbsolute(200,100);//自定義大小
img.scalePercent(50);// 依照比例縮放
int pageSize = reader.getNumberOfPages();
for (int i = 1; i <= pageSize; i++) {
PdfContentByte under = stamper.getUnderContent(i);
under.addImage(img);
PdfGState gs = new PdfGState();
gs.setFillOpacity(0.2f);// 設置透明度為0.2
under.setGState(gs);
}
stamper.close();// 關閉
System.out.println("添加成功++++++++++++++++++++++++++++++++++++++++++");
} else {
System.out.println("復制pdf失敗====================");
}
}


linux下轉pdf可以用libreoffice,需要安裝,這個是免費的,具體代碼如下:

String command = "libreoffice5.0 --invisible --convert-to pdf:writer_pdf_Export --outdir " + destFilepath
+ " " + source;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

『貳』 javaWeb怎麼實現根據內容生成縮略圖

packagecom.hoo.util;

importjava.awt.Image;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.net.MalformedURLException;
importjava.net.URL;
importjavax.imageio.ImageIO;
importcom.sun.image.codec.jpeg.ImageFormatException;
importcom.sun.image.codec.jpeg.JPEGCodec;
importcom.sun.image.codec.jpeg.JPEGEncodeParam;
importcom.sun.image.codec.jpeg.JPEGImageEncoder;

/**
*<b>function:</b>縮放圖片工具類,創建縮略圖、伸縮圖片比例
*@authorhoojo
*@createDate2012-2-3上午10:08:47
*@fileScaleImageUtils.java
*@packagecom.hoo.util
*@version1.0
*/
{

_SCALE_QUALITY=1f;
_IMAGE_FORMAT=".jpg";//圖像文件的格式
_FILE_PATH="C:/temp-";

/**
*<b>function:</b>設置圖片壓縮質量枚舉類;
*Someguidelines:0.75highquality、0.5mediumquality、0.25lowquality
*@authorhoojo
*@createDate2012-2-7上午11:31:45
*@fileScaleImageUtils.java
*@packagecom.hoo.util
*@projectJQueryMobile
*@version1.0
*/
publicenumImageQuality{
max(1.0f),high(0.75f),medium(0.5f),low(0.25f);

privateFloatquality;
publicFloatgetQuality(){
returnthis.quality;
}
ImageQuality(Floatquality){
this.quality=quality;
}
}

privatestaticImageimage;

/**
*<b>function:</b>通過目標對象的大小和標准(指定)大小計算出圖片縮小的比例
*@authorhoojo
*@createDate2012-2-6下午04:41:48
*@paramtargetWidth目標的寬度
*@paramtargetHeight目標的高度
*@paramstandardWidth標准(指定)寬度
*@paramstandardHeight標准(指定)高度
*@return最小的合適比例
*/
publicstaticdoublegetScaling(doubletargetWidth,doubletargetHeight,doublestandardWidth,doublestandardHeight){
doublewidthScaling=0d;
doubleheightScaling=0d;
if(targetWidth>standardWidth){
widthScaling=standardWidth/(targetWidth*1.00d);
}else{
widthScaling=1d;
}
if(targetHeight>standardHeight){
heightScaling=standardHeight/(targetHeight*1.00d);
}else{
heightScaling=1d;
}
returnMath.min(widthScaling,heightScaling);
}

『叄』 javaweb如何處理像空間說說那樣的文字和圖片的發表

這個你需要文本編輯器的插件了。

『肆』 為什麼javaweb運行後只有文字沒圖片沒樣式

沒樣式,那就是樣式沒起作用,看下css,js文件有沒有錯誤,或者有沒有導入進去,F12跟進一下

『伍』 javaweb裡面上傳圖片的時候字元串索引超出范圍怎麼回事

把+1拿到括弧外面來:
filename = filename.substring(filename.lastIndexOf("\\") + 1);

『陸』 java web中,用src圖片只顯示邊框與X,內容顯示不出來文件已經放在WebContent/images里

代碼改成如下:<img src="../images/center.jpg"/>

『柒』 Java web 怎麼保證圖片在前文字在後,並且處於同一行

css樣式 一個float:left 一個float:right

『捌』 java web中表單標記中編寫關於圖片的代碼的時候怎樣編寫才能確定是電腦里的哪個文件夾里的圖片

是最基礎的網頁開發語言
Hyper Text Markup Language 超文本標記語言
超文本
超文本使用超鏈接的方法,將不同空間的文字信息組織在一起的網狀文本。
標記語言:
由標簽構成的語言。<標簽名稱>,如html,xml
標記語言不是編程語言
快速入門:
語法:
html文檔後綴名.html或者.htm
標簽分為:
圍堵標簽:有開始標簽和結束標簽。如,<html>、<html>
自閉和標簽:開始標簽和結束標簽在一起。如,<br/>
標簽可以嵌套:
需要正確嵌套,不能你中有我,我中有你
正確:<a><b></b></a>
錯誤:<a><b></a></b>
在開始標簽中可以定義屬性。屬性是由鍵值對構成,值需要用引號(單雙都可以)引起來。
html的標簽不區分大小寫,建議使用小寫

『玖』 java web 登錄 ,上傳視頻、上傳圖片 、上傳文字 小項目

寫一個servlet使用org.apache.commons.fileupload.servlet.ServletFileUpload 這個類提交,然後傳入到資料庫的話需要用流的寫入即可

閱讀全文

與javaweb圖片文字相關的資料

熱點內容
可愛男海圖片 瀏覽:482
志願者照片圖片男生 瀏覽:572
word批量插入的圖片重疊怎麼辦 瀏覽:647
選不出衣服發瘋的圖片 瀏覽:614
寓意很美的文字圖片 瀏覽:293
白菜圖片可愛 瀏覽:589
瓊瑤白色衣服搭配圖片 瀏覽:612
大人男生發型圖片 瀏覽:286
動漫女生全身帥氣圖片 瀏覽:173
國畫寫意梅花圖片大全 瀏覽:573
男生反戴手錶圖片 瀏覽:114
二次元主播男生圖片 瀏覽:817
女孩卡通校園圖片 瀏覽:536
真人男生腹肌圖片高清 瀏覽:643
女生一道卷發型圖片 瀏覽:5
越野沙灘車價格及圖片 瀏覽:777
單排皮卡車圖片及價格 瀏覽:623
軍人行李的圖片簡單 瀏覽:377
一個女孩拿著行李箱的圖片 瀏覽:275
洗碗工衣服圖片 瀏覽:560