aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
diff options
context:
space:
mode:
authornetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-12-17 15:43:39 +0000
committernetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-12-17 15:43:39 +0000
commit9ef042419014ebe9ea3e6ce0af5568de2d933c7d (patch)
treea8284072aac2839b4d6ea0b1d39c4f82a93e5fb1 /src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
parentcd02a128515400fdb97c276e70631d5bdb5ff509 (diff)
downloadpdf-as-3-9ef042419014ebe9ea3e6ce0af5568de2d933c7d.tar.gz
pdf-as-3-9ef042419014ebe9ea3e6ce0af5568de2d933c7d.tar.bz2
pdf-as-3-9ef042419014ebe9ea3e6ce0af5568de2d933c7d.zip
Change Request "Document Correction"
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@239 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
new file mode 100644
index 0000000..409a600
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/correction/InternalCorrector.java
@@ -0,0 +1,57 @@
+/**
+ *
+ */
+package at.gv.egiz.pdfas.impl.input.correction;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.exceptions.framework.CorrectorException;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.input.correction.Corrector;
+import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
+
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.pdf.PdfReader;
+import com.lowagie.text.pdf.PdfStamper;
+
+/**
+ * Corrects a document using iText.
+ *
+ * @author wprinz
+ */
+public class InternalCorrector implements Corrector
+{
+
+ /**
+ * @see at.gv.egiz.pdfas.framework.input.correction.Corrector#correctDocument(at.gv.egiz.pdfas.framework.input.PdfDataSource)
+ */
+ public PdfDataSource correctDocument(PdfDataSource document) throws CorrectorException
+ {
+ try
+ {
+ byte[] pdf = document.getAsByteArray();
+ PdfReader reader = new PdfReader(pdf);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(pdf.length);
+
+ PdfStamper stamper = new PdfStamper(reader, baos, '\0', false);
+ stamper.close();
+
+ baos.close();
+ byte[] corrected_pdf = baos.toByteArray();
+
+ return new ByteArrayPdfDataSourceImpl(corrected_pdf);
+ }
+ catch (DocumentException e)
+ {
+ throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e);
+ }
+ catch (IOException e)
+ {
+ throw new CorrectorException(ErrorCode.CORRECTOR_EXCEPTION, e);
+ }
+ }
+
+}