Response.Contenttype For Pdf In Asp
Export Grid. View with Images to Word Excel and PDF Formats in ASP. Net. In one of my previous articles I explained Export Grid. View with Images from database to Word, Excel and PDF Formats. In this article I am explaining how to Export Grid. View to Microsoft Word, Microsoft Excel and Portable Document Format PDF which has images and pictures in it. Here I am exporting a Grid. View which is displaying images stored on disk and the respective paths stored in SQL Server Database. Figure below describes how image paths are stored in the database table. The concept is quite simple whenever the Word or Excel file is transmitted to the client and the client opens it a call is made to the server and the images are downloaded from the server. Hence instead if the relative URL we will have to use the complete URL. So that the images are downloaded from the server. Here I am using the same Grid. View which I used in my article Display Images in Grid. View Control using the path stored in SQL Server database to display images stored on disk in Grid. View. The only exporting I will be changing the URL of the image handler from relative to absolute URL. For example in the previous example the URL was ImagesGarden. Now it will be changed to http localhostImagesGarden. Since Word, Excel or PDF files need complete URL of the image so that they can download the image from the server. For doing this conversion I have the following function. This article, by Scott Mitchell, shows how to programmatically populate PDF form fields using ASP. NET and the free, open source iTextSharp library. LGwwQ-jKz0c/WCA_OjzDwiI/AAAAAAAAAhs/m5frdCwQUX8P542InfMmLX_0y3ZA6DKiwCK4B/s1600/pdf.jpg' alt='Response.Contenttype For Pdf In Asp' title='Response.Contenttype For Pdf In Asp' />Cprotected string Get. Urlstring imagepath string splits Request. Url. Absolute. Uri. This article, by Scott Mitchell, shows how to programmatically create PDF documents using ASP. NET and the free, open source iTextSharp library. This article is about to export an aspx page into Pdf file. In this article Im going to explain how to export HTML table to PDF in ASP. NET. There are many ways we can export HTML Table to PDF document. Here Ill explain. Split if splits. Length 2 string url splits0 for int i 2 i lt splits. Length 1 i url splitsi url return url imagepath return imagepath VB. Net Protected. Function Get. UrlBy. Val imagepath As. String As. String Dim splits As. String Request. Url. Absolute. Uri. Splitc If splits. Laptop Battery Double 1.2 here. Length 2 Then Dim url As. String splits0 For i As. Integer 2 To splits. Length 2 url splitsi url Next Return url imagepath End. If Return imagepath End. Function. And I am calling the function in the Grid. View in the following Manner. As you can see below I am passing the Image File Path to the Get. Url function which in returns the complete URL for the Image. Grid. View. IDGrid. View. Auto. Generate. ColumnsfalseFont NamesArial lt Columns lt asp Bound. Field. Data. FieldIDHeader. TextID Item. Style Height1. Bound. Field. Data. FieldFile. NameHeader. TextImage Name Item. Style Height1. Template. Field Item. Style Height1. Item. Style Width1. Item. Template lt asp Image. IDImage. 1runatserver Image. Urllt EvalFile. Path, Get. Url0 lt Item. Template lt asp Template. Field lt Columns lt asp Grid. View Figure Below displays the Grid. View with Images stored on disk and their relative paths stored in SQL Server Database. When you do View Source of the page in Browser you will notice that the relative URL have been converted to absolute one and the Get. Url function has done its job perfectly. Refer the figure below that displays the Source of the page with the complete URL of the image. Now here is the code to Export the Grid. View in the Word, Excel and PDF Formats. Word. Cprivatevoid WordExport Response. Clear Response. Buffer true Response. Add. Headercontent disposition, attachment filenameGrid. View. Export. doc Response. Charset Response. Content. Type applicationvnd. String. Writer sw new. String. Writer Html. Text. Writer hw new. Html. Text. Writersw Grid. View. 1. Allow. Paging false Grid. View. 1. Data. Bind Grid. View. 1. Render. Controlhw Response. Output. Writesw. To. String Response. Flush Response. End VB. Net. Private. Sub WordExport Response. Clear Response. Buffer True Response. Add. Headercontent disposition, attachment filenameGrid. View. Export. doc Response. Charset Response. Content. Type applicationvnd. Dim sw As. New String. Writer Dim hw As. New Html. Text. Writersw Grid. View. 1. Allow. Paging False Grid. View. 1. Data. Bind Grid. View. 1. Render. Controlhw Response. Output. Writesw. To. String Response. Flush Response. EndEnd. Sub. Figure below displays the Word document which contains exported Grid. View with images. Backyard Baseball 2001 Full Version. Excel. Cprivatevoid ExcelExport Response. Clear Response. Buffer true Response. Add. Headercontent disposition, attachment filenameGrid. View. Export. xls Response. Charset Response. Content. Type applicationvnd. String. Writer sw new. String. Writer Html. Text. Writer hw new. Html. Text. Writersw Grid. View. 1. Allow. Paging false Grid. View. 1. Data. Bind for int i 0 i lt Grid. View. 1. Rows. Count i Grid. View. Row row Grid. View. 1. Rowsi Apply text style to each Row row. Attributes. Addclass, textmode Grid. View. 1. Render. Controlhw style to format numbers to string string style lt style. Response. Writestyle Response. Output. Writesw. To. String Response. Flush Response. End. VB. Net. Private. Sub ExcelExport Response. Clear Response. Buffer True Response. Add. Headercontent disposition, attachment filenameGrid. View. Export. xls Response. Charset Response. Content. Type applicationvnd. Dim sw As. New String. Writer Dim hw As. New Html. Text. Writersw Grid. View. 1. Allow. Paging False Grid. View. 1. Data. Bind For i As. Integer 0 To Grid. View. 1. Rows. Count 1 Dim row As Grid. View. Row Grid. View. Rowsi Apply text style to each Row row. Attributes. Addclass, textmode Next Grid. View. 1. Render. Controlhw style to format numbers to string Dim style As. String lt style. Response. Writestyle Response. Output. Writesw. To. String Response. Flush Response. EndEnd. Sub. Figure below displays the Excel Workbook which contains exported Grid. View with images. Portable Document Format PDF. For exporting the Grid. View to PDF format I am using the i. Text. Sharp Library that will be available with the source code of this example. Also you can download it from here. Cprivatevoid PDFExport Response. Content. Type applicationpdf Response. Add. Headercontent disposition, attachment filenameGrid. View. Export. pdf Response. Cache. Set. CacheabilityHttp. Cacheability. No. Cache String. Writer sw new. String. Writer Html. Text. Writer hw new. Html. Text. Writersw Grid. View. 1. Allow. Paging false Grid. View. 1. Data. Bind Grid. View. 1. Render. Controlhw String. Reader sr new. String. Readersw. To. String Document pdf. Doc new. DocumentPage. Size. A4, 1. 0f, 1. HTMLWorker htmlparser new. HTMLWorkerpdf. Doc Pdf. Writer. Get. Instancepdf. Doc, Response. Output. Stream pdf. Doc. Open htmlparser. Parsesr pdf. Doc. Close Response. Writepdf. Doc Response. End VB. Net. Private. Sub PDFExport Response.