Hi.

I am currently working on a quote system project. The final step of the quote would be to print the quote.

Does anyone know whether it is possible to create a pdf file with c# coding? even if i first have to create something else like a XML file it would be OK. I just need to know whether it is possible and a few clues or ideas as to how to do it.

Although preference is for pdf a word document would also be fine.

I would really appreciate your help. Thank you.

thank you holly but i think i made a mistake asking what i asked.

perhaps i should just ask how to create a word document from C# and then the word document can be converted to pdf with some pdf tool.

so can anyone give me some idea how to go about creating word documents from within C# code?

Aspose does that too. I have used myLittleWriter in the past which is a free tool that creates rtf (Word can open them just fine)

But I don't get it. Why output a doc and then convert it? why not just output straight to pdf? Or is it a requirement that the user has a choice of output format?

Maybe this is what you're after?
http://msdn2.microsoft.com/en-us/library/bb735940.aspx

But only Office 2007 will be able to open them, prior versions your outta luck.

it does not really matter that it is first a word document and then pdf. it is just that the program's output must be in some electronic document format like word or pdf.

instead of printing the screen output and sending it via mail it has to be saved as a document so that it can be e-mailed.

in visual basic one can use the docmd.outputtext or transfertext to create all kinds of files from database tables but i dont know the C# equivalent for that.

in visual basic one can use the docmd.outputtext or transfertext to create all kinds of files from database tables

That just outputs text files not "all kinds of files" and certainly not office documents. If that's all you want to do just use the classes in System.IO

using System.IO;
            // create a writer and open the file
            TextWriter tw = new StreamWriter("test.txt");

            // write a line of text to the file
            tw.WriteLine("My output...");

            // close the stream
            tw.Close();

sorry holly but one create a csv file and then it can be opened as an excell document.

anyway. just creating an ordinary file might be my only answer. but is dot txt the only way to go? can one not use RTF or DOC? the problem is i need to have some formatting in. like bold or something.

sorry holly but one create a csv file and then it can be opened as an excell document.

A csv file is not an office document, and you never mentioned CSV before now. Excel is able to read csv files. CSV files are just textfiles.

using System.IO;
            // create a writer and open the file
            TextWriter tw = new StreamWriter("test.csv");

            // write a line of text to the file
            tw.WriteLine("\"col1\",\"col2\",\"col3\"");

            // close the stream
            tw.Close();

can one not use RTF or DOC? the problem is i need to have some formatting in. like bold or something.

Have you looked at any of the resources I posted?

RTF is also text but you have to learn the arcane formatting:
http://www.biblioscape.com/rtf15_spec.htm
Word can open rtf files.

using System.IO;
            // create a writer and open the file
            TextWriter tw = new StreamWriter("test.rtf");

            // write a line of text to the file
            tw.WriteLine("{\\rtf1{\\info{\\title some data}{\\author Ravenous Wolf}}\\par\\b Created: using c#\\b0\\tab\\par\\b\\b0\\tab\\tab\\line\\par");

            // close the stream
            tw.Close();
}

DOC

MS Word docs are proprietary (company secret) binary file, not text. Many clever developers have backward engineered the binary format and give us handy libraries such as Aspose that I mentioned earlier. But you can't just docmd.writeworddocument in any language I'm afraid.

@ hollystyles

firstly thank you. although it is a bit to soon to speak, i believe that you have provided a solution.

i of course have to learn the arcane formatting but i believe that it cannot be more difficult than learning html.

just to be sure. csharp can do rtf and rtf has special formatting which i can learn from the link you posted and then the rtf file can be opened from word? if that is so then i believe you have helped me a lot.

about the other links. i did look at them but they were not very practical. couple of years and 2007 was just not an option. but thank you for your help. i believe the last link is just what i need. i really appreciate it.

csharp can do rtf and rtf has special formatting which i can learn from the link you posted and then the rtf file can be opened from word?

Ok just to split hairs. C# is just a language, the .NET framework has classes that can write text to the filesystem. RTF is text. So yes you can programitically create RTF files by programing the .NET framework using C# syntax as demonstrated yes.

Finally, yes Microsoft Word can open RTF files.

Best of luck with your solution. If you get stuck come back to this thread any time.

Hi,
I like the information in this thread. Like me friend in Australia I prefer to generate the pdf by myself, Now, Does anybody know how to generate 2D (Two Dimensions) bar code, like the one use by Fedex or UPS.

Thank you,

Just a suggestion - I code stuff that puts data into MS Office apps - PowerPoint, Excel and Word. You are better of doing it with VB then C#. We do all processing in C# and then use VB to create the documents at the end. With Word this does the table:

Dim trange As Word.Range = _wordDocument.Paragraphs.Item(ParagraphCount()).Range
_wordDocument.Tables.Add(trange, row, col)

Then you can literaly go cell by cell to edit the values

This inserts and formats paragraph of text

With _wordDocument.Range.Paragraphs.Item(ParagraphCount()).Range
    .Text = "This is a simple text to be added as paragraph"
    .Font.Size = presOptions.FontSize
    .Font.Name = presOptions.FontFamily
    .Font.Italic = presOptions.Italic
    .Font.Bold = presOptions.Bold
    .Font.Underline = presOptions.Underlined
    .Font.Color = RGB(r, g, b)
    .Paragraphs.Alignment = alignment
End With

in the above, pres options is not something I am willing to discuss in details but basically user's settings regarding formatting.

I am a big fan of C# but with office related stuff, VB is much easier. As far as PDF conversion goes - I did this by implementing someone else's libraries, I think it costed us something like $5000.00 for an unlilmited development licence, but saved me tons of work.

Maybe he can try that XPS API I think it allows for programmatic reading writing of XPS and PDF and the new open Word format

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.