Florence Blogspot about asp.net tutorials and web design and web development

Sunday, November 23, 2008

Generating pdf report using asp.net

PDF analysis by Florence.D



I have found some free components for generating pdf report using asp.net

iTextSharp.dll

ghtml2Pdf.exe

PDFSharp.dll

ApacheFop.net.dll

But I found some difficulty in the above components :

iTextSharp.dll:

In iTextSharp,

we can use 2 methods here

By passing the whole html script as string

by create a table in the code behind.

Our requirement is to generate the 1000 lines of html script into pdf.

So it is high risk to pass the 1000 lines of html script into string and also in the code behind it is not possible to create a each table in the code behind because every time the script generated may vary..
Only we can create a simple pdf not complex html scripts.

We cannot write the 1000 lines of html script into iTextSharp.dll.

ghtml2Pdf.exe:
Here we are using the exe component to generate the pdf file by passing the html file.
We have to generate the html file first and then pass that file into ghtml2Pdf.exe.
It is high riskable in the dotnet framework. Morever the we cannot use this in our whole servers.
It has the rights to work in only limited number of computers.

PDFSharp.dll

Here again we cannot use the html scripts to generate the pdf.
We have to create our own design in the codebehind. Again the same problem that every time the design or the html script may vary according to the report generated.
ApacheFop.net.dll
This is the good method to generate the pdf in dotnet using java classes.
Also we need vjslib.dll to work with the Java classess.
The process is some wat critical.
First we have to create a xml file to store the datas needed.
Then we have to create a design pattern like stylesheet using xsl.
After creating the xml and xsl, we have to transform these two and need to generate the fo file ie Formatted object file.
After the fo file created , we can generate the pdf from the fo file.
This is the structure.
But this requires some amount of time.
Using Java:
http://www.javaworld.com/javaworld/jw-04-2006/jw-0410-html.html
Here is the link where I read article for generating pdf using java.
It is a difficult process same as the above one.
Conclusion.

I have found lot of premium shareware components to generate the pdf from html.

It average costs from 600 to 1000 $.
The best is
www.winnovative-software.com
http://www.winnovative-software.com/Buy.aspx#redistributable
cost for redistributable pacakage is

INR 33938.41

Some other premium components
http://www.html-to-pdf.net/Pricing.aspx

Hope all got some knowledge anyone who started creating pdf.

Exporting WebPage to Excel using Javascript.

Refered from : Javascript

Export2Excelinjavascript

Monday, August 11, 2008

Yahoo contacts!!! import class in C#

I tried to find free Yahoo! Contact import code for .NET platform. I found only paid packages for 300+$.


I've implemented importing and you can use it for free.
(But you need to make some change in code to compile it)




using System;

using System.Collections.Specialized;

using System.Net;

using System.Text;

using System.Text.RegularExpressions;



namespace Gnilly.Syndication.Mail

