java實現公文印章,Java電子簽章

本文目錄一覽:

怎樣用JAVA實現電子印章

/** 

 * Copyright (c) 2003-2007 Wonders Information Co.,Ltd. All Rights Reserved.

 * 5-6/F, 20 Bldg, 481 Guiping RD. Shanghai 200233,PRC

 *

 * This software is the confidential and proprietary information of Wonders Group.

 * (Research  Development Center). You shall not disclose such

 * Confidential Information and shall use it only in accordance with 

 * the terms of the license agreement you entered into with Wonders Group. 

 *

 * Distributable under GNU LGPL license by gun.org

 */

package com.wonders.cop.billing.util;

import java.awt.AlphaComposite;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics2D;

import java.awt.Image;

import java.awt.RenderingHints;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import javax.imageio.ImageIO;

/**

 * TODO(用一句話描述該文件做什麼)

 * 

 * @Title: ImageMarkLogUtil.java

 * @Package com.wonders.cop.billing.util

 * @ClassName: ImageMarkLogUtil

 * @author YaoHang

 * @company Wonders Information Co.,Ltd.

 * @date 2014年11月6日 下午4:24:35

 * @version V1.0

 */

public class ImageMarkLogoUtil {

// 水印透明度

private static float alpha = 1f;

// 水印橫向位置

private static int positionWidth = 82;

// 水印縱向位置

private static int positionHeight = 545;

// 水印文字字體

private static Font font = new Font(“宋體”, Font.PLAIN, 13);

// 水印文字顏色

private static Color color = Color.black;

public static void main(String[] args) {

String srcImgPath = “d:/888880002302900_web.jpg”;

String targerTextPath = “d:/qie_text.jpg”;

ImageMarkLogoUtil

.markImageByTexts(testValue(),

BillDetailImagePosition.getPosition(“888880002302900”), srcImgPath,

targerTextPath);

}

public static Map testValue() {

MapString, String value = new HashMapString, String();

value.put(“feedPrice”, “15.1”);

value.put(“feedCount”, “20”);

value.put(“nowNum”, “124”);

value.put(“drainageCount”, “55”);

value.put(“drainagePrice”, “1.5”);

value.put(“feedCost”, “66”);

value.put(“cost”, “66”);

value.put(“drainageCost”, “100”);

value.put(“barcode”, “10101010101010101”);

value.put(“nextCopy”, “2014-12-10”);

value.put(“waterType”, “居民生活用水”);

value.put(“meterReader”, “測試人員”);

value.put(“copyNumber”, “741sg”);

value.put(“prevCarryOver”, “0.25”);

value.put(“nowCarryOver”, “2.12”);

value.put(“openDate”, “20141002”);

value.put(“nextMonth”, “201402 “);

value.put(“remark”, “您繳付的2013年03月30.80元水費,我公司已收到,謝謝!”);

value.put(“detailStatus”, “00”);

value.put(“billStatus”, “00”);

value.put(“prevMonth”, “201406”);

value.put(“lastPayDate”, “20140112”);

value.put(“companyName”, “市北水”);

value.put(“type”, “1”);

value.put(“amount”, “58.1”);

value.put(“address”, “浦秀路220弄10號101”);

value.put(“year”,”2014″);

value.put(“month”, “04”);

value.put(“billId”, “11111”);

value.put(“account”, “38445450”);

value.put(“companyId”, “888880002302900”);

value.put(“realName”, “姚航”);

return value;

}

/**

 * 給圖片添加水印文字、可設置水印文字的旋轉角度

 * 

 * @param logoText

 * @param srcImgPath

 * @param targerPath

 * @param degree

 */

public static void markImageByTexts(MapString, String value,

MapString, String[] position, String srcImgPath, String targerPath) {

InputStream is = null;

OutputStream os = null;

try {

// 1、源圖片

Image srcImg = ImageIO.read(new File(srcImgPath));

BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null),

srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);

// 2、得到畫筆對象

IteratorString positionIter = position.keySet().iterator();

String key = “”;

String logotext = “”;

String[] xy;

while (positionIter.hasNext()) {

key = positionIter.next();

xy = position.get(key);

logotext = value.get(key);

System.out.println(“key:”+key+”,value:”+logotext);

if (xy != null  xy.length == 2)

printText(srcImg, buffImg, logotext,

Integer.valueOf(xy[0]), Integer.valueOf(xy[1]));

}

// 10、生成圖片

os = new FileOutputStream(targerPath);

ImageIO.write(buffImg, “JPG”, os);

System.out.println(“圖片完成添加水印文字”);

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (null != is)

is.close();

} catch (Exception e) {

e.printStackTrace();

}

