Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=""/>
<classpathentry kind="output" path=""/>
</classpath>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/ConversorPDF.class
/PDFConverter.class

17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>quia-java</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
98 changes: 65 additions & 33 deletions PDFConverter.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
public class ConversorPDF {

// A aplicação foi projetada para tratar arquivos WORD, temos que cuidar para que
// alterações não mudem o comportamento, para que não exista reflexo para clientes
// legados
public String tipoDocumento = "WORD";

/**
* Esse 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("WORD")) {
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();
} 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();
}
}
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();
}
}