org.apache.poi
diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java
index 0d38208bab..1fdf07a05f 100644
--- a/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java
+++ b/pdf/src/main/java/com/baeldung/pdf/PDF2HTMLExample.java
@@ -1,6 +1,8 @@
package com.baeldung.pdf;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
@@ -10,14 +12,21 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.fit.pdfdom.PDFDomTree;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.pdf.PdfWriter;
+import com.itextpdf.tool.xml.XMLWorkerHelper;
+
public class PDF2HTMLExample {
- private static final String FILENAME = "src/main/resources/pdf.pdf";
+ private static final String PDF = "src/main/resources/pdf.pdf";
+ private static final String HTML = "src/main/resources/html.html";
public static void main(String[] args) {
try {
- generateHTMLFromPDF(FILENAME);
- } catch (IOException | ParserConfigurationException e) {
+ generateHTMLFromPDF(PDF);
+ generatePDFFromHTML(HTML);
+ } catch (IOException | ParserConfigurationException | DocumentException e) {
e.printStackTrace();
}
}
@@ -32,4 +41,12 @@ public class PDF2HTMLExample {
pdf.close();
}
}
+
+ private static void generatePDFFromHTML(String filename) throws ParserConfigurationException, IOException, DocumentException {
+ Document document = new Document();
+ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("src/output/html.pdf"));
+ document.open();
+ XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(filename));
+ document.close();
+ }
}
diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java
index 00778d16c1..69f5d9731f 100644
--- a/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java
+++ b/pdf/src/main/java/com/baeldung/pdf/PDF2ImageExample.java
@@ -1,24 +1,36 @@
package com.baeldung.pdf;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.tools.imageio.ImageIOUtil;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
+import com.itextpdf.text.BadElementException;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.Image;
+import com.itextpdf.text.pdf.PdfWriter;
public class PDF2ImageExample {
- private static final String FILENAME = "src/main/resources/pdf.pdf";
-
+ private static final String PDF = "src/main/resources/pdf.pdf";
+ private static final String JPG = "http://cdn2.baeldung.netdna-cdn.com/wp-content/uploads/2016/05/baeldung-rest-widget-main-1.2.0";
+ private static final String GIF = "https://media.giphy.com/media/l3V0x6kdXUW9M4ONq/giphy";
+
public static void main(String[] args) {
try {
- generateImageFromPDF(FILENAME, "png");
- generateImageFromPDF(FILENAME, "jpeg");
- generateImageFromPDF(FILENAME, "gif");
- } catch (IOException e) {
+ generateImageFromPDF(PDF, "png");
+ generateImageFromPDF(PDF, "jpeg");
+ generateImageFromPDF(PDF, "gif");
+ generatePDFFromImage(JPG, "jpg");
+ generatePDFFromImage(GIF, "gif");
+ } catch (IOException | DocumentException e) {
e.printStackTrace();
}
}
@@ -32,4 +44,19 @@ public class PDF2ImageExample {
}
document.close();
}
+
+ private static void generatePDFFromImage(String filename, String extension)
+ throws IOException, BadElementException, DocumentException {
+ Document document = new Document();
+ String input = filename + "." + extension;
+ String output = "src/output/" + extension + ".pdf";
+ FileOutputStream fos = new FileOutputStream(output);
+ PdfWriter writer = PdfWriter.getInstance(document, fos);
+ writer.open();
+ document.open();
+ document.add(Image.getInstance((new URL(input))));
+ document.close();
+ writer.close();
+ }
+
}
diff --git a/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java b/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java
index c5880a4e91..7965152234 100644
--- a/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java
+++ b/pdf/src/main/java/com/baeldung/pdf/PDF2TextExample.java
@@ -1,6 +1,9 @@
package com.baeldung.pdf;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
@@ -10,14 +13,24 @@ import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.Element;
+import com.itextpdf.text.Font;
+import com.itextpdf.text.PageSize;
+import com.itextpdf.text.Paragraph;
+import com.itextpdf.text.pdf.PdfWriter;
+
public class PDF2TextExample {
- private static final String FILENAME = "src/main/resources/pdf.pdf";
+ private static final String PDF = "src/main/resources/pdf.pdf";
+ private static final String TXT = "src/main/resources/txt.txt";
public static void main(String[] args) {
try {
- generateTxtFromPDF(FILENAME);
- } catch (IOException e) {
+ generateTxtFromPDF(PDF);
+ generatePDFFromTxt(TXT);
+ } catch (IOException | DocumentException e) {
e.printStackTrace();
}
}
@@ -45,4 +58,27 @@ public class PDF2TextExample {
pw.close();
}
+ private static void generatePDFFromTxt(String filename) throws IOException, DocumentException {
+ Document pdfDoc = new Document(PageSize.A4);
+ PdfWriter.getInstance(pdfDoc, new FileOutputStream("src/output/txt.pdf"))
+ .setPdfVersion(PdfWriter.PDF_VERSION_1_7);
+ pdfDoc.open();
+
+ Font myfont = new Font();
+ myfont.setStyle(Font.NORMAL);
+ myfont.setSize(11);
+ pdfDoc.add(new Paragraph("\n"));
+
+ BufferedReader br = new BufferedReader(new FileReader(filename));
+ String strLine;
+ while ((strLine = br.readLine()) != null) {
+ Paragraph para = new Paragraph(strLine + "\n", myfont);
+ para.setAlignment(Element.ALIGN_JUSTIFIED);
+ pdfDoc.add(para);
+ }
+
+ pdfDoc.close();
+ br.close();
+ }
+
}
diff --git a/pdf/src/main/resources/html.html b/pdf/src/main/resources/html.html
new file mode 100644
index 0000000000..d3072c056c
--- /dev/null
+++ b/pdf/src/main/resources/html.html
@@ -0,0 +1,53 @@
+
+
+
+
+A very simple webpage
+
+
+
+A very simple webpage. This is an "h1" level header.
+
+This is a level h2 header.
+
+This is a level h6 header. Pretty small!
+
+This is a standard paragraph.
+
+Now I've aligned it in the center of the screen.
+
+Now aligned to the right
+
+Bold text
+
+Strongly emphasized text Can you tell the difference vs. bold?
+
+Italics
+
+Emphasized text Just like Italics!
+
+How about a nice ordered list!
+
+ - This little piggy went to market
+ - This little piggy went to SB228 class
+ - This little piggy went to an expensive restaurant in Downtown Palo Alto
+ - This little piggy ate too much at Indian Buffet.
+ - This little piggy got lost
+
+
+Unordered list
+
+ - First element
+ - Second element
+ - Third element
+
+
+
+And finally, how about some
Links?
+
+Remember, you can view the HTMl code from this or any other page by using the "View Page Source" command of your browser.
+
+
+
+
+
diff --git a/pdf/src/main/resources/txt.txt b/pdf/src/main/resources/txt.txt
new file mode 100644
index 0000000000..de0c36ae75
--- /dev/null
+++ b/pdf/src/main/resources/txt.txt
@@ -0,0 +1,3 @@
+Test
+Text
+ Test TEST
\ No newline at end of file
diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml
index cc96ea8529..754bf679b5 100644
--- a/selenium-junit-testng/pom.xml
+++ b/selenium-junit-testng/pom.xml
@@ -25,6 +25,7 @@
**/*UnitTest.java
+ false
@@ -42,6 +43,7 @@
**/*LiveTest.java
+ false
diff --git a/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java b/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java
index 58d47c0162..b97f66e9dd 100644
--- a/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java
+++ b/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java
@@ -1,14 +1,13 @@
package main.java.com.baeldung.selenium;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.concurrent.TimeUnit;
-
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
public class SeleniumExample {
private WebDriver webDriver;
@@ -38,12 +37,12 @@ public class SeleniumExample {
private void closeOverlay() {
List webElementList = webDriver.findElements(By.tagName("a"));
- try {
- if (webElementList != null && !webElementList.isEmpty()) {
- webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click();
- }
- } catch (NoSuchElementException exception) {
- exception.printStackTrace();
+ if (webElementList != null) {
+ webElementList.stream()
+ .filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
+ .filter(WebElement::isDisplayed)
+ .findAny()
+ .ifPresent(WebElement::click);
}
}
@@ -56,6 +55,6 @@ public class SeleniumExample {
}
public boolean isAuthorInformationAvailable() {
- return webDriver.findElement(By.xpath("//*[contains(text(), 'Eugen – an engineer')]")).isDisplayed();
+ return webDriver.findElement(By.xpath("//*[contains(text(), 'an engineer with a passion for teaching and building stuff on the web')]")).isDisplayed();
}
}
diff --git a/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java b/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java
index f8d9a5dada..180b3d9d33 100644
--- a/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java
+++ b/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java
@@ -26,16 +26,11 @@ public class SeleniumWithJUnitLiveTest {
@Test
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
- try {
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
assertTrue(seleniumExample.isAuthorInformationAvailable());
- } catch (Exception exception) {
- exception.printStackTrace();
- seleniumExample.closeWindow();
- }
}
}
diff --git a/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java b/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java
index 5ec9ade39f..bc8fc712bf 100644
--- a/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java
+++ b/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java
@@ -26,15 +26,10 @@ public class SeleniumWithTestNGLiveTest {
@Test
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
- try {
- seleniumExample.getAboutBaeldungPage();
- String actualTitle = seleniumExample.getTitle();
- assertNotNull(actualTitle);
- assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
- assertTrue(seleniumExample.isAuthorInformationAvailable());
- } catch (Exception exception) {
- exception.printStackTrace();
- seleniumExample.closeWindow();
- }
+ seleniumExample.getAboutBaeldungPage();
+ String actualTitle = seleniumExample.getTitle();
+ assertNotNull(actualTitle);
+ assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
+ assertTrue(seleniumExample.isAuthorInformationAvailable());
}
}
diff --git a/spring-apache-camel/pom.xml b/spring-apache-camel/pom.xml
index fbea9b779d..6cd4f136e0 100644
--- a/spring-apache-camel/pom.xml
+++ b/spring-apache-camel/pom.xml
@@ -11,25 +11,26 @@
2.16.1
4.2.4.RELEASE
+ 2.19.1
1.7
- 4.1
+ 4.12
-
+
junit
junit
${junit.version}
test
-
+
org.apache.camel
camel-core
${env.camel.version}
-
+
org.apache.camel
camel-spring
@@ -49,7 +50,7 @@
-
+
@@ -62,6 +63,22 @@
${java.version}
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+
+