create pdf or word file from within c#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 164
Reputation: Ravenous Wolf is an unknown quantity at this point 
Solved Threads: 1
Ravenous Wolf Ravenous Wolf is offline Offline
Junior Poster

create pdf or word file from within c#

 
0
  #1
Sep 27th, 2007
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.
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: create pdf or word file from within c#

 
0
  #2
Sep 27th, 2007
We use a third party component to do that kind of thing. http://www.aspose.com/

There are other options, crystal reports can create pdf output too.

If your budget is 0 here are some open source c# libraries:

http://csharp-source.net/open-source/pdf-libraries
Last edited by hollystyles; Sep 27th, 2007 at 5:08 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: create pdf or word file from within c#

 
0
  #3
Sep 27th, 2007
If you fancy it (and have like a couple of years) you can implement your own. Here's the standard:

http://www.adobe.com/devnet/pdf/pdf_reference.html

You will need to understand PostScript, vector and raster graphics, font embedding and data compression.
Last edited by hollystyles; Sep 27th, 2007 at 5:08 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 164
Reputation: Ravenous Wolf is an unknown quantity at this point 
Solved Threads: 1
Ravenous Wolf Ravenous Wolf is offline Offline
Junior Poster

Re: create pdf or word file from within c#

 
0
  #4
Sep 27th, 2007
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?
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: create pdf or word file from within c#

 
0
  #5
Sep 27th, 2007
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.
Last edited by hollystyles; Sep 27th, 2007 at 7:15 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 164
Reputation: Ravenous Wolf is an unknown quantity at this point 
Solved Threads: 1
Ravenous Wolf Ravenous Wolf is offline Offline
Junior Poster

Re: create pdf or word file from within c#

 
0
  #6
Sep 27th, 2007
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.
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: create pdf or word file from within c#

 
0
  #7
Sep 27th, 2007
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

  1. using System.IO;
  2. // create a writer and open the file
  3. TextWriter tw = new StreamWriter("test.txt");
  4.  
  5. // write a line of text to the file
  6. tw.WriteLine("My output...");
  7.  
  8. // close the stream
  9. tw.Close();
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 164
Reputation: Ravenous Wolf is an unknown quantity at this point 
Solved Threads: 1
Ravenous Wolf Ravenous Wolf is offline Offline
Junior Poster

Re: create pdf or word file from within c#

 
0
  #8
Sep 27th, 2007
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.
... what society overwhelmingly asks for is snake oil. Of course, the snake oil has the most impressive names —otherwise you would be selling nothing— like "Structured Analysis and Design", "Software Engineering", "Maturity Models", "IPSE", "MIS", "OO", "BPRE".... by Edsger W. Dijkstra
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: create pdf or word file from within c#

 
0
  #9
Sep 27th, 2007
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.

  1. using System.IO;
  2. // create a writer and open the file
  3. TextWriter tw = new StreamWriter("test.csv");
  4.  
  5. // write a line of text to the file
  6. tw.WriteLine("\"col1\",\"col2\",\"col3\"");
  7.  
  8. // close the stream
  9. 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?
Last edited by hollystyles; Sep 27th, 2007 at 11:07 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: create pdf or word file from within c#

 
0
  #10
Sep 27th, 2007
RTF is also text but you have to learn the arcane formatting:
http://www.biblioscape.com/rtf15_spec.htm
Word can open rtf files.
  1. using System.IO;
  2. // create a writer and open the file
  3. TextWriter tw = new StreamWriter("test.rtf");
  4.  
  5. // write a line of text to the file
  6. tw.WriteLine("{\\rtf1{\\info{\\title some data}{\\author Ravenous Wolf}}\\par\\b Created: using c#\\b0\\tab\\par\\b\\b0\\tab\\tab\\line\\par");
  7.  
  8. // close the stream
  9. tw.Close();
  10. }

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.
Last edited by hollystyles; Sep 27th, 2007 at 11:28 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC