11/*
22 This file is part of the iText (R) project.
3- Copyright (c) 1998-2025 Apryse Group NV
3+ Copyright (c) 1998-2026 Apryse Group NV
44 Authors: Apryse Software.
55
66 This program is offered under a commercial and under the AGPL license.
@@ -27,17 +27,21 @@ This file is part of the iText (R) project.
2727import com .itextpdf .html2pdf .attach .impl .OutlineHandler ;
2828import com .itextpdf .html2pdf .attach .util .AlternateDescriptionResolver ;
2929import com .itextpdf .html2pdf .css .apply .ICssApplierFactory ;
30+ import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
3031import com .itextpdf .kernel .pdf .PdfAConformance ;
3132import com .itextpdf .kernel .pdf .PdfConformance ;
3233import com .itextpdf .kernel .pdf .PdfOutputIntent ;
3334import com .itextpdf .kernel .pdf .PdfUAConformance ;
35+ import com .itextpdf .kernel .pdf .WellTaggedPdfConformance ;
3436import com .itextpdf .layout .font .FontProvider ;
3537import com .itextpdf .styledxmlparser .css .media .MediaDeviceDescription ;
3638import com .itextpdf .styledxmlparser .resolver .resource .IResourceRetriever ;
3739
3840import java .io .InputStream ;
3941import java .util .HashMap ;
4042import java .util .Map ;
43+ import java .util .Set ;
44+ import java .util .function .Supplier ;
4145
4246/**
4347 * Properties that will be used by the {@link com.itextpdf.html2pdf.HtmlConverter}.
@@ -49,7 +53,7 @@ public class ConverterProperties {
4953 */
5054 private static final int DEFAULT_LIMIT_OF_LAYOUTS = 10 ;
5155
52- private final HashMap <Class <?>, Object > dependencies = new HashMap <>();
56+ private final Map <Class <?>, Supplier < Object > > dependencies = new HashMap <>();
5357
5458 /**
5559 * The media device description.
@@ -130,7 +134,7 @@ public class ConverterProperties {
130134 * Instantiates a new {@link ConverterProperties} instance.
131135 */
132136 public ConverterProperties () {
133- this .dependencies .put (AlternateDescriptionResolver .class , new AlternateDescriptionResolver ());
137+ this .dependencies .put (AlternateDescriptionResolver .class , () -> new AlternateDescriptionResolver ());
134138 }
135139
136140 /**
@@ -155,9 +159,7 @@ public ConverterProperties(ConverterProperties other) {
155159 this .continuousContainerEnabled = other .continuousContainerEnabled ;
156160 this .conformance = other .conformance ;
157161 this .outputIntent = other .outputIntent ;
158- for (Class <?> aClass : other .dependencies .keySet ()) {
159- this .dependencies .put (aClass , other .dependencies .get (aClass ));
160- }
162+ this .dependencies .putAll (other .dependencies );
161163 }
162164
163165 /**
@@ -486,13 +488,40 @@ public PdfUAConformance getPdfUaConformance() {
486488 * Required parameter, when converting to PDF/UA one has to specify an explicit PDF/UA conformance.
487489 *
488490 * @param uaConformance a {@link PdfUAConformance} constant
491+ *
489492 * @return the {@link ConverterProperties} instance
490493 */
491494 public ConverterProperties setPdfUAConformance (PdfUAConformance uaConformance ) {
492495 this .conformance = new PdfConformance (conformance .getAConformance (), uaConformance );
493496 return this ;
494497 }
495498
499+ /**
500+ * Sets the generation and strictness level of the WTPDF that must be followed.
501+ * Required parameter, when converting to WTPDF one has to specify an explicit WTPDF conformance.
502+ * <p>
503+ * For pdfHtml currently we only support 1 WTPDF conformance level.
504+ *
505+ * @param wtPdfConformance a {@link WellTaggedPdfConformance} constant
506+ *
507+ * @return the {@link ConverterProperties} instance
508+ */
509+ public ConverterProperties setWtPdfConformance (WellTaggedPdfConformance wtPdfConformance ) {
510+ this .conformance = new PdfConformance (conformance .getAConformance (), conformance .getUAConformance (),
511+ wtPdfConformance );
512+ return this ;
513+ }
514+
515+ /**
516+ * Gets the generation and strictness level of the conformance that must be followed.
517+ *
518+ * @return The conformance level
519+ */
520+ public PdfConformance getPdfConformance () {
521+ return conformance ;
522+ }
523+
524+
496525 /**
497526 * Checks if immediateFlush is set.
498527 * <p>
@@ -571,8 +600,56 @@ public ConverterProperties setContinuousContainerEnabled(boolean value) {
571600 * Gets the dependencies.
572601 *
573602 * @return the dependencies
603+ *
604+ * @deprecated in favor of {@link ConverterProperties#getDependenciesClasses()},
605+ * {@link ConverterProperties#getDependencySupplier(Class)}
574606 */
607+ @ Deprecated
575608 public Map <Class <?>, Object > getDependencies () {
576- return dependencies ;
609+ Map <Class <?>, Object > currentInstances = new HashMap <>();
610+ for (Map .Entry <Class <?>, Supplier <Object >> entry : dependencies .entrySet ()) {
611+ currentInstances .put (entry .getKey (), entry .getValue ().get ());
612+ }
613+ return currentInstances ;
614+ }
615+
616+ /**
617+ * Register custom dependency for the document.
618+ *
619+ * @param clazz type of the dependency
620+ * @param instanceSupplier the instance of the supplier for the dependency
621+ *
622+ * @return this {@link ConverterProperties} instance
623+ */
624+ public ConverterProperties registerDependency (Class <?> clazz , Supplier <Object > instanceSupplier ) {
625+ if (clazz == null ) {
626+ throw new IllegalArgumentException (KernelExceptionMessageConstant .TYPE_SHOULD_NOT_BE_NULL );
627+ }
628+ if (instanceSupplier == null ) {
629+ throw new IllegalArgumentException (KernelExceptionMessageConstant .INSTANCE_SUPPLIER_SHOULD_NOT_BE_NULL );
630+ }
631+ dependencies .put (clazz , instanceSupplier );
632+ return this ;
633+ }
634+
635+ /**
636+ * Get all dependencies classes.
637+ *
638+ * @return the set of dependencies classes
639+ */
640+ public Set <Class <?>> getDependenciesClasses () {
641+ return dependencies .keySet ();
642+ }
643+
644+ /**
645+ * Get specific dependency supplier.
646+ *
647+ * @param clazz the dependency class to return supplier for
648+ *
649+ * @return supplier for the dependency.
650+ * May return {code null} if no dependency supplier is present for specified class.
651+ */
652+ public Supplier <Object > getDependencySupplier (Class <?> clazz ) {
653+ return dependencies .get (clazz );
577654 }
578655}
0 commit comments