try {

if (null != os)

os.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

/**

 * 在圖片上列印文字

 * 

 * @param srcImg

 * @param buffImg

 * @param logoText

 * @return

 */

private static void printText(Image srcImg, BufferedImage buffImg,

String logoText, Integer positionX, Integer PositionY) {

Graphics2D g = buffImg.createGraphics();

// 3、設置對線段的鋸齒狀邊緣處理

g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,

RenderingHints.VALUE_INTERPOLATION_BILINEAR);

g.drawImage(

srcImg.getScaledInstance(srcImg.getWidth(null),

srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);

// 5、設置水印文字顏色

g.setColor(color);

// 6、設置水印文字Font

g.setFont(font);

// 7、設置水印文字透明度

g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,

alpha));

// 8、第一參數-設置的內容,後面兩個參數-文字在圖片上的坐標位置(x,y)

g.drawString(logoText, positionX, PositionY);

// 9、釋放資源

g.dispose();

}

}

電子印章產品在公文中的應用

傳統實體印章的實地紙質蓋章方式帶來的用章難問題,是當前組織公文管理中的核心難題。電子合同平台可以幫助組織製作和管理具有法律效力的電子印章,一個平台就能對所有印章進行全過程管理和使用監控。

組織通過引入電子印章將蓋章、簽字搬到線上,在半電子化的基礎上徹底打通公文電子體系,實現全程無紙化管理。

(電子印章台帳)

圍繞組織內部發文流程,一對一化解各個環節的管理難題,給公文流轉提速:

1.擬稿便捷:電子擬稿可以直接根據需求套用模板,實現在線編輯,並全程記錄所有文件修改痕迹,通過修改留痕功能保證公文內容安全。

2.簽發安全:在公文簽發環節,電子合同平台提供驗簽和身份驗真服務,避免代簽、盜簽風險,明確簽署人身份,確保簽發可靠。

為了提升公文簽發效率,電子合同平台的移動簽署服務,在簽發過程中,無論領導是否在公司,隨時用手機就能簽字、蓋章,保留簽字痕迹,方便又安全。

印章的真實性是驗證公文的核心環節,電子合同平台提供的每個簽名和印章都有權威CA機構頒發的數字證書,隨時都能查明印章和簽署人的身份,全程確保安全發文。

3.套紅自動:公文自動套紅全程無需人工操作,格式規範、速度快,提升發文效率。

4.用印智能:以電子印章替換實體印章,以透明的線上籤署方式確保用印中的印章和內容安全。

電子合同平台在蓋章環節自動將審核確認的公文自動轉換成國家標準的PDF格式,文件更加正式,不易篡改;對組織的所有電子印章進行使用許可權設置,控制使用人員,提升使用安全性;多部門聯合用印能夠實現多個部門的同步用章,無需輾轉跑腿,提升發文效率。

5.列印防泄:蓋完章的文件有時候需要下發到多個區域,列印傳閱的過程中,電子合同平台的防偽列印功能可以加強文件管控力,防止文件外泄、防止內容篡改。

6.簽收驗真:組織可以直接將來文上傳至電子合同平台進行驗證,如果已經和公文系統集成,收文的同時就能自動檢驗文件的簽名和印章的真實性。確保文件來源、文件內容、文件印章真實。

怎樣用JAVA實現電子印章?

參考如下代碼:

package com.wonders.cop.billing.util;

import java.awt.AlphaComposite;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics2D;

import java.awt.Image;

import java.awt.RenderingHints;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;

import javax.imageio.ImageIO;

