Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 14th, 2008, 2:01 AM   #1
JunCsharp
Newbie
 
Join Date: Mar 2008
Posts: 5
Rep Power: 0 JunCsharp is on a distinguished road
Application to export to an PDF

excuse me for the thread typo if you have noticed it

Good morning to you all, this is my first post but I have been around here a little while already.

So I tried to search the forums and did not find anything about an application with code that writes text to a pdf file.

I succeeded with .txt and .doc, however I really do not know how to do so with PDF.
It is for a school project, so If anyone could help me, I'd really be gratefull.

So here is what I got so far.
(changing .doc to .pdf does create the pdf file with the title given but afterwards I can not open the pdf file!

c# Syntax (Toggle Plain Text)
  1. private void Export_Click(object sender, EventArgs e)
  2. {
  3.  
  4. string path = @"C:\Documents and Settings\Erwin\Desktop\app exporter\app exporter\bin\Debug\alwin.doc";
  5. try
  6. {
  7.  
  8.  
  9. using (StreamWriter sw = new StreamWriter(path))
  10. {
  11. sw.Write(textBox1.Text);
  12. }
  13.  
  14. using (StreamReader sr = new StreamReader(path))
  15. {
  16. while (sr.Peek() >= 0)
  17. {
  18. Console.WriteLine(textBox1.Text);
  19.  
  20. }
  21. }
  22. }
JunCsharp is offline   Reply With Quote
Old Apr 14th, 2008, 3:11 AM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 929
Rep Power: 4 lectricpharaoh will become famous soon enough
Re: Application to export to an PDF

All you're doing is writing text to a file. Therefore, the resultant file is plain text, no matter what you call it. Changing the extension from .TXT to .PDF doesn't make it into a Portable Document Format file, any more than changing the extension from .TXT to .EXE would make it into a program.

A PDF file is basically a collection of drawing commands (these can draw either graphics or text), and when it's opened, Acrobat Reader or whatever program just reads the file and recreates the 'paper appearance' of it. Without the special formatting codes, software won't recognize it as a valid .PDF file.

If you're set on creating .PDFs, then you have two choices. First, you can write the code yourself, and to do this, you'll need to be familiar with the .PDF specification. You can find it here. If you take this approach I hope you like reading, as the thing is about 1400 pages of technical material. The second, much easier, approach is to use a library designed to output .PDF files, such as iTextSharp.

If all you need to do is output the contents of textboxes while preserving format information, you can use the RichTextBox control. This control has methods for controlling the appearance of text within the control, as well as a SaveFile() method that will allow you to write the text to a file, as a .RTF file. These files can be opened in many word processors, and the format allows for such metadata as fonts and colors.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Apr 14th, 2008, 3:49 AM   #3
JunCsharp
Newbie
 
Join Date: Mar 2008
Posts: 5
Rep Power: 0 JunCsharp is on a distinguished road
Re: Application to export to an PDF

Much apreciated for the post.

My purpose is to make an invoice.

It's an ASP webpage with a computer configurator. When a customer presses on OK after selecting his/her products from the comboboxes, the programm has to make a PDF file with default store lay-out and the textboxes (item, price, quantity...etc) in the right area.


The outcome would be something like

Image was too large, please click
http://www.office-kit.com/excel_invo...ce_printed.gif


Will iTextSharp or a RichTextBox do it?
Im sorry i did not mention it was for ASP.NET
JunCsharp is offline   Reply With Quote
Old Apr 14th, 2008, 5:33 AM   #4
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 929
Rep Power: 4 lectricpharaoh will become famous soon enough
Re: Application to export to an PDF

Quote:
Originally Posted by JunCsharp
Will iTextSharp or a RichTextBox do it?
Im sorry i did not mention it was for ASP.NET
Hmm. You will be able to use iTextSharp without issue, but remember that the document will be generated on the server (of course, you can then serve this to the client). As far as a RichTextBox goes, there's no equivalent for ASP.NET (RichTextBox is a Windows Forms control).

Since it's a web-based application, have you considered simply giving the user HTML output for their report? Since they will be interacting with the app in a browser, they could print or save the content from their browser.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Apr 15th, 2008, 3:01 AM   #5
JunCsharp
Newbie
 
Join Date: Mar 2008
Posts: 5
Rep Power: 0 JunCsharp is on a distinguished road
Re: Application to export to an PDF

Quote:
Originally Posted by lectricpharaoh View Post

Since it's a web-based application, have you considered simply giving the user HTML output for their report? Since they will be interacting with the app in a browser, they could print or save the content from their browser.
Thanks for the reply.

It is possible, but our teacher does not agree on that, because he find it too easy.

It will also leave out competences such as SQL, and ASP (after the user selects OK the lines will be written in a underlying database)

Oh, I don't know hot to use iTextSharp. I have checked the FAQ and some other help recourses.

What I tried is, run 'itextsharp.sln', then Batch build the release. The outcome were 2 files in the Release folder

itextsharp.dll and iTextSharp.xml,

now I don't know what to do with that. Could anyone help me use itextsharp?

Last edited by JunCsharp; Apr 15th, 2008 at 3:21 AM.
JunCsharp is offline   Reply With Quote
Old Apr 15th, 2008, 5:47 AM   #6
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 929
Rep Power: 4 lectricpharaoh will become famous soon enough
Re: Application to export to an PDF

Quote:
Originally Posted by JunCsharp
It is possible, but our teacher does not agree on that, because he find it too easy.
The PDF specification is pretty detailed, and not exactly easy to follow. If your teacher expects you to be able to produce PDF output, then he should be prepared to teach you how. My guess is that he's got some idea that it's a much easier task than it is.
Quote:
Originally Posted by JunCsharp
It will also leave out competences such as SQL, and ASP (after the user selects OK the lines will be written in a underlying database)
Using HTML for report output does not mean you will not be writing code to interact with the database. Remember that a database stores raw data. By itself, this data often isn't very helpful; thus the software needs to put things into context, and present the information in a meaningful way. This is what a report is about.

As an example, imagine the database stores what products are kept in stock (along with a price, description, supplier, etc for each). It also stores records of each transaction (what was sold, when it was sold, etc). By querying the database, the software can assemble a picture of what is going on. It might present a graph that shows sales of a certain type of product, say bicycles, reach their peak in the summer, and barely sell at all during the winter. It could show which stores are the most productive, or which employees make the most sales, dollar-wise. It really depends on the type of report the user wants to see (your software should probably provide several).
Quote:
Originally Posted by JunCsharp
now I don't know what to do with that. Could anyone help me use itextsharp?
First, you will need to have it installed on the server. This may or may not be an issue, depending on your instructor, and school policy. If your instructor won't or can't do this, then forget about iTextSharp.

I personally think the point of your project is to show you can develop a 'data-driven' ASP.NET application, and not that you know how to create .PDF files on the fly. Look at the web site for any company that does business online. You will probably be able to search for products, browse by category, and the like. When viewing a particular product, you'll probably be presented with a description of it (details such as price, brand, what is included, what stores stock it, and so on), as well as a picture of the product. All of this can be stored in the database (though the pictures are often stored as simple files, with a name that matches the product ID), and it's fetched when the user requests it. The HTML the user sees is all generated on-the-fly by the ASP.NET engine.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp
lectricpharaoh is offline   Reply With Quote
Old Apr 15th, 2008, 9:52 AM   #7
mbd
Programmer
 
Join Date: Nov 2007
Posts: 86
Rep Power: 1 mbd is on a distinguished road
Re: Application to export to an PDF

to use itextsharp, take the .dll file from the release folder and add it to your project through the add existing item menu. then from the add references menu, choose the browse tab and browse to the .dll file in your project. that will give you access to al the classes in itextsharp.

Edit: forgot to mention that this method will allow you to Ise itextsharp on the server without actually installing anything there.

Last edited by mbd; Apr 15th, 2008 at 9:58 AM. Reason: forgot to mention something
mbd is offline   Reply With Quote
Old Apr 15th, 2008, 11:16 AM   #8
JunCsharp
Newbie
 
Join Date: Mar 2008
Posts: 5
Rep Power: 0 JunCsharp is on a distinguished road
Re: Application to export to an PDF

thank you a lot for the usefull reply mbd and lectricpharaoh!!!

I will try this out and let you guys know how it went
JunCsharp is offline   Reply With Quote
Old Apr 16th, 2008, 8:19 AM   #9
JunCsharp
Newbie
 
Join Date: Mar 2008
Posts: 5
Rep Power: 0 JunCsharp is on a distinguished road
Re: Application to export to an PDF

Ok I successfully implemented iTextSharp, and Im making improvement, im very exiting about this project .

So if anyone else was interested, I found these toturials to get you going

http://itextsharp.sourceforge.net/tutorial/ch01.html
http://itextsharp.sourceforge.net/examples/Chap0101.cs

thanks again everyone
JunCsharp is offline   Reply With Quote
Old Apr 17th, 2008, 3:53 PM   #10
florence.chen2008
Newbie
 
Join Date: Apr 2008
Posts: 1
Rep Power: 0 florence.chen2008 is on a distinguished road
Re: Application to export to an PDF

Is it possible to create "Contents" and "Bibliography" by using itextsharp? I know latex can automatically create "Contents" and "Bibliography" etc. But, I never see anyone talking about this for itextsharp. I need create a complex pdf financial report with content pages by using C# program.
florence.chen2008 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PC application with bluetooth urip Java 5 Feb 13th, 2008 12:15 PM
application failed to initialize properly 0xc0000005 ronaldr C++ 3 Dec 27th, 2007 8:24 PM
creating an application that stands between the browser and the serve ronias Visual Basic 5 Oct 30th, 2005 4:22 PM
"Not Responding" Message in Windows Form Application G_Zola C# 1 Apr 29th, 2005 10:15 AM
Application opens twice ! hipolito Visual Basic 6 Apr 21st, 2005 11:55 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC