Jump to content

How to print with .net ?


aic007

Recommended Posts

Hi.I did a bit of googling, but could not find what I was looking for. I was wondering if somebody could help me with some examples of customized printing ? Is it possible at all ? Can I take input from textboxes and then put it in my own pdf document for instance and then print it out ?

Link to comment
Share on other sites

If you are talking about ASP.NET (i.e. web-based) then printing is a client-side function that happens in the browser; the only thing you'd be able to do in ASP.NET is to send the following javascript to run on the client-side:

<script type="text/javascript">window.print();</script>

Generating a PDF, however, isn't a bad idea. You could generate the PDF and send it to the user for downloading. For more info on generating PDFs, check Google: http://www.google.com/search?q=asp.net+pdf+generator

Link to comment
Share on other sites

place the dll file in your projects bin folder. Then in vs right click on references from the solution explorer and choose Add. Browse to your bin folder and select the dll. It should now be in your selection list. Press OK.Then at the top of every page you want to se it on you use this statement (C#)using dllNamespace; //replace with correct namespace[.sub namespace] declarations.

Link to comment
Share on other sites

It's not that I'am lazy or something like that, but I have googled alot and studied alot without being able to understand what to do in order to generate a pdf file that contains information that user has typed in a .aspx form. If someone could help me a bit with a good and detailed example I would be very thankful.

Link to comment
Share on other sites

Im back again with stupid questions :) I use this code;

  protected void Button1_Click(object sender, EventArgs e)    {        Console.WriteLine("Chapter 1 example 1: Hello World");        // step 1: creation of a document-object        Document document = new Document();        try        {            // step 2:            // we create a writer that listens to the document            // and directs a PDF-stream to a file            PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));            // step 3: we open the document            document.Open();            // step 4: we Add a paragraph to the document            document.Add(new Paragraph("Hello World"));        }        catch (DocumentException de)        {            Console.Error.WriteLine(de.Message);        }        catch (IOException ioe)        {            Console.Error.WriteLine(ioe.Message);        }        // step 5: we close the document        document.Close();    }

and when I click on the button, nothing happens.. It is supposed to generate a pdf file, but nothing happens. Any1 have any idea what I am doing wrong ?I am using code from this site;http://itextsharp.sourceforge.net/tutorial/ch01.htmlplz help me

Link to comment
Share on other sites

try using only one catch statement and use a regualr Exception and use Console.Write to output the error. That way you can see the true compiler error not the custom error that somebody made up.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...