diff --git a/itext-java-html-pdf/.classpath b/itext-java-html-pdf/.classpath index 33a301cc..8d216a15 100644 --- a/itext-java-html-pdf/.classpath +++ b/itext-java-html-pdf/.classpath @@ -3,6 +3,17 @@ - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/itext-java-html-pdf/index.html b/itext-java-html-pdf/index.html index db6616a9..054b0e51 100644 --- a/itext-java-html-pdf/index.html +++ b/itext-java-html-pdf/index.html @@ -7,8 +7,10 @@

HTML to PDF

- itext 5.4.2 converting HTML to PDF + itext 7.1.9 + converting HTML to PDF

+ java-logo diff --git a/itext-java-html-pdf/java.png b/itext-java-html-pdf/java.png new file mode 100644 index 00000000..c1e3d023 Binary files /dev/null and b/itext-java-html-pdf/java.png differ diff --git a/itext-java-html-pdf/pdf.pdf b/itext-java-html-pdf/pdf.pdf deleted file mode 100644 index 16654fcc..00000000 Binary files a/itext-java-html-pdf/pdf.pdf and /dev/null differ diff --git a/itext-java-html-pdf/pom.xml b/itext-java-html-pdf/pom.xml index d764eeb2..f7910a6b 100644 --- a/itext-java-html-pdf/pom.xml +++ b/itext-java-html-pdf/pom.xml @@ -12,18 +12,20 @@ UTF-8 + RELEASE - com.itextpdf - itextpdf - 5.4.2 - - - com.itextpdf.tool - xmlworker - 5.4.1 + com.itextpdf + itext7-core + 7.1.9 + pom + + + com.itextpdf + html2pdf + 2.1.6 diff --git a/itext-java-html-pdf/src/main/java/com/hmkcode/App.java b/itext-java-html-pdf/src/main/java/com/hmkcode/App.java index 0e6c9723..0be911e5 100644 --- a/itext-java-html-pdf/src/main/java/com/hmkcode/App.java +++ b/itext-java-html-pdf/src/main/java/com/hmkcode/App.java @@ -1,29 +1,31 @@ package com.hmkcode; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import com.itextpdf.text.Document; -import com.itextpdf.text.DocumentException; -import com.itextpdf.text.pdf.PdfWriter; -import com.itextpdf.tool.xml.XMLWorkerHelper; + +import com.itextpdf.html2pdf.HtmlConverter; public class App { - public static void main( String[] args ) throws DocumentException, IOException + public static final String HTML = "

Hello

" + + "

This was created using iText

" + + "hmkcode.com"; + + + public static void main( String[] args ) throws FileNotFoundException, IOException { - // step 1 - Document document = new Document(); - // step 2 - PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf")); - // step 3 - document.open(); - // step 4 - XMLWorkerHelper.getInstance().parseXHtml(writer, document, - new FileInputStream("index.html")); - //step 5 - document.close(); - + + // String to PDF + HtmlConverter.convertToPdf(HTML, new FileOutputStream("string-to-pdf.pdf")); + + + // HTML file to PDF + HtmlConverter.convertToPdf(new FileInputStream("index.html"), + new FileOutputStream("index-to-pdf.pdf")); + + System.out.println( "PDF Created!" ); } } diff --git a/java-jasper/pom.xml b/java-jasper/pom.xml new file mode 100644 index 00000000..37666f32 --- /dev/null +++ b/java-jasper/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + + com.hmkcode + java-jasper + 1.0-SNAPSHOT + + java-jasper + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + net.sf.jasperreports + jasperreports + 6.10.0 + + + + + org.springframework + spring-core + 5.2.3.RELEASE + + + + diff --git a/java-jasper/src/main/java/com/hmkcode/App.java b/java-jasper/src/main/java/com/hmkcode/App.java new file mode 100644 index 00000000..72853237 --- /dev/null +++ b/java-jasper/src/main/java/com/hmkcode/App.java @@ -0,0 +1,61 @@ +package com.hmkcode; + +import net.sf.jasperreports.engine.*; +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; +import org.springframework.util.ResourceUtils; + +import java.io.*; +import java.util.*; + +public class App +{ + // name and destination of output file e.g. "report.pdf" + private static String destFileName = "report.pdf"; + public static void main( String[] args ) throws FileNotFoundException, JRException { + + System.out.println( "generating jasper report..." ); + + // 1. compile template ".jrxml" file + JasperReport jasperReport = getJasperReport(); + + // 2. parameters "empty" + Map parameters = getParameters(); + + // 3. datasource "java object" + JRDataSource dataSource = getDataSource(); + + JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource); + JasperExportManager.exportReportToPdfFile(jasperPrint, destFileName); + + } + + private static JasperReport getJasperReport() throws FileNotFoundException, JRException { + File template = ResourceUtils.getFile("classpath:report.jrxml"); + return JasperCompileManager.compileReport(template.getAbsolutePath()); + } + private static Map getParameters(){ + Map parameters = new HashMap<>(); + parameters.put("createdBy", "hmkcode"); + return parameters; + } + + private static JRDataSource getDataSource(){ + + List countries = new LinkedList<>(); + + countries.add(new Country("IS", "Iceland", "https://i.pinimg.com/originals/72/b4/49/72b44927f220151547493e528a332173.png")); + countries.add(new Country("TR", "Turkey", "https://i.pinimg.com/originals/82/63/23/826323bba32e6e5a5996062c3a3c662f.png")); + countries.add(new Country("ZA", "South Africa", "https://i.pinimg.com/originals/f5/c7/8d/f5c78da001b46e26481c04fb93473454.png")); + countries.add(new Country("PL", "Poland", "https://i.pinimg.com/originals/7f/ae/21/7fae21c4854010b11127218ead743863.png")); + countries.add(new Country("CA", "Canada", "https://i.pinimg.com/originals/4d/d4/01/4dd401733ba25e6442fc8696e04e5846.png")); + + countries.add(new Country("PA", "Panama", "https://i.pinimg.com/originals/84/dc/e4/84dce49e52ebfb5b3814393069807e0a.png")); + countries.add(new Country("HR", "Croatia", "https://i.pinimg.com/originals/f5/8c/94/f58c94a2a2b3221328fc1e2b7acfa656.png")); + countries.add(new Country("JP", "Japan", "https://i.pinimg.com/originals/a5/d6/88/a5d688289cd6850016f14fe93b17da01.png")); + countries.add(new Country("DE", "Germany", "https://i.pinimg.com/originals/af/c9/b2/afc9b2592a9f1cf591e8a52256ae1e9f.png")); + countries.add(new Country("BR", "Brazil", "https://i.pinimg.com/originals/e4/03/c4/e403c4447a3bd8940459ae4f50856bed.png")); + + + return new JRBeanCollectionDataSource(countries); + } +} diff --git a/java-jasper/src/main/java/com/hmkcode/Country.java b/java-jasper/src/main/java/com/hmkcode/Country.java new file mode 100644 index 00000000..ecbc501d --- /dev/null +++ b/java-jasper/src/main/java/com/hmkcode/Country.java @@ -0,0 +1,47 @@ +package com.hmkcode; + +public class Country { + + private String code; + private String name; + private String url; + + public Country(String code, String name, String url) { + this.code = code; + this.name = name; + this.url = url; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @Override + public String toString() { + return "Country{" + + "code='" + code + '\'' + + ", name='" + name + '\'' + + ", url='" + url + '\'' + + '}'; + } +} diff --git a/java-jasper/src/main/resources/report.jrxml b/java-jasper/src/main/resources/report.jrxml new file mode 100644 index 00000000..113a787a --- /dev/null +++ b/java-jasper/src/main/resources/report.jrxml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java-spi/java-spi-api/pom.xml b/java-spi/java-spi-api/pom.xml new file mode 100644 index 00000000..e7c1e87d --- /dev/null +++ b/java-spi/java-spi-api/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + + com.hmkcode.api + java-spi-api + 1.0-SNAPSHOT + + java-spi-api + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + + + + + diff --git a/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java new file mode 100644 index 00000000..4928f453 --- /dev/null +++ b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyService.java @@ -0,0 +1,6 @@ +package com.hmkcode.api; + +public interface MyService { + + void doSomething(); +} diff --git a/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java new file mode 100644 index 00000000..8e166424 --- /dev/null +++ b/java-spi/java-spi-api/src/main/java/com/hmkcode/api/MyServiceProviderInterface.java @@ -0,0 +1,6 @@ +package com.hmkcode.api; + +public interface MyServiceProviderInterface { + + MyService getService(); +} diff --git a/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar b/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar new file mode 100644 index 00000000..23a1c6be Binary files /dev/null and b/java-spi/java-spi-app/lib/java-spi-api-1.0-SNAPSHOT.jar differ diff --git a/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar b/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar new file mode 100644 index 00000000..c8007874 Binary files /dev/null and b/java-spi/java-spi-app/lib/java-spi-impl1-1.0-SNAPSHOT.jar differ diff --git a/java-spi/java-spi-app/pom.xml b/java-spi/java-spi-app/pom.xml new file mode 100644 index 00000000..74906a4f --- /dev/null +++ b/java-spi/java-spi-app/pom.xml @@ -0,0 +1,40 @@ + + + + 4.0.0 + + com.hmkcode.app + java-spi-app + 1.0-SNAPSHOT + + java-spi-app + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + + com.hmkcode.api + java-spi-api + 1.0-SNAPSHOT + system + ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar + + + com.hmkcode.impl + java-spi-impl1 + 1.0-SNAPSHOT + system + ${project.basedir}/lib/java-spi-impl1-1.0-SNAPSHOT.jar + + + + + diff --git a/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java new file mode 100644 index 00000000..8e46d684 --- /dev/null +++ b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/App.java @@ -0,0 +1,9 @@ +package com.hmkcode.app; + +public class App +{ + public static void main( String[] args ) + { + MyServiceLoader.defaultProvider().getService().doSomething(); + } +} diff --git a/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java new file mode 100644 index 00000000..2efc5d74 --- /dev/null +++ b/java-spi/java-spi-app/src/main/java/com/hmkcode/app/MyServiceLoader.java @@ -0,0 +1,31 @@ +package com.hmkcode.app; + +import java.nio.file.ProviderNotFoundException; +import java.util.Iterator; +import java.util.ServiceLoader; + +import com.hmkcode.api.MyServiceProviderInterface; + + +public class MyServiceLoader { + + private static final String DEFAULT_PROVIDER = "com.hmkcode.impl.MyServiceProviderImpl1"; + + public static MyServiceProviderInterface defaultProvider() { + return provider(DEFAULT_PROVIDER); + } + + public static MyServiceProviderInterface provider(String providerName) { + ServiceLoader loader = ServiceLoader.load(MyServiceProviderInterface.class); + + Iterator it = loader.iterator(); + while (it.hasNext()) { + MyServiceProviderInterface provider = it.next(); + if (providerName.equals(provider.getClass().getName())) { + return provider; + } + } + throw new ProviderNotFoundException("provider " + providerName + " not found"); + } + +} diff --git a/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar b/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar new file mode 100644 index 00000000..23a1c6be Binary files /dev/null and b/java-spi/java-spi-impl1/lib/java-spi-api-1.0-SNAPSHOT.jar differ diff --git a/java-spi/java-spi-impl1/pom.xml b/java-spi/java-spi-impl1/pom.xml new file mode 100644 index 00000000..2e234c96 --- /dev/null +++ b/java-spi/java-spi-impl1/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + com.hmkcode.impl + java-spi-impl1 + 1.0-SNAPSHOT + + java-spi-impl1 + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + com.hmkcode.api + java-spi-api + 1.0-SNAPSHOT + system + ${project.basedir}/lib/java-spi-api-1.0-SNAPSHOT.jar + + + + diff --git a/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java new file mode 100644 index 00000000..24afcfa4 --- /dev/null +++ b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceImpl1.java @@ -0,0 +1,12 @@ +package com.hmkcode.impl; + +import com.hmkcode.api.MyService; + +public class MyServiceImpl1 implements MyService{ + + @Override + public void doSomething() { + System.out.println("MyServiceImpl1"); + + } +} diff --git a/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java new file mode 100644 index 00000000..252b7a3e --- /dev/null +++ b/java-spi/java-spi-impl1/src/main/java/com/hmkcode/impl/MyServiceProviderImpl1.java @@ -0,0 +1,13 @@ +package com.hmkcode.impl; + +import com.hmkcode.api.MyService; +import com.hmkcode.api.MyServiceProviderInterface; + +public class MyServiceProviderImpl1 implements MyServiceProviderInterface { + + @Override + public MyService getService() { + return new MyServiceImpl1(); + } + +} diff --git a/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface b/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface new file mode 100644 index 00000000..008c8c11 --- /dev/null +++ b/java-spi/java-spi-impl1/src/main/resources/META-INF/services/com.hmkcode.api.MyServiceProviderInterface @@ -0,0 +1 @@ +com.hmkcode.impl.MyServiceProviderImpl1 \ No newline at end of file
Title