{

public class YahooExtract

{

private const string _addressBookUrl = "http://address.yahoo.com/yab/us/Yahoo_ab.csv?loc=us&.rand=1671497644&A=H&Yahoo_ab.csv";

private const string _authUrl = "https://login.yahoo.com/config/login?"; private const string _loginPage = "https://login.yahoo.com/config/login";

private const string _userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";





public bool Extract( NetworkCredential credential, out MailContactList list )

{

bool result = false;





list = new MailContactList();





try

{

WebClient webClient = new WebClient(); webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent; webClient.Encoding = Encoding.UTF8;





byte[] firstResponse = webClient.DownloadData( _loginPage );

string firstRes = Encoding.UTF8.GetString( firstResponse );



NameValueCollection postToLogin = new NameValueCollection();

Regex regex = new Regex( "type=\"hidden\" name=\"(.*?)\" value=\"(.*?)\"", RegexOptions.IgnoreCase );

Match match = regex.Match( firstRes );

while ( match.Success )

{

if ( match.Groups[ 0 ].Value.Length > 0 )

{

postToLogin.Add( match.Groups[ 1 ].Value, match.Groups[ 2 ].Value );

}

match = regex.Match( firstRes, match.Index + match.Length );

}





postToLogin.Add( ".save", "Sign In" );

postToLogin.Add( ".persistent", "y" );





string login = credential.UserName.Split( '@' )[ 0 ];

postToLogin.Add( "login", login );

postToLogin.Add( "passwd", credential.Password );





webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;

webClient.Headers[ HttpRequestHeader.Referer ] = _loginPage;

webClient.Encoding = Encoding.UTF8;

webClient.Headers[ HttpRequestHeader.Cookie ] = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];



webClient.UploadValues( _authUrl, postToLogin );

string cookie = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];





if ( string.IsNullOrEmpty( cookie ) )

{

return false;

}





string newCookie = string.Empty;

string[] tmp1 = cookie.Split( ',' );

foreach ( string var in tmp1 )

{

string[] tmp2 = var.Split( ';' );

newCookie = String.IsNullOrEmpty( newCookie ) ? tmp2[ 0 ] : newCookie + ";" + tmp2[ 0 ];

}





// set login cookie

webClient.Headers[ HttpRequestHeader.Cookie ] = newCookie;

byte[] thirdResponse = webClient.DownloadData( _addressBookUrl );

string thirdRes = Encoding.UTF8.GetString( thirdResponse );





string crumb = string.Empty;

Regex regexCrumb = new Regex( "type=\"hidden\" name=\"file://.crumb/" id=\"crumb1\" value=\"(.*?)\"", RegexOptions.IgnoreCase );

match = regexCrumb.Match( thirdRes );

if ( match.Success && match.Groups[ 0 ].Value.Length >) )

{

crumb = match.Groups[ 1 ].Value;

}





NameValueCollection postDataAB = new NameValueCollection();

postDataAB.Add( ".crumb", crumb );

postDataAB.Add( "vcp", "import_export" );

postDataAB.Add( "submit[action_export_yahoo]", "Export Now" );





webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;

webClient.Headers[ HttpRequestHeader.Referer ] = _addressBookUrl;



byte[] FourResponse = webClient.UploadValues( _addressBookUrl, postDataAB );

string csvData = Encoding.UTF8.GetString( FourResponse );



string[] lines = csvData.Split( '\n' ); foreach ( string line in lines )

{

string[] items = line.Split( ',' );

if ( items.Length < 5 )

{ continue;

}

string email = items[ 4 ];

string name = items[ 3 ];

if ( !string.IsNullOrEmpty( email ) && !string.IsNullOrEmpty( name ) )

{

email = email.Trim( '\"' );

name = name.Trim( '\"' );

if ( !email.Equals( "Email" ) && !name.Equals( "Nickname" ) )

{

MailContact mailContact = new MailContact();

mailContact.Name = name;

mailContact.Email = email;

list.Add( mailContact );



}

}

}





result = true;

}

catch

{

}

return result;

}

}

}

Sunday, July 27, 2008

Adding google MAP into your .NET website in just 15 minutes


Adding GOOGLE MAP into your .NET website in just 15 minutes by Florence

Ever wanted to add a Google Map to your site but only had 15 minutes to spare? Now you can add a map and still have time to brag to your mates and bask in the worship that (inevitably) comes afterward. Basically, the guys over at subgurim.net have already done all the hard work in writing the .Net wrapper for Google Maps. Problem is, the examples on their site are mostly in spanish & its a bit difficult to find out exactly what is needed to get everything working. But all this is cutting into your bragging time - so lets get started!

1. Get a Google Maps API key from here:http://www.google.com/apis/maps/

2. Download the SubGurim wrapper dll from here:http://en.googlemaps.subgurim.net/descargar.aspx

3. Unzip it, and put it in your \bin directory

4. Add it to your toolbox byTools -> Choose Toolbox Items -> Browse -> Select the .dll file -> OKGMap will now be in the ‘Standard’ area of your Toolbox.

5. Add a new webpage. 6. Drag the GMap from the toolbox onto the page. A new instance of the GMap will appear on the page, with the name ‘GMap1′

7. Add the following lines to your web.config file: appsettings add value="YourGoogleMapsAPIKeyHere" key="googlemaps.subgurim.net" appsettings 8. Add the following code to your Page.Load sub
Dim sStreetAddress As String Dim sMapKey As String = ConfigurationManager.AppSettings("googlemaps.subgurim.net") Dim GeoCode As Subgurim.Controles.GeoCode sStreetAddress = "100 Russell St. Melbourne. VIC. 3000. Australia" GeoCode = GMap1.geoCodeRequest(sStreetAddress, sMapKey) Dim gLatLng As New Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng) GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal) Dim oMarker As New Subgurim.Controles.GMarker(gLatLng) GMap1.addGMarker(oMarker)
Press F5, and start basking in the glory!

Search