public class ImageMarkLogoUtil {

// 水印透明度

private static float alpha = 1f;

// 水印橫向位置

private static int positionWidth = 82;

// 水印縱向位置

private static int positionHeight = 545;

// 水印文字字體

private static Font font = new Font(“宋體”, Font.PLAIN, 13);

// 水印文字顏色

private static Color color = Color.black;

public static void main(String[] args) {

String srcImgPath = “d:/888880002302900_web.jpg”;

String targerTextPath = “d:/qie_text.jpg”;

ImageMarkLogoUtil

.markImageByTexts(testValue(),

BillDetailImagePosition.getPosition(“888880002302900”), srcImgPath,

targerTextPath);

}

public static Map testValue() {

MapString, String value = new HashMapString, String();

value.put(“feedPrice”, “15.1”);

value.put(“feedCount”, “20”);

value.put(“nowNum”, “124”);

value.put(“drainageCount”, “55”);

value.put(“drainagePrice”, “1.5”);

value.put(“feedCost”, “66”);

value.put(“cost”, “66”);

value.put(“drainageCost”, “100”);

value.put(“barcode”, “10101010101010101”);

value.put(“nextCopy”, “2014-12-10”);

value.put(“waterType”, “居民生活用水”);

value.put(“meterReader”, “測試人員”);

value.put(“copyNumber”, “741sg”);

value.put(“prevCarryOver”, “0.25”);

value.put(“nowCarryOver”, “2.12”);

value.put(“openDate”, “20141002”);

value.put(“nextMonth”, “201402 “);

value.put(“remark”, “您繳付的2013年03月30.80元水費,我公司已收到,謝謝!”);

value.put(“detailStatus”, “00”);

value.put(“billStatus”, “00”);

value.put(“prevMonth”, “201406”);

value.put(“lastPayDate”, “20140112”);

value.put(“companyName”, “市北水”);

value.put(“type”, “1”);

value.put(“amount”, “58.1”);

value.put(“address”, “浦秀路220弄10號101”);

value.put(“year”,”2014″);

value.put(“month”, “04”);

value.put(“billId”, “11111”);

value.put(“account”, “38445450”);

value.put(“companyId”, “888880002302900”);

value.put(“realName”, “姚航”);

return value;

}

/**

* 給圖片添加水印文字、可設置水印文字的旋轉角度

*

* @param logoText

* @param srcImgPath

* @param targerPath

* @param degree

*/

public static void markImageByTexts(MapString, String value,

MapString, String[] position, String srcImgPath, String targerPath) {

InputStream is = null;

OutputStream os = null;

try {

// 1、源圖片

Image srcImg = ImageIO.read(new File(srcImgPath));

BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null),

srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);

// 2、得到畫筆對象

IteratorString positionIter = position.keySet().iterator();

String key = “”;

String logotext = “”;

String[] xy;

while (positionIter.hasNext()) {

key = positionIter.next();

xy = position.get(key);

logotext = value.get(key);

System.out.println(“key:”+key+”,value:”+logotext);

if (xy != null xy.length == 2)

printText(srcImg, buffImg, logotext,

Integer.valueOf(xy[0]), Integer.valueOf(xy[1]));

}

// 10、生成圖片

os = new FileOutputStream(targerPath);

ImageIO.write(buffImg, “JPG”, os);

System.out.println(“圖片完成添加水印文字”);

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (null != is)

is.close();

} catch (Exception e) {

e.printStackTrace();

}

try {

if (null != os)

os.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

/**

* 在圖片上列印文字

*

* @param srcImg

* @param buffImg

* @param logoText

* @return

*/

private static void printText(Image srcImg, BufferedImage buffImg,

String logoText, Integer positionX, Integer PositionY) {

Graphics2D g = buffImg.createGraphics();

// 3、設置對線段的鋸齒狀邊緣處理

g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,

RenderingHints.VALUE_INTERPOLATION_BILINEAR);

g.drawImage(

srcImg.getScaledInstance(srcImg.getWidth(null),

srcImg.getHeight(null), Image.SCALE_SMOOTH), 0, 0, null);

// 5、設置水印文字顏色

g.setColor(color);

// 6、設置水印文字Font

g.setFont(font);

// 7、設置水印文字透明度

g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,

alpha));

// 8、第一參數-設置的內容,後面兩個參數-文字在圖片上的坐標位置(x,y)

g.drawString(logoText, positionX, PositionY);

// 9、釋放資源

g.dispose();

}

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/236051.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-12 11:58
下一篇 2024-12-12 11:58

相關推薦

發表回復

登錄後才能評論