Results 1 to 7 of 7
  1. #1
    faroafro is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default Creating PDF file from a String

    Hi, i have to do this thing, create a PDF file from a source that is a String. I'm using iText libraries but i'm not able to do that. My conversion function receive a String representing the pdf file (and of course is illegible if i try to print it). I now that is weird (have a string with the content of the pdf inside) but i have no control to the input parameter. I've tried to create the file with the object PdfReader() (this is the code)

    InputStream is = new ByteArrayInputStream(myString.getBytes(encoding));
    PdfReader reader = new PdfReader(is);

    and then write with the PdfWriter but the result is a file illegible (but not empty).

    Any idea?

  2. #2
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    you have to do it programatically ?

  3. #3
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    if you know how to tag the file to make it pdf read the file parse it tag it and save it as a pdf

  4. #4
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    open some pdfs in your note pad

  5. #5
    faroafro is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    mmm i don't know what you mean, this is the part of the code which write the file:

    InputStream is = new ByteArrayInputStream(myString.getBytes(encoding));
    PdfReader reader = new PdfReader(is);
    FileOutputStream fos = new FileOutputStream("outfile.pdf");
    PdfWriter writer = PdfWriter.getInstance(document, fos);
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    document.newPage();
    PdfImportedPage page = null;
    page = writer.getImportedPage(reader, 1);
    cb.addTemplate(page, 0, 0);
    fos.flush();
    document.close();
    fos.close();

  6. #6
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default PDF Reader

    why are you using pdf reader when you are reading a text file?

  7. #7
    faroafro is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    Because the string has inside the bytes of the pdf (is a illegible string), and so i'm not able to transform it to a new file.

Similar Threads

  1. Replies: 7
    Last Post: 10-13-2009, 12:16 AM
  2. Creating Array of Characters From a String
    By ngc0202 in forum New To Java
    Replies: 6
    Last Post: 07-30-2009, 08:30 AM
  3. Creating jar file
    By Heather in forum Advanced Java
    Replies: 4
    Last Post: 02-11-2009, 10:58 AM
  4. Creating objects based on a String value
    By lvh in forum New To Java
    Replies: 4
    Last Post: 04-30-2008, 03:00 PM
  5. creating .ear file
    By psn in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-06-2008, 06:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •