How to create a dotted line in iTextSharp PDF table cell.

First, you will need to create a new class that will handle the PDF PCell events of CellLayout:

 // Cell Event to make dotted Line
    class dot : IPdfPCellEvent {

        public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
             cell.Border = Rectangle.TOP_BORDER;
            PdfContentByte cb = canvases[PdfPTable.LINECANVAS];
            cb.SetLineDash(3f, 3f);
            cb.Rectangle(position.Left, position.Bottom, position.Width, position.Height);

With a cell event, a border is drawn around every cell. This means you’ll have multiple stroke() operators and overlapping lines.

The most elegant way to draw the cell borders, as it uses only one stroke() operator for all the lines. This isn’t an option if you have tables with rowspans (but you probably don’t care about rowspans, because you’re using an obsolete version of iText that didn’t support rowspans).

 class DottedCells : IPdfPTableEvent {

    public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases)
        PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
        canvas.SetLineDash(3f, 3f);
        float llx = widths[0][0];
        float urx = widths[0][widths[0].Length - 1];
        for (int i = 0; i < heights.Length; i++)
            canvas.MoveTo(llx, heights[i]);
            canvas.LineTo(urx, heights[i]);
        for (int i = 0; i < widths.Length; i++)
            for (int j = 0; j < widths[i].Length; j++)
                canvas.MoveTo(widths[i][j], heights[i]);
                canvas.LineTo(widths[i][j], heights[i + 1]);

How to call the code:

                PdfPTable t1 = new PdfPTable(1); t1.WidthPercentage = 100f;
                //add dotted line underneath
                PdfPCell cell2 = new PdfPCell();
                dot evt = new dot();
                cell2.CellEvent = evt;
                cell2.Border = Rectangle.NO_BORDER;
                cell2.Colspan = 2;
                pB = new Paragraph(3f, " ", times);

How to trim leading zeroes in a column/string in SQL

If you have been using this:

SUBSTRING(str_col, PATINDEX('%[^0]%', str_col), LEN(str_col))

to get your zeroes removed from a string, you might be interested in a variation that only removes the leading zeroes. The T-SQL Function has been created to be called from either Stored Procedure code or Triggers.

--print dbo.ufn_TrimLeadingZeros ('0100 ATN652')
ALTER FUNCTION [dbo].[ufn_TrimLeadingZeros] ( @Input VARCHAR(50) )
    --RETURN REPLACE(LTRIM(REPLACE(@Input, '0', ' ')), ' ', '0')
    RETURN SUBSTRING(@Input, PATINDEX('%[^0]%', @Input+'.'), LEN(@Input))

How to obtain the subdomain of a domain name using VB.NET

How to obtain the subdomain of a domain name using VB.NET:

I thought that the System.Uri class contained that information in an easy retrievable way, but no.

Here’s what I came up with instead. It still uses the System.Uri to find the subdomain.

 Function GetSubdomain() As String
        Dim url As Uri = Request.Url
        Dim host As String = url.Host
        If host.Split(".").Length > 1 Then
            Dim index As Integer = host.IndexOf(".")
            Return host.Substring(0, index)
        End If
        Return ""
    End Function

How to send Push Notifications using PHP / Google Android

Google Cloud Messaging (GCM) for Android is a service that allows you to send data from your server to your users’ Android-powered device, and also to receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device, and it is completely free.

The only thing you will need is a Google_Api_key:

To create a Google API project:

  1. Open the Google Developers Console.
  2. If you haven’t created an API project yet, click Create Project.
  3. Supply a project name and click Create.Once the project has been created, a page appears that displays your project ID and project number. For example, Project Number: 670330094152.
  4. Copy down your project number. You will use it later on as the GCM sender ID.

To obtain an API key:

  1. In the sidebar on the left, select APIs & auth > Credentials.
  2. Under Public API access, click Create new key.
  3. In the Create a new key dialog, click Server key.
  4. In the resulting configuration dialog, supply your server’s IP address. For testing purposes, you can use0.0.0.0/0.
  5. Click Create.
  6. In the refreshed page, copy the API key. You will need the API key later on to perform authentication in your app server.

Continue reading “How to send Push Notifications using PHP / Google Android”