-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPDFConverter.java
More file actions
66 lines (46 loc) · 1.73 KB
/
PDFConverter.java
File metadata and controls
66 lines (46 loc) · 1.73 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
66
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import com.aspose.cells.*;
import com.aspose.words.PdfCompliance;
import com.aspose.words.PdfSaveOptions;
import com.aspose.words.SaveFormat;
public class PDFConverter {
public String tipoDocumento = "";
/**
* Método recebe o como entrada o arquivo que vai ser convertido para PDF
*
* @param bytesArquivo
* @return
*/
public byte[] converteParaPDF(byte[] bytesArquivo) {
if (tipoDocumento.equals("EXCEL")) {
return workFile2Excel(bytesArquivo);
}
if (tipoDocumento.equals("WORD")) {
return workFile(bytesArquivo);
} else {
InputStream entrada = new ByteArrayInputStream(bytesArquivo);
Workbook workbook = new Workbook(entrada);
PdfSaveOptions opcaoSalvar = new PdfSaveOptions();
opcaoSalvar.setCompliance(PdfCompliance.PDF_A_1_B);
ByteArrayOutputStream documentoPDF = new ByteArrayOutputStream();
workbook.save(documentoPDF, opcaoSalvar);
return documentoPDF.toByteArray();
}
}
private byte[] workFile(byte[] bytesArquivo) throws Exception {
InputStream entrada = new ByteArrayInputStream(bytesArquivo);
com.aspose.words.Document documentoWord = new com.aspose.words.Document(entrada);
ByteArrayOutputStream documentoPDF = new ByteArrayOutputStream();
documentoWord.save(documentoPDF, SaveFormat.PDF);
return documentoPDF.toByteArray();
}
private byte[] workFile2Excel(byte[] bytesArquivo) throws Exception {
InputStream entrada = new ByteArrayInputStream(bytesArquivo);
Workbook asposeCellWb = new Workbook(entrada);
ByteArrayOutputStream documentoPDF = new ByteArrayOutputStream();
asposeCellWb.save(documentoPDF, SaveFormat.PDF);
return documentoPDF.toByteArray();
}
}