Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

fix for pdf import library. Changed to itext #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* #%L
* Lapis JSF Exporter - PDF export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* #%L
* Lapis JSF Exporter - PDF export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -14,27 +14,22 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
* #L%
*/
package com.lapis.jsfexporter.pdf;

import java.io.ByteArrayOutputStream;

import javax.faces.context.ExternalContext;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.lapis.jsfexporter.api.IExportCell;
import com.lapis.jsfexporter.api.IExportRow;
import com.lapis.jsfexporter.api.IExportType;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;

import javax.faces.context.ExternalContext;
import java.io.ByteArrayOutputStream;

public class PDFExportType implements IExportType<Document, Void, Integer> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* #%L
* Lapis JSF Exporter - PDF export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* #%L
* Lapis JSF Exporter - PDF export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -14,14 +14,14 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
* #L%
*/
package com.lapis.jsfexporter.pdf;

import com.lapis.jsfexporter.api.IExportType;
import com.lapis.jsfexporter.spi.IExportTypeFactory;
import com.lowagie.text.Document;
import com.itextpdf.text.Document;

public class PDFExportTypeFactory implements IExportTypeFactory<Document, Void, Integer> {

Expand Down
45 changes: 45 additions & 0 deletions export-type-word/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>jsf-exporter-parent</artifactId>
<version>1.0.4-SNAPSHOT</version>
<relativePath>../jsf-exporter-parent/pom.xml</relativePath>
</parent>
<artifactId>export-type-word</artifactId>
<packaging>jar</packaging>

<name>Lapis JSF Exporter - Word export type</name>
<description>DOC/DOCX export type implementation</description>
<url>https://github.com/rdicroce/jsfexporter</url>
<scm>
<url>https://github.com/rdicroce/jsfexporter</url>
<connection>scm:git:[email protected]:rdicroce/jsfexporter.git</connection>
<developerConnection>scm:git:[email protected]:rdicroce/jsfexporter.git</developerConnection>
<tag>HEAD</tag>
</scm>

<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
</dependency>

<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>jsf-exporter-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* #%L
* Lapis JSF Exporter - Excel export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.lapis.jsfexporter.word;

/**
* Configuration options for Excel export type.
* @author Richard
*
*/
public class WordExportOptions {

private WordFileFormat format;

/**
* Constructor for default options:
* <ul>
* <li>Format: XLSX</li>
* </ul>
*/
public WordExportOptions() {
this.format = WordFileFormat.DOCX;
}

public WordExportOptions(WordFileFormat format) {
this.format = format;
}

public WordFileFormat getFormat() {
return format;
}

public void setFormat(WordFileFormat format) {
this.format = format;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* #%L
* Lapis JSF Exporter - Word export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.lapis.jsfexporter.word;


import com.lapis.jsfexporter.api.IExportRow;
import com.lapis.jsfexporter.api.IExportType;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import javax.faces.context.ExternalContext;

public class WordExportType implements IExportType<XWPFDocument, WordExportOptions, Integer> {

private final WordExportOptions configOptions;
private XWPFDocument document;
private XWPFTable table;
private int rowCount;

public WordExportType(WordExportOptions configOptions) {
this.configOptions = configOptions;
document = configOptions.getFormat().createNewWorkbook();
table = document.createTable();
}

@Override
public XWPFDocument getContext() {
return document;
}

@Override
public void beginExport(int columnCount) {
table = document.createTable(1,columnCount);
}

@Override
public Integer exportRow(IExportRow row) {
XWPFTableRow tableRow = table.createRow();
for(int i = 0; i< row.getCells().size(); i++){
XWPFTableCell tableCell = tableRow.getCell(i);
tableCell.setText(row.getCells().get(i).getValue());
}

return rowCount++;
// returntableRow
}

// private static void rowSpan(XWPFTable table, int col, int fromRow, int toRow) {
// for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
// XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
// if ( rowIndex == fromRow ) {
// // The first merged cell is set with RESTART merge value
// cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
// } else {
// // Cells which join (merge) the first one, are set with CONTINUE
// cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
// }
// }
// }
// private void colSpan(XWPFTable table, int row, int fromCol, int toCol) {
// XWPFTableCell cell = table.getRow(row).getCell(fromCol);
// cell.getCTTc().getTcPr().addNewGridSpan();
// cell.getCTTc().getTcPr().getGridSpan().setVal(BigInteger.valueOf((long) toCol));
// }

@Override
public void endExport() {
// try {
// document.add(table);
// } catch (DocumentException e) {
// throw new RuntimeException(e);
// }
}

@Override
public void writeExport(ExternalContext externalContext) throws Exception {
document.write(externalContext.getResponseOutputStream());
}

@Override
public String getContentType() {
return "application/pdf";
}

@Override
public String getFileExtension() {
return "pdf";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* #%L
* Lapis JSF Exporter - Excel export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.lapis.jsfexporter.word;

import com.lapis.jsfexporter.api.IExportType;
import com.lapis.jsfexporter.spi.IExportTypeFactory;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class WordExportTypeFactory implements IExportTypeFactory<XWPFDocument, WordExportOptions, Integer> {

@Override
public IExportType<XWPFDocument, WordExportOptions, Integer> createNewExporter(WordExportOptions configOptions) {
return new WordExportType(configOptions);
}

@Override
public WordExportOptions getDefaultConfigOptions() {
return new WordExportOptions();
}

@Override
public String getExportTypeId() {
return "word";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* #%L
* Lapis JSF Exporter - Excel export type
* %%
* Copyright (C) 2013 - 2015 Lapis Software Associates
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.lapis.jsfexporter.word;
import org.apache.poi.xwpf.usermodel.*;

public enum WordFileFormat {
DOC("doc", "application/msword") {
@Override
public XWPFDocument createNewWorkbook() {
XWPFDocument xwpfDocument = new XWPFDocument();
return xwpfDocument;
}
},
DOCX("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
@Override
public XWPFDocument createNewWorkbook() {
XWPFDocument xwpfDocument = new XWPFDocument();
return xwpfDocument;
}
};

private String fileExtension;
private String mimeType;

private WordFileFormat(String fileExtension, String mimeType) {
this.fileExtension = fileExtension;
this.mimeType = mimeType;
}

public String getFileExtension() {
return fileExtension;
}

public String getMimeType() {
return mimeType;
}

public abstract XWPFDocument createNewWorkbook();

}
Loading