Notes 생성 QR코드, 바코드 등
- package com.mmm.picture;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import java.util.Vector;
-
- import javax.imageio.ImageIO;
-
- import lotus.domino.Agent;
- import lotus.domino.AgentBase;
- import lotus.domino.AgentContext;
- import lotus.domino.Database;
- import lotus.domino.Document;
- import lotus.domino.DocumentCollection;
- import lotus.domino.EmbeddedObject;
- import lotus.domino.NotesException;
- import lotus.domino.RichTextItem;
- import lotus.domino.Session;
-
- import com.google.zxing.BarcodeFormat;
- import com.google.zxing.BinaryBitmap;
- import com.google.zxing.LuminanceSource;
- import com.google.zxing.MultiFormatReader;
- import com.google.zxing.MultiFormatWriter;
- import com.google.zxing.ReaderException;
- import com.google.zxing.Result;
- import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
- import com.google.zxing.common.ByteMatrix;
- import com.google.zxing.common.HybridBinarizer;
-
- public class QRCode extends AgentBase {
- private static final int BLACK = 0xff000000;
- private static final int WHITE = 0xFFFFFFFF;
- Session session = null;
- Agent curAgent = null;
- Database curDB = null;
- DocumentCollection docCol = null;
- Document doc = null;
- private static StringBuffer log = new StringBuffer();
-
- public void NotesMain() {
- try {
- session = getSession();
- AgentContext agentContext = session.getAgentContext();
-
- // (Your code goes here)
- curAgent = agentContext.getCurrentAgent();
- curDB = agentContext.getCurrentDatabase();
- log.append("Agent: " + curAgent.getName() + " in "
- + curDB.getFilePath() + " started at "
- + new java.util.Date().toString() + "
");
- docCol = curDB
- .search("Form = \"Certificate\" & StatusFlag = \"3\" & NeedMail = \"1\"");
- log.append("Find " + Integer.toString(docCol.getCount()) + " docs");
- for (int i = 1; i <= docCol.getCount(); i++) {
- doc = docCol.getNthDocument(i);
- if (doc != null) {
- String imgFolder = "C:\\QRCode\\";
- String imgPath = imgFolder + doc.getItemValueString("SN") + ".png";
- File imgFolderFile = new File(imgFolder);
- if(!imgFolderFile.isDirectory()){
- imgFolderFile.mkdir();
- }
- File imgFile = new File(imgPath);
- encode(" "
- + doc.getItemValueString("Ecode"), imgFile, "png");
- RichTextItem rtfField = doc.createRichTextItem("QRCode");
- try {
- rtfField.embedObject(EmbeddedObject.EMBED_ATTACHMENT,
- "", imgPath, null);
- doc.replaceItemValue("QRCoded", "Y");
- doc.save(true, false);
- rtfField.recycle();
- imgFile.delete();
- } catch (NotesException e) {
- // TODO Auto-generated catch block
- log.append("embedObject1: " + e.toString());
- } catch (Exception e) {
- log.append("embedObject2: " + e.toString());
- }
- doc.recycle();
- }
- }
- docCol.recycle();
- log.append("Agent: " + curAgent.getName() + " in "
- + curDB.getFilePath() + " finished at "
- + new java.util.Date().toString() + "
");
- sendMail(log.toString());
-
- curDB.recycle();
- curAgent.recycle();
- session.recycle();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private void sendMail(String msg) {
- try {
- Vector sendTo = new Vector();
- sendTo.add("XXX/XXX");
- sendTo.add("XXX/XXX");
-
- Document mail = curDB.createDocument();
- mail.replaceItemValue("SendTo", sendTo);
- mail.replaceItemValue(
- "Subject",
- "Message from Agent " + curAgent.getName() + " in "
- + curDB.getFilePath());
- mail.replaceItemValue("Principal", "EForm/XXX");
- RichTextItem body = mail.createRichTextItem("Body");
- body.appendText(msg);
- mail.send(false);
- mail.remove(true);
- body.recycle();
- mail.recycle();
- // System.out.println(msg);
- } catch (NotesException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- QRCode qrCode = new QRCode();
- File imgFile = new File("C:\\QRCode.png");
- //
- qrCode.encode(" ",
- imgFile, "png");
-
- //
- qrCode.decode(imgFile);
- System.out.println(log.toString());
- }
-
- /**
- * com.google.zxing.qrcode.encoder.Encoder.java static final
- * String DEFAULT_BYTE_MODE_ENCODING = "ISO8859-1"; UTF-8,
- */
- public void encode(String strCode, File imgFile, String fileType) {
- try {
- ByteMatrix byteMatrix;
- byteMatrix = new MultiFormatWriter().encode(strCode,
- BarcodeFormat.QR_CODE, 200, 200);
- writeToFile(byteMatrix, fileType, imgFile);
- } catch (Exception e) {
- log.append("encode: " + e.toString());
- }
- }
-
- public static void writeToFile(ByteMatrix matrix, String format, File file)
- throws IOException {
- BufferedImage image = toBufferedImage(matrix);
- ImageIO.write(image, format, file);
- }
-
- public static BufferedImage toBufferedImage(ByteMatrix matrix) {
- int width = matrix.getWidth();
- int height = matrix.getHeight();
- BufferedImage image = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_ARGB);
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- image.setRGB(x, y, matrix.get(x, y) == 0 ? BLACK : WHITE);
- }
- }
- return image;
- }
-
- /**
- *
- */
- public void decode(File imgFile) {
- try {
- BufferedImage image;
- try {
- image = ImageIO.read(imgFile);
- if (image == null) {
- log.append("Could not decode image");
- }
- LuminanceSource source = new BufferedImageLuminanceSource(image);
- BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
- source));
-
- Result result;
-
- // :utf-8,
- log.append(" :"
- + new MultiFormatReader().decode(bitmap).getText());
-
- } catch (IOException ioe) {
- log.append("decode1: " + ioe.toString());
- } catch (ReaderException re) {
- log.append("decode2: " + re.toString());
- }
-
- } catch (Exception ex) {
- log.append("decode3: " + ex.toString());
- }
- }
- }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
해결js가 QR코드를 생성할 때 빈 div 문제를 정의해야 합니다qrcode의 설명에 따르면: QR코드를 저장하는 요소가 있어야 합니다. 이div에 canvas,img 두 개의 라벨이 추가된 것을 볼 수 있습니다. 근데 이div를 만들고 싶지 않아요?그리고 노드-qrcode를 찾...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.