0

I am not very experienced in Java and I am having trouble converting a ByteArrayInputStream object to a FileInputStream object.

Is there any way to do that ?

I wrote code that takes a file URL and pass it to this function renderer.setDocument(url);

Here is my code:

 String url = new File(File_To_Convert).toURI().toURL().toString();
 String HTML_TO_PDF = "C:/Taha/SmartPlannerNew/ConvertedFile.pdf";       

  ITextRenderer renderer = new ITextRenderer();
         renderer.setDocument(url);  

but now I don't want to write anything on the hard disk so I exchanged the file with a ByteArrayInputStream that contains my text now , and I want to pass this to ITextRenderer instead of passing the File URL.

Is there any way to do that?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
mohammad
  • 2,142
  • 7
  • 35
  • 60
  • 1
    Are you sure you don't mean FileOutputStream? Usually you create an output stream from an input stream. – Gilbert Le Blanc Mar 11 '13 at 19:07
  • @Gilbert Le Blanc i modified my question to be more clear thanx. – mohammad Mar 11 '13 at 19:23
  • It looks like you want to use iText to convert HTML to PDF. This is possible. I think that rather than trying to piece the solution together yourself you would be well advised to study one or more examples. [Here's a StackOverflow question dealing exactly with this](http://stackoverflow.com/questions/235851/using-itext-to-convert-html-to-pdf) [Here's a nice simple example of converting HTML to PDF](http://javaxtendsolutions.wordpress.com/2011/01/03/itext-1-5-html-to-pdf/). If you manage to read your input file into a String you will be able to use that example as the beginning of your code. – Carl Smotricz Mar 11 '13 at 19:35
  • This looks like the same: http://stackoverflow.com/questions/1236429/whats-the-easiest-way-of-converting-an-xhtml-string-to-pdf-using-flying-saucer But I'm not sure. Is the `ITextRenderer` from this "FlyingSaucer" library, or from "itext"? (Or are they the same? I didn't want do google-guess this...) – Marco13 Jan 01 '17 at 15:35

0 Answers0