kimilg commented on code in PR #210:
URL: https://github.com/apache/pdfbox/pull/210#discussion_r2203744294


##########
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject.java:
##########
@@ -383,6 +383,69 @@ public static PDImageXObject 
createFromByteArray(PDDocument document, byte[] byt
         throw new IllegalArgumentException("Image type " + fileType + " not 
supported: " + name);
     }
 
+    /**
+     * Create a PDImageXObject from an image byte array. This overloaded 
version allows providing 
+     * a custom factory to handle specific image formats, such as BMP and GIF, 
or to act as a 
+     * fallback strategy when the default converters (e.g., for PNG or TIFF) 
fail.
+     *
+     * @param document the document that shall use this PDImageXObject.
+     * @param byteArray bytes from an image file.
+     * @param name name of image file for exception messages, can be null.
+     * @param defaultFactory optional factory used to handle BMP, GIF, or 
fallback cases 
+     *                       (e.g., for PNG or TIFF). If {@code null}, this 
method delegates to
+     *                       {@link #createFromByteArray(PDDocument, byte[], 
String)}.
+     * @return a PDImageXObject.
+     * @throws IOException if there is an error when reading the file or 
creating the
+     * PDImageXObject.
+     * @throws IllegalArgumentException if the image type is not supported.
+     */
+    public static PDImageXObject createFromByteArray(PDDocument document, 
byte[] byteArray, String name, DefaultFactory defaultFactory) throws IOException

Review Comment:
   Thanks for the feedback.  
   I’ve removed the duplicate logic, and the code feels more compact and 
cleaner now.
   Naming the functional interface is tricky - a precise name gets too long, 
but a short one feels too vague.
   I renamed it to CustomFactory because it more clearly reflects its intended 
usage than DefaultFactory.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to