-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimbre.java
More file actions
65 lines (49 loc) · 2.27 KB
/
Timbre.java
File metadata and controls
65 lines (49 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pdf417;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.BarcodePDF417;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class timbre {
public static final String DEST = "/rutaOrigen"; //ruta del documento en formato pdf de origen al cual se añade el timbre
public static final String INPUT="/rutaDestino"; //ruta del documento con el timbre agregado
public timbre() {
}
public void GenerarTimbre(File file) throws DocumentException, FileNotFoundException, UnsupportedEncodingException, IOException{
String lectura,cadena="";
BarcodePDF417 pdf417 = new BarcodePDF417();
pdf417.setCodeRows(5); //setear el codigo de barras
pdf417.setCodeColumns(18);
pdf417.setErrorLevel(5);
pdf417.setLenCodewords(999);
pdf417.setOptions(BarcodePDF417.PDF417_FORCE_BINARY);
FileReader f = new FileReader(file);
BufferedReader b = new BufferedReader(f);
while ((lectura = b.readLine()) != null) { //leer el archivo txt
cadena=cadena+lectura+"\n";
}
System.out.println("Datos timbre: \n"+cadena);
pdf417.setText(cadena); //insertar texto al pdf417
b.close();
com.itextpdf.text.Image image = pdf417.getImage();
try { //insertar el timbre en la factura de origen
PdfReader pdfReader = new PdfReader(INPUT);
PdfStamper pdfStamper = new PdfStamper(pdfReader,new FileOutputStream(DEST));
for(int i=1; i<= pdfReader.getNumberOfPages(); i++){
PdfContentByte content = pdfStamper.getUnderContent(i);
image.setAbsolutePosition(50,20); //seteo imagen
image.scaleAbsolute(184, 72);
content.addImage(image);
}
pdfStamper.close();
} catch (IOException | DocumentException e) {
}
}
}