import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
public class GeneratePDF {
public static void main(String[] args) {
try {
String k = "<html><body> This is my Project </body></html>";
OutputStream file = new FileOutputStream(new File("E:\\Test.pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
document.add(new Paragraph(k));
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Đây là mã của tôi để chuyển đổi HTML sang PDF. Tôi có thể chuyển đổi nó nhưng trong tập tin PDF nó tiết kiệm như HTML toàn bộ trong khi tôi cần phải hiển thị chỉ văn bản. <html><body> This is my Project </body></html>
được lưu vào PDF trong khi nó chỉ nên lưu This is my Project
.Cách chuyển đổi HTML sang PDF bằng cách sử dụng iText
thử này http://stackoverflow.com/questions/4712641/java-how-to-convert-a-html -content-to-pdf-without-loss-the-format – pratZ
Tôi cần chuyển đổi Trong java –
[API mở văn phòng Apache] (http://wiki.openoffice.org/wiki/API/Tutorials/PDF_export#How_to_use_it_from_Java) –