@@ -65,9 +65,17 @@ This file is part of the iText (R) project.
65
65
*/
66
66
// TODO handle <base href=".."> tag?
67
67
public class ResourceResolver {
68
+
68
69
/**
69
70
* Identifier string used when loading in base64 images.
70
71
*/
72
+ public static final String BASE64_IDENTIFIER = "base64" ;
73
+
74
+ /**
75
+ * Identifier string used when loading in base64 images.
76
+ * @deprecated This variable will be replaced by {@link #BASE64_IDENTIFIER} in 7.2 release
77
+ */
78
+ @ Deprecated
71
79
public static final String BASE64IDENTIFIER = "base64" ;
72
80
73
81
/**
@@ -330,13 +338,12 @@ public boolean isImageTypeSupportedByImageDataFactory(String src) {
330
338
protected PdfXObject tryResolveBase64ImageSource (String src ) {
331
339
try {
332
340
String fixedSrc = src .replaceAll ("\\ s" , "" );
333
- fixedSrc = fixedSrc .substring (fixedSrc .indexOf (BASE64IDENTIFIER ) + 7 );
341
+ fixedSrc = fixedSrc .substring (fixedSrc .indexOf (BASE64_IDENTIFIER ) + BASE64_IDENTIFIER . length () + 1 );
334
342
PdfXObject imageXObject = imageCache .getImage (fixedSrc );
335
343
if (imageXObject == null ) {
336
344
imageXObject = new PdfImageXObject (ImageDataFactory .create (Base64 .decode (fixedSrc )));
337
345
imageCache .putImage (fixedSrc , imageXObject );
338
346
}
339
-
340
347
return imageXObject ;
341
348
} catch (Exception ignored ) {
342
349
}
@@ -377,7 +384,7 @@ private byte[] retrieveBytesFromBase64Src(String src) {
377
384
if (isContains64Mark (src )) {
378
385
try {
379
386
String fixedSrc = src .replaceAll ("\\ s" , "" );
380
- fixedSrc = fixedSrc .substring (fixedSrc .indexOf (BASE64IDENTIFIER ) + 7 );
387
+ fixedSrc = fixedSrc .substring (fixedSrc .indexOf (BASE64_IDENTIFIER ) + BASE64_IDENTIFIER . length () + 1 );
381
388
return Base64 .decode (fixedSrc );
382
389
} catch (Exception ignored ) {
383
390
}
@@ -393,6 +400,6 @@ private byte[] retrieveBytesFromBase64Src(String src) {
393
400
* @return true if string contains base64 mark
394
401
*/
395
402
private boolean isContains64Mark (String src ) {
396
- return src .contains (BASE64IDENTIFIER );
403
+ return src .contains (BASE64_IDENTIFIER );
397
404
}
398
405
}
0 commit comments