prasanna_soft (27) [Avatar] Offline
#1
I am developing a tool to convert files to PDF format and send them as a mail to the requesters mail address. I have gone through the book of yours and get to know how to do the conversion. But i have some problems when i convert a word document, i think i can be able to solve that, but i after that i need to send that converted file as a mail to the requester. Please suggest me ways to do this. I need to use Javamail?. how do i make the converted file send through the mail.
blowagie (284) [Avatar] Offline
#2
Re: Converting to PDF and sending them in mail
About converting Word to PDF: iText doesn't do that, but if you succeed, you have done a great job. I believe Windward reports has a similar product that is using iText.

About sending the PDF as a mail: yes you need an API such as JavaMail. This is beyond the scope of iText.
prasanna_soft (27) [Avatar] Offline
#3
Re: Converting to PDF and sending them in mail
Thanks for reply.
I am afraid, conversion is not possible. I am trying out with Txt files now, i am trying to make the contents of the TXT file has paragraphs and write a pdf. Will this work.. May be i can parse the text file and do the five step process which u have given and try...but with ur support..

Thanks
blowagie (284) [Avatar] Offline
#4
Re: Converting to PDF and sending them in mail
Converting text to PDF is certainly possible. Start with the example in Chapter 7 and work from there. Free support from me is limited, but usually you'll get the answers you need on the mailing list: itext-questions@lists.sourceforge.net
prasanna_soft (27) [Avatar] Offline
#5
Re: Converting to PDF and sending them in mail
Thanks very much.
I will follow the tips, read that and start.
Thanks
prasanna_soft (27) [Avatar] Offline
#6
Re: Converting to PDF and sending them in mail
Hi,

I am doing a text file conversion to PDF.
I am able to print the contents of the text file in the PDF.
I used the fileinputstream object, parsed the contents of the file stored in the StringBuffer and appended the contents of the text file.
Now to write in the pdf i used the 5step process and it writing without any issues. But alignment is in big trouble.

Please help me to find which class from iText can help me solve this issue.

Thanks
blowagie (284) [Avatar] Offline
#7
Re: Converting to PDF and sending them in mail
'But alignment is in big trouble' is not sufficient information for me to answer this question.

All I can do is guess what you mean.
For instance: if you have a txt file with some tabular data:
Fruit | Vegetable
------------------------
Apple | Cabage
Pear | Salad
Orange | Carrot

You'd need a monospaced font to have this table properly aligned.
(Same as on this HTML page, where there's also an alignment problem.)
prasanna_soft (27) [Avatar] Offline
#8
Re: Converting to PDF and sending them in mail
Thanks for the quick response.
I am not having any tabular data in the text file.
for example if i have a java program in a text file just imagine how we used to type in our code...with alignment, formatting, indentation.
Now when i write the text file into PDF, the code is not the same as it is in text file.
The alignment is changed.
blowagie (284) [Avatar] Offline
#9
Re: Converting to PDF and sending them in mail
I think we have a different idea concerning the concept 'text file'. To me, it's plain text, ASCII, the stuff you get when you use Notepad. To you, it seems like RTF, or at least text with extra styles, the kind you get with Wordpad.
However, if you'd use the book example to add RTF to the PDF, you'd see the syntax (markup, RTF constructs). Apparently you don't which makes me believe you are just feeding iText with plain text without any styles.
In any case, you should rephrase your question, because the way it's formulated now, it's unanswerable. Either you have style in your text file, or you don't. You say it has, and at the same time you say it hasn't.
prasanna_soft (27) [Avatar] Offline
#10
Re: Converting to PDF and sending them in mail
Thanks for the patience. I can understand from your reply..i have given tough time to understand my requirements, sorry for confusing you.

You are right, its a plain ASCII text, i am using only notepad. I am not having any Rich Text Format, All i want is to make my pdf look similar to the notepad with lines in proper alignment.

Eg: Contents of the note pad file

class FileDemo
{

public static void main(String args[])
{
StringBuffer contents = new StringBuffer();

}
}

Contents of the PDF File:

class FileDemo { public static void main(String args[]) { StringBuffer contents = new StringBuffer(); }} ---------------------------------------------------------------

My problem is this. The alignment of the text in the pdf is different, it just write as a single paragraph.

Hope I dint confuse you this time either.
blowagie (284) [Avatar] Offline
#11
Re: Converting to PDF and sending them in mail
You confused me because you say 'alignment' where you mean 'indentation'.
The indentation of the plain text is wrong on this page too as HTML doesn't respect space characters. It would if you used non-breaking space characters instead. The same is true for iText: if you want to avoid that iText trims spaces, replace all spaces with u00a0.
Apparently you also have a problem with newlines. Normally iText respects newlines, but maybe your implementation is wrong. In any case: the example in chapter 7 respects newlines.
prasanna_soft (27) [Avatar] Offline
#12
Re: Converting to PDF and sending them in mail
Thanks for the support. Atlast the alignment problem got solved.
Its all due to StringBuffer and String issues.
iText is such a excellent one it just take care of everything.
Alignment problem came beacuse since i read with StringBuffer directly from file and wrote in the PDF. Then made some modifications in the file handling and StringBuffer things got clicked.
Thanks for your patience and tips.
javadeveloper (1) [Avatar] Offline
#13
Re: Converting to PDF and sending them in mail
Hi... i too have a similar problem.. i am trying to convert an ascii file with several fields and several records(as that of a table, but with no physical structure).. Just think that it looks like a statement entry of a bank account with several fields like time, date,stmt id,... (separated by tabbed alignment)

Remember this is not a table.. I am getting alignment problems when I try to convert it to PDF.. (Like the content of a line is broken up in two lines).. I would be thankful if you can help me regarding this...
blowagie (284) [Avatar] Offline
#14
Re: Converting to PDF and sending them in mail
Tabs will always be problematic, no matter what tool you use:
some editors will replace the tab with 4 spaces, others with 2.
You'll have to write some custom code that preprocesses the String.
prasanna_soft (27) [Avatar] Offline
#15
Re: Converting to PDF and sending them in mail
Hi,

Just check which u store the contents of the ascii file. There is a subtle difference in reading the files using String Buffer and String...it does make lot of difference.