For smart Primates & ROBOTS (oh and ALIENS ).

Thursday, August 14, 2014

Watermark and heading in existing PDF Using itextSharp C#

Watermark and heading in existing PDF Using itextSharp C#

In recently my project of Learning Management System,ICT training programmes,academic software modules and teaching application software/technologies for researchers in the institutions of higher education
in Dot Net, I have faced a problem to Add Watermark and heading in existing PDF Using itextSharp C# at the same time. I have solved this problem. So If you are looking for the solution you can use my code.


  string sourceFile="c://aa.pdf", string outputFile="c://bb.pdf", string watermarkText="Heading Water Mark";
            iTextSharp.text.pdf.PdfReader reader = null;
            iTextSharp.text.pdf.PdfStamper stamper = null;
            iTextSharp.text.pdf.PdfGState gstate = null;
            iTextSharp.text.pdf.PdfContentByte contentByte = null;
            iTextSharp.text.Rectangle rect = null;
            int pageCount = 0;
            BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
            iTextSharp.text.Font black = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.UNDEFINED, 30f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.GRAY);
            float fontSize = 50, xPosition = 300, yPosition = 400, angle = 55;
            try
            {
                reader = new iTextSharp.text.pdf.PdfReader(sourceFile);
                rect = reader.GetPageSizeWithRotation(1);
                stamper = new iTextSharp.text.pdf.PdfStamper(reader, new System.IO.FileStream(outputFile, System.IO.FileMode.Create));
                gstate = new iTextSharp.text.pdf.PdfGState();
                pageCount = reader.NumberOfPages;
                for (int i = 1; i <= pageCount; i++)
                {
                    contentByte = stamper.GetOverContent(i);
                    contentByte.SaveState();
                    contentByte.SetGState(gstate);
                    if (i == 1)
                    {
                        PdfPTable table = new PdfPTable(1);
                        float[] widths = new float[] { 500f };
                        table.SetWidths(widths);
                        table.TotalWidth = 600f;
                        table.LockedWidth = true;
                        Chunk chk_subject = new Chunk("My Heading Text", black);
                        Phrase ph_subject = new Phrase();
                        ph_subject.Add(chk_subject);
                        PdfPCell cell = new PdfPCell(ph_subject);
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
                        cell.BorderWidthLeft = 1f;
                        cell.BorderWidthRight = 1f;
                        cell.BorderWidthTop = 1f;
                        cell.BorderWidthBottom = 1f;
                        cell.BorderColor = BaseColor.WHITE;
                        table.AddCell(cell);
                        table.WriteSelectedRows(0, -1, 0, 690, stamper.GetOverContent(1));
                    }
                    gstate.FillOpacity = (float)0.3;
                    gstate.StrokeOpacity = (float)0.3;
                    contentByte.SetGState(gstate);
                    contentByte.BeginText();
                    contentByte.SetColorFill(BaseColor.LIGHT_GRAY);
                    contentByte.SetFontAndSize(baseFont, fontSize);
                    contentByte.SetTextMatrix(30, 30);
                    contentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER, watermarkText, xPosition, yPosition, angle);
                    contentByte.EndText();
                }
                stamper.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            MessageBox.Show("Done");

Share:

Saturday, July 19, 2014

Post Xml data without form in JSP and receive

How to post xml data in JSP page without form field and get it's data
in the next JSP page.

The first file post-data.jsp is just taking xml data form xml file and
sending xml data as a post to the get-post.jsp page.

first file is:

post-data.jsp
--------------
< %@ page import="java.net.*" % >
< %@ page import="java.io.*" % >
< %@ page import="java.util.*" % >
< %@ page import="java.text.*" % >
< %
try
{
URL u;
u = new URL("http://localhost:9292/post/get-post.jsp");
// get the xml data from xml file which you want to post
String inputFileName="C:\\temp1.xml";
FileReader filereader =new FileReader(inputFileName);
BufferedReader bufferedreader=new BufferedReader(filereader);
String initial=bufferedreader.readLine();
String finalData=new String();
while(initial!=null)
{
finalData=finalData+initial;
initial=bufferedreader.readLine();
}
String s=(finalData.toString());
HttpURLConnection uc = (HttpURLConnection)u.openConnection();
uc.setRequestMethod("POST");
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
uc.setAllowUserInteraction(false);
DataOutputStream dstream = new DataOutputStream(uc.getOutputStream());
dstream.writeBytes(s);
dstream.close();
InputStream in = uc.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(in));
StringBuffer buf = new StringBuffer();
String line;
while ((line = r.readLine())!=null) {
buf.append(line);
}
in.close();
out.println(buf.toString());
}
catch (IOException e)
{
out.println(e.toString());
}
% >


Second file is:

get-post.jsp
-----------------

< %@ page import="java.util.*" % >
< %
String postedData = request.getReader().readLine();
///// perform here your operation for postedData
out.println("Posted Data is ");
out.println(postedData);
% > 
Share:

Friday, July 11, 2014

Add html tag dynamically in html

Add html tag dynamically in html

