Adding an image to the Pdf file using Itext Pdf
source link: https://www.codesd.com/item/adding-an-image-to-the-pdf-file-using-itext-pdf.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Adding an image to the Pdf file using Itext Pdf
I am using iText to generate Pdf. But when I'm trying to add images in the pdf,
Image schoolLogo = Image.getInstance(new URL(timetableResource.getImageUrl())); document.add(schoolLogo);
But I'm getting error as
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)
Please consider switching to iText7. As Bruno already indicated, you are currently using a version that is no longer supported. For your information, the iText7 way of adding an image would be:
String FOX = "path/to/resource/fox.png";
String DOG = "path/to/resource/dog.png";
Image fox = new Image(ImageDataFactory.create(FOX));
Image dog = new Image(ImageDataFactory.create(DOG));
Paragraph p = new Paragraph("The quick brown ")
.add(fox)
.add(" jumps over the lazy ")
.add(dog);
document.add(p);
There a complete jumpstart tutorial, aimed at those people who already know how iText works and need some pointers migrating to iText7.
Check it out at http://developers.itextpdf.com/content/itext-7-jump-start-tutorial/chapter-1-introducing-basic-building-blocks
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK