java使用Itext Pdf将图像添加到Pdf文件
我正在使用iText生成Pdf。但当我尝试在pdf中添加图像时
Image schoolLogo = Image.getInstance(new URL(timetableResource.getImageUrl()));
document.add(schoolLogo);
但我也犯了同样的错误
HTTP Status 500 - Server returned HTTP response code: 400 for URL: http://139.59.72.150:8080/sms/attachments/23/42/school/23/23/Vandana International School Logo.png
type Exception report
message Server returned HTTP response code: 400 for URL:(myUrl)
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.io.IOException: Server returned HTTP response code: 400 for URL: (myUrl) sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876) sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474) java.net.URL.openStream(URL.java:1045) com.lowagie.text.Image.getInstance(Unknown Source)
# 1 楼答案
400https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html#HTTP_BAD_REQUEST
显然是连接错误,请检查url是否有效,您可以正常登录
# 2 楼答案
我已经解决了这个问题,问题是url中的空格。我已经用“% 20”替换空白空间,它工作得非常好。
# 3 楼答案
有一个完整的jumpstart教程,针对那些已经知道iText如何工作并且需要一些迁移到iText7的指针的人
在http://developers.itextpdf.com/content/itext-7-jump-start-tutorial/chapter-1-introducing-basic-building-blocks查看