<script src="jquery-2.1.1.js" language="javascript" type="application/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var ID = 1;
        function addRow() {
            var html =  '<tr>' +
                        '<td>Name: <input type="text" name="aa' + ID + '" /></td>' +
                        '<td>File: <input type="file" name="fileUpload' + ID + '" /></td>' +
                        '<td><input type="button" class="BtnPlus" value="+" /></td>' +
                        '<td><input type="button" class="BtnMinus" value="-" /></td>' +
                        '</tr>'
            $(html).appendTo($("#Table1"))
            ID++;
        };
        $("#Table1").on("click", ".BtnPlus", addRow);
        function deleteRow() {
            if(ID==1) return;
            var par = $(this).parent().parent();
            par.remove();
            ID--;
        };
        $("#Table1").on("click", ".BtnMinus", deleteRow);
    });
</script>
<table id="Table1" cellspacing="3">
    <tr>
        <td>Name: <input type="text" name="aa0"  id="aa0" /></td>
        <td>File: <input type="file" name="fileUpload0"/></td>
        <td><input type="button" class="BtnPlus" value="+" /></td>
        <td><input type="button" class="BtnMinus" value="-" /></td>
    </tr>
</table>
Share:

Display content with delay in jquery

Display content with delay in jquery

Some time you want to show some data with delay, then use the listed below code:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Display content with delay</title>
<style>
.my-class {
    display: none;
}
</style>
<script language="javascript" src="jquery-1.10.2.js" type="text/javascript"></script>
</head>
<body>
<div class="my-class">
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
</div>
</body>
<script>
$(document).ready(function() {
$('.my-class').delay(1000).fadeIn(3500);
});
</script>
</html>
Share:

Fieldset in html

Fieldset example in html
----------------------------
Fieldset is very useful to combine the more than one information which you want to show or
feed data entry. actually it will block the more than one columns (all colums will be shown in one
box with header heading).

<fieldset style="text-align:right; width:300px;" accesskey="c">
<legend><b>Address Details</b></legend>
Name <input type="text" size="50" /><br>
Address <input type="text" /><br>
City <input type="text" /><br>
State <input type="text" />
</fieldset>
Share:

Tuesday, July 08, 2014

Sum datagridview cell by button click c#

If you have enter many records in datagridview in c# winform and want to show the sum of any cell values for example: "mark" cell, then you needed to retrieve each datagridview row and add it's value in other variable.... but we want to do this not using iteration.. thwn what we will do?

Use listed below code to achieve target:

---------------------------------------------------------------------------------------------------
string m = "Total Marks =" + dataGridView1.Rows.Cast<DataGridViewRow>().AsEnumerable()                                                    .Sum(x => int.Parse(x.Cells["mark"].Value.ToString())).ToString();
---------------------------------------------------------------------------------------------------


Share:

Sort Datagridview column by button click c#

Sort Datagridview column by button click c#

If you have added the random records in your Datagridview C# winform and want to show records by any column on button click then use this:

-------------------------------------------------------------------------------------
dataGridView1.Sort(dataGridView1.Columns[1], ListSortDirection.Ascending);
-------------------------------------------------------------------------------------
OR
-------------------------------------------------------------------------------------
dataGridView1.Sort(dataGridView1.Columns["mark"], ListSortDirection.Ascending);
-------------------------------------------------------------------------------------

"mark" is the cell name in the datagridview.


Share:

Saturday, July 05, 2014

Image rotate in jQuery

Image rotate in jQuery


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<img style="transform: rotate(285.4deg);" id="myimg"  src="WOW.jpg">
<script type="text/javascript">
    jQuery(function($) {
        $(document).ready(function() {
            window.imagerotate = function () {
                $('#myimg').rotate({
                                angle:0,
                                animateTo:-360,
                                callback: imagerotate,
                                //t: current time,b: beginning value,c: change in value,d: duration
                                easing: function (x,t,b,c,d) {
                                    return c*(t/d)+b+10000;
                                }
                            });
                        };
                        setTimeout('imagerotate()', 1000);
                });
});
</script>
</body></html>          
Share:

Send Files to IP address in C#

If there are you situation you want to send file to IP address,
then use listed below code:

string sourceDir = @"C:\\tt";
string destIP = @"\\10.10.10.10\shared-folder-amit";
string[] sourceFiles = Directory.GetFiles(sourceDir, "*", SearchOption.AllDirectories);
foreach (string files in sourceFiles) {
  string localFile = files.Replace(sourceDir, "");
  if (!Directory.Exists(Path.GetDirectoryName(destIP + "\\" + localFile)))
    Directory.CreateDirectory(Path.GetDirectoryName(destIP + "\\" + localFile));
  File.Copy(files, destIP + "\\" + localFile, true);
}



Share:

CodeIgniter Undefined property CI_Loader $session codeigniter error

Problem:

If you works in CodeIgniter and play with session then you can get this error message :
Undefined property: CI_Loader::$session

CodeIgniter Undefined property CI_Loader $session codeigniter error

A PHP Error was encountered CodeIgniter
CodeIgniter error

 Severity: Notice
Message: Undefined property: CI_Loader::$session

Solution:

It means that you have not loaded session library in it controller's index or constructor as
$this->load->library('session'); 

Example:

To prevent this error message use listed below code:

public function index() {
        $this->load->library('session');
}
Share:

Ads Inside Post

Powered by Blogger.

Archive