Skip to content

better handling of href uri #469 #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.*;
import java.awt.geom.*;
import java.io.IOException;
import java.net.URI;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -232,7 +233,7 @@ private void addUriAsLink(RenderingContext c, Box box, PDPage page, float pageHe
} else {
XRLog.general(Level.WARNING, "Could not find valid target for link. Link href = " + uri);
}
} else if (uri.contains("://")) {
} else if (isURI(uri)) {
PDActionURI uriAct = new PDActionURI();
uriAct.setURI(uri);

Expand All @@ -249,6 +250,15 @@ private void addUriAsLink(RenderingContext c, Box box, PDPage page, float pageHe
}
}

private static boolean isURI(String uri) {
try {
return URI.create(uri) != null;
} catch (IllegalArgumentException e) {
XRLog.general(Level.INFO, "'"+uri+"' in href is not a valid URI, will be skipped");
return false;
}
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
private boolean placeAnnotation(AffineTransform transform, Shape linkShape, Rectangle2D targetArea,
PDAnnotationLink annot) {
Expand Down