Click here to Skip to main content
15,909,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Public Sub ExportGridToExcel(ByRef grdGridView As GridView, ByVal fileName As String)
Response.Clear()
Response.AddHeader("content-disposition", String.Format("attachment;filename={0}.xls", fileName))
Response.Charset = ""
Response.ContentType = "application/vnd.xls"
Dim strWr As New StringWriter()
Dim HtmlWr As New HtmlTextWriter(strWr)
grdGridView.RenderControl(HtmlWr)
Response.Write(strWr.ToString)
Response.End()
End Sub

please tell me how i can convert in pdf format
Posted
Updated 27-Aug-11 22:48pm
v2
Comments
Member 14779870 9-Nov-20 8:23am    
I have a windows app in VB Net 2019 that has a report that I wish to save as a PDF file. I setup the report in a group box for the ease of printing, that works will. But It is a must to Save the file to be able to use without the program. A pdf file is the best way bur I cannot get the group box is convert to pdf. I used PDF Sharp to save the form, but the screen shot does not show the full group box and save the complete screen. I need to just save the Group box and all that is inside it, the page is 8 X 10. Can someone help.

Hai here is an example to create a pdf file using itextsharp.dll in vb.net
Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("D:\Temporary\sample.pdf", FileMode.Create))
doc.Open()


Dim para As New Paragraph("This is my first paragraph")
Dim pharse As New Phrase("This is my first phrase")
Dim chunk_ As New Chunk("This is my first chunk")

doc.Add(para)
doc.Add(pharse)
doc.Add(chunk_)

doc.Close()
 
Share this answer
 
Comments
irfanansari 29-Aug-11 1:53am    
Sir Please Tell Me That I Have To Reference With Dll File And Then Imports Some Thing With those above Code?
Download the Dll iTextSharp
from http://www.codeproject.com/KB/cs/iTextSharpPdfTables/iTextSharpPdfTables.zip
and then connect your application resource.
 
Share this answer
 
Comments
irfanansari 30-Aug-11 3:02am    
Thanks A Lot Sir Can You Give Me Your Emails Address Please
irfanansari 3-Sep-11 15:25pm    
this is Error come when i use on localhost its work on visual studio but ion on localhost it seems just for There is no Write Purmission so tell me how i will use that in my Domain
Server Error in '/' Application.
--------------------------------------------------------------------------------

Access to the path 'C:\sample.pdf' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\sample.pdf' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true">, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[UnauthorizedAccessException: Access to the path 'C:\sample.pdf' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +651
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1038
System.IO.FileStream..ctor(String path, FileMode mode) +64
CONTACT.ImageButton1_Click(Object sender, ImageClickEventArgs e) +81
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
You would need to pass it through an Excel to PDF converter: Google[^] can help
 
Share this answer
 
Comments
irfanansari 28-Aug-11 4:50am    
But I need directly use code convert in PDF not any other converter
OriginalGriff 28-Aug-11 4:52am    
Sorry? I don't understand your response.
irfanansari 28-Aug-11 5:12am    
Sir i Mean Please help me
Save file in PDF please
OriginalGriff 28-Aug-11 5:16am    
Then add "VB" to the google search I gave you - you will find lots of different ways...
irfanansari 28-Aug-11 5:24am    
Sir You Do Know About it
So tell me please
Apparently, you need to be able to read Excel data and write PDF.

To work with Excel, use Microsoft.Office.Interop.Excel. See some code samples:
http://stackoverflow.com/questions/657131/how-to-read-data-of-an-excel-file-using-c[^],
http://www.google.com/search?hl=en&source=hp&q=site%3ACodeProject.com+SAKryukov&aq=f&aqi=&aql=&oq=[
target="_blank" title="New Window">^
].

You will find a lot more if you need to.
See also http://msdn.microsoft.com/en-us/library/aa168292%28v=office.11%29.aspx[^].

To work with PDF, I would recommend iText Open Source library. See:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^].

It has a .NET port called iTextSharp: http://sourceforge.net/projects/itextsharp/[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900