Create PDF (for printing outgoing documents)

Last post 05-26-2007 9:36 PM by jasonjanofsky. 2 replies.

Sort Posts:

  • Create PDF (for printing outgoing documents)

    05-26-2007, 7:42 AM
    • Member
      60 point Member
    • DevFox
    • Member since 08-24-2006, 8:00 AM
    • Posts 15

    Hi,

    I have a task of generating and printing an outgoing document (with the company letterhead). The address, subject, text fields etc. are all saved in a database. I tried doing this using plain HTML but it is almost impossible to get the whole thing fit in and print an A4 size document.

    I guess PDF is one option here. Can anyone guide me in this matter. Should I use any third-party component?

     Here is the summary of what I want to do:

    1. Add a header, footer and a side image (background perhaps).

    2. Adjust the borders.

    3. Write text which does not overlap the images.

    Thanks in advance.    //  I am using C# ; Smile

    DevFox 

     

     

     

  • Re: Create PDF (for printing outgoing documents)

    05-26-2007, 3:22 PM
    • All-Star
      62,660 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 8:34 AM
    • England
    • Posts 12,228
    • TrustedFriends-MVPs

    Which version of SQL Server do you have? Both SQL 2000 (via an add-on) and SQL2005 by an install option  have reporting services. Reporting service can produce a document and export it as a PDF.

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Create PDF (for printing outgoing documents)

    05-26-2007, 9:36 PM
    Answer
    • Member
      618 point Member
    • jasonjanofsky
    • Member since 03-19-2004, 2:57 PM
    • San Diego
    • Posts 140

    Bah, you dont need reporting services or anything like this.  Asp.net supports PDF printing natively, the only caveat is that, I believe you need to have the full Visual Studio.  Once you have created your report within visual studio you will be all set.  There are two way to output the file, one is with the report viewer control (this option sucks) and the second option is to render the pdf right to the response object. 

    Private Sub RenderReport(ByVal ReportPath As String, ByVal OutFile As String)Dim localreport As LocalReport = New LocalReport   'page must import Microsoft.Reporting.WebForms

    localreport.ReportPath = ReportPath 'I pass this in the sub args, but you can hardcode

    Dim abll As New BLL.MydataObject 'You need to get data for your report

    Dim ag As MyTyedDataTable = abll.GetDataByID(ID) 'A simple single record queryDim rds As ReportDataSource = New ReportDataSource("Data_Datatable", ag) 'creating the data source, you can find the name reference in the report -->data sources menu in VS

    localreport.DataSources.Add(rds)

    Dim reportType As String = "PDF"

    Dim mimeType As String = Nothing

    Dim encoding As String = Nothing

    Dim fileNameExtension As String = Nothing

    Dim DeviceInfo As String = _

    "<DeviceInfo>" & _

    " <OutputFormat>PDF</OutputFormat>" & _

    " <PageWidth>8.5in</PageWidth>" & _

    " <PageHeight>11in</PageHeight>" & _

    " <MarginTop>0.5in</MarginTop>" & _

    " <MarginLeft>1in</MarginLeft>" & _

    " <MarginRight>1in</MarginRight>" & _

    " <MarginBottom>0.5in</MarginBottom>" & _

    "</DeviceInfo>"

    Dim warnings As Warning() = Nothing

    Dim renderedBytes As Byte() = Nothing

    Dim streams As String() = Nothing

    renderedBytes = localreport.Render(reportType, DeviceInfo, mimeType, encoding, fileNameExtension, streams, warnings)

    Response.Clear()

    Response.ContentType = mimeType

    Response.AddHeader(
    "content-disposition", "attachment; filename=" & OutFile & "." + fileNameExtension) 'you can hardcode this as well for the output file name

    Response.BinaryWrite(renderedBytes)

    Response.End()

    End Sub

     

    Good luck!!

    Feel free to hit me on MSN, I will try to help if I am not super busy.
Page 1 of 1 (3 items)