I was working on a project and have been asked to convert the webpage into a pdf document. I have found a solution in a forum, but it was in c#, I have converted it in VB.net. See below method to convert a webpage into a PDF document.
First, you need to download iTextSharp. iTextSharp is a port of the iText open source java library which allows you to generate PDF files on the fly.
Once you downloaded the library, you need to reference it in your project. To reference the downloaded the library, follow the below steps:
From the Website menu, select “Add Reference”, then you will be prompted with the add reference dialog
Click on the browse button to locate your iTextSharp library (itextsharp.dll)
once you have done that, you should see a reference to your class library in Solution Explorer window.
Now, Add the below code in your project.
pdf.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pdf.aspx.vb" Inherits="Pdf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:PlaceHolder ID="PlaceholderPdf" runat="server"></asp:PlaceHolder>
<div>
<table border="1">
<tr>
<td colspan="2">
This is a test document, credit goes to srinivaskotra
</td></tr><tr><td>cell1
</td><td>cell2</td></tr>
<tr><td colspan=”2″>
<asp:Label ID=”lblLabel” runat=”server” Text=”Label Test”></asp:Label>
</td></tr></table></div>
</form>
</body>
</html>
pdf.aspx.vb
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
Imports System.Text.RegularExpressions
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html
Imports iTextSharp.text.xml
Imports System.Xml
Imports iTextSharp.text.html.simpleparser
Public Partial Class Pdf
Inherits System.Web.UI.Page
Protected Overloads Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim mem As New MemoryStream()
Dim twr As New StreamWriter(mem)
Dim myWriter As New HtmlTextWriter(twr)
MyBase.Render(myWriter)
myWriter.Flush()
myWriter.Dispose()
Dim strmRdr As New StreamReader(mem)
strmRdr.BaseStream.Position = 0
Dim pageContent As String = strmRdr.ReadToEnd()
strmRdr.Dispose()
mem.Dispose()
writer.Write(pageContent)
'---------------------------------------------------
CreatePDFDocument(pageContent)
End Sub
Public Sub CreatePDFDocument(ByVal strHtml As String)
'---------------------------------------------------
Dim strFileName As String = HttpContext.Current.Server.MapPath("test.pdf")
' step 1: creation of a document-object
Dim document As New Document()
' step 2:
' we create a writer that listens to the document
PdfWriter.GetInstance(document, New FileStream(strFileName, FileMode.Create))
Dim se As New StringReader(strHtml)
Dim obj As New HTMLWorker(document)
document.Open()
obj.Parse(se)
document.Close()
'---------------------------------------------------
ShowPdf(strFileName)
End Sub
Public Sub ShowPdf(ByVal strFileName As String)
Response.ClearContent()
Response.ClearHeaders()
Response.AddHeader("Content-Disposition", "inline;filename=" & strFileName)
Response.ContentType = "application/pdf"
Response.WriteFile(strFileName)
Response.Flush()
Response.Clear()
End Sub
End Class
That’s it. Now when you run the program, you will see the pdf file instead opening the webpage.
Windows Management Instrumentation (WMI) is a set of extensions to the Windows Driver Model that provides an operating system interface through which instrumented components can provide information and notification. WMI is Microsoft’s implementation of the Web-Based Enterprise Management (WBEM) Standard from the Distributed Management Task Force (DMTF).
WMI allows scripting languages like VBScript to manage Microsoft Windows personal computers and servers, both locally and remotely. WMI is preinstalled in Windows Server 2003, Windows XP, Windows Me, and Windows 2000.
Microsoft also provides a command line interface to WMI called Windows Management Instrumentation Command-line (WMIC).
Some usefull commands when using WMIC:
wmic process [pid] delete
The rough equivalent (for you UNIX/Linux minded folks) of “kill -9 [pid]“
wmic process where name='cmd.exe' delete
It functions something like “killall -9 cmd.exe” would on a Linux box, where killall lets you kill processes by name.
wmic process list brief /every:1
Sort of like (but not exactly) the Linux/UNIX top command.
wmic useraccount
This one gives a lot more detail than the old “net user” command. With “wmic useraccount” you get user
names, SIDs, and various security settings.
wmic qfe
This one shows all hotfixes and service packs. QFE stands for Quick Fix Engineering.
wmic startup list full
This shows a whole bunch of stuff useful in malware analysis, including all files loaded at Startup and the
reg keys associated with autostart.
wmic process list brief | find "cmd.exe"
That works a little like a Linux “ps -aux | grep cmd.exe”.
wmic /record:test.xml process list brief
You can use the /record option in WMIC to record the WMIC commands you typed, their output, and a timestamp.
After the command runs, your results are stored in xml format. That’s the only format supported, but this
is a handy record of what you typed, when you typed it, and the results you got. The only down side, though,
is that it will overwrite a previous test.xml, rather than append to it. Still, not bad, as long as you make
sure to use different names for your record files.
Network interface configuration options offered by WMIC:
wmic nicconfig where IPEnabled='true'
That’ll give you a list of IP interfaces.
wmic nicconfig where Index=1 call EnableStatic ("10.10.10.10"), ("255.255.255.0")
To change the IP address at the command line
wmic nicconfig where Index=1 call EnableDHCP
Do this for DHCP, where the index is the number of the interface you get from that first nicconfig
command I put in this update.
1. Telnet into Exchange server hosting IMS service using TCP port 25. Command is telnet <servername> 25
2. Turn on local echo on your telnet client so that you can see what you are typing. On Win 9x and NT 3.5/4.0 Telnet client this done by selecting the “preferences” from the “terminal” pull down menu, and checking the local echo radio button. For Windows 2000 telnet client, issue command “set local_echo”, from the telnet command prompt.
3. Issue the following smtp command sequence
helo <your domain name><enter>
response should be as follows
250 OK
mail from: <your Email Address><enter> response should be as follows
250 OK - mail from <your Email address>
rcpt to: <recipient address><enter> response should be as follows
250 OK - Recipient <recipient address>
data<enter> response should be as follows
354 Send data. End with CRLF.CRLF
To: <recipient’s display name><enter>
From: <your display name><enter>
Subject: <Subject field of Email message><enter>
<Enter you body text><enter><enter> . <enter> response should be as follows
250 OK
My friend used to borrow my memory stick and I thought to trick him for fun. I created a fake folder (actually its just a file with 3 lines of code) called “my secrets” and saved on my memory stick. When returning back the memory stick he asked me “hey! how did you lock the folder?”, and I asked him to visit my website. :p
So, Do you also want to fool or test your mates? Follow the steps below:
Open notepad (Click start > Run > type Notepad.exe)
Copy the following code to Notepad [Shell]
Command=2
IconFile=explorer.exe,3
Save the file as “my secrets.scf” (with quotes, this is to prevent Notepad from appending .txt extension)
Simply copy and paste the following code into the root htaccess file of your site to enjoy a serious reduction in wasted bandwidth, stolen resources, and comment spam.
If you want to create a table without using your mouse and menus; try the following:
- Open MS Word - Type, +—–+—–+——+——-+ - Press Enter
You will see a table with 4 cells. You can create as many cells you want. for each cell type +——+ . Also if you want to make different size of cells you could try; +—–+———–+—–+—————+