Guest User

Untitled

a guest
Nov 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. Rectangle pageSize = new Rectangle(2780, 2525);
  2. Document pdfDocument = new Document(pageSize);
  3.  
  4. String pdfFilePath = outputFile;
  5.  
  6. try
  7.  
  8. {
  9. FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
  10.  
  11. PdfWriter writer = null;
  12.  
  13. writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
  14.  
  15. writer.open();
  16.  
  17. pdfDocument.open();
  18.  
  19. /**
  20.  
  21. * Proceed if the file given is a picture file
  22.  
  23. */
  24.  
  25. if (isPictureFile)
  26.  
  27. {
  28.  
  29. pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
  30.  
  31. }
  32.  
  33. /**
  34.  
  35. * Proceed if the file given is (.txt,.html,.doc etc)
  36.  
  37. */
  38.  
  39. else
  40.  
  41. {
  42.  
  43. File file = new File(inputFile);
  44.  
  45. pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils.readFileToString(file)));
  46.  
  47. }
  48.  
  49.  
  50.  
  51. pdfDocument.close();
  52.  
  53. writer.close();
  54.  
  55. }
  56.  
  57. catch (Exception exception)
  58.  
  59. {
  60.  
  61. System.out.println("Document Exception!" + exception);
  62.  
  63. }
  64.  
  65. PDFConversion pdfConversion = new PDFConversion();
  66.  
  67. //pdfConversion.createPdf("C:/shunmuga/tajmahal.jpg", "C:/shunmuga/tajmahal.pdf", true);
  68.  
  69. pdfConversion.createPdf("a.html","sample.pdf", false);
  70.  
  71. }
Add Comment
Please, Sign In to add comment