myAdBanner

2013年10月28日 星期一

數字前面補0 使用sprintf

* %% - 返回百分比符號
* %b - 二進位數字
* %c - 依照 ASCII 值的字元
* %d - 帶符號十進位數字
* %e - 可續計數法(比如 1.5e+3)
* %u - 無符號十進位數字
* %f - 浮點數(local settings aware)
* %F - 浮點數(not local settings aware)
* %o - 八進位數
* %s - 字串
* %x - 十六進位數(小寫字母)
* %X - 十六進位數(大寫字母)

< ?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f
With no decimals: %1\$u",$number);
echo $txt."<br>";
echo sprintf("%05d", 1); 
?>
輸出: With 2 decimals: 123.00 With no decimals: 123 00001

2013年10月21日 星期一

用jquery來控制div的顯示與隱藏





   
   
   
   

2013年10月15日 星期二

iis7 改 port

選取站台 右鍵 編輯連繫 http 80 改 8080

2013年10月8日 星期二

解決 PHP 連 MySQL 亂碼的問題

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_wcjx_conn = "localhost";
$database_wcjx_conn = "dbName";
$username_wcjx_conn = "root";
$password_wcjx_conn = "12345678";
$wcjx_conn = mysql_pconnect($hostname_wcjx_conn, $username_wcjx_conn, $password_wcjx_conn) or trigger_error(mysql_error(),E_USER_ERROR); 
// 加上這一段就OK了
mysql_query("SET CHARACTER SET utf8",$wcjx_conn);
mysql_query("SET CHARACTER_SET_database= utf8",$wcjx_conn);
mysql_query("SET CHARACTER_SET_CLIENT= utf8",$wcjx_conn);
mysql_query("SET CHARACTER_SET_RESULTS= utf8",$wcjx_conn);
?>

2013年10月7日 星期一

itext 文字浮水印

        string sFileIn = "D:\\pdftmp\\102\\09\\10209240001.pdf";
        PdfReader reader = new PdfReader(sFileIn);
        MemoryStream ms = new MemoryStream();

        PdfStamper stamper = new PdfStamper(reader, ms);

        for (int i = 1; i <= reader.NumberOfPages; i++)
        {
            iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i);
            PdfContentByte pdfPageContents = stamper.GetUnderContent(i);
            pdfPageContents.BeginText();
            BaseFont bfChinese = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\kaiu.ttf", BaseFont.IDENTITY_V, BaseFont.NOT_EMBEDDED); //字體 標楷體直書
            //BaseFont bfChinese = BaseFont.createFont("C:\\windows\\fonts\\KAIU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); //字體 標楷體橫書

            pdfPageContents.SetFontAndSize(bfChinese, 14);//14 字型大小
            pdfPageContents.SetRGBColorFill(0, 0, 0); //文字顏色
            float textAngle = 0.0f; //旋轉角度
            float left = 570; //PageSize.Width / 2;
            float bottom = 700; // PapeSize.A4.Hight / 2 + 120f;
            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "版權所有翻印必究。", left, bottom, textAngle);
            //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "本內容之版權由相關機構擁有", left + 15, bottom, textAngle);
                    
            stamper.FormFlattening = true;
            stamper.Close();
            reader.Close();
            pdfPageContents.EndText();
        }
        //stamper.FormFlattening = true;
        //stamper.Close();
        FileStream fs = new FileStream("D:\\pdftmp\\102\\09\\watermarked-output.pdf", FileMode.Create, FileAccess.ReadWrite);
        BinaryWriter bw = new BinaryWriter(fs);
        bw.Write(ms.ToArray());
        fs.Close();
        bw.Close();

用此方式如產生
『此頁上有錯誤。Acrobat可能無法正確顯示頁面。請聯繫PDF文件的建立者來更正問題。』

請移除舊版檢視軟體(Adobe Reader),移除後請至「ADOBE READER」網站,下載並安裝Adobe Reader(須10.1.4以上版本)。

itext 加上圖片浮水印


        string FileLocation = "D:\\pdftmp\\102\\09\\10209240001.pdf";  //PDF原始檔路徑
        string WatermarkLocation = "D:\\www\\aspx\\cute\\water-4.png"; //浮水印圖檔路徑

        Document document = new Document();
        PdfReader pdfReader = new PdfReader(FileLocation);
        PdfStamper stamp = new PdfStamper(pdfReader, new FileStream(FileLocation.Replace(".pdf", "[temp][file].pdf"), FileMode.Create));

        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(WatermarkLocation);
        img.SetAbsolutePosition(560, 100); // 圖片位置 (560,0 = 距離 左方,下方 位置)
        img.ScalePercent(35f);  //縮放比例

        PdfContentByte waterMark;
        for (int page = 1; page <= pdfReader.NumberOfPages; page++)
        {
            waterMark = stamp.GetOverContent(page);
            waterMark.AddImage(img);
        }
        stamp.FormFlattening = true;
        stamp.Close();
        File.Delete(FileLocation);
        File.Move(FileLocation.Replace(".pdf", "[temp][file].pdf"), FileLocation);