2005年06月30日

使用如下代码

 switch (strtoupper(trim($format))){
   case ‘4A0′: {$format = array(4767.87,6740.79); break;}
   case ‘2A0′: {$format = array(3370.39,4767.87); break;}
   case ‘A0′: {$format = array(2383.94,3370.39); break;}
   case ‘A1′: {$format = array(1683.78,2383.94); break;}
   case ‘A2′: {$format = array(1190.55,1683.78); break;}
   case ‘A3′: {$format = array(841.89,1190.55); break;}
   case ‘A4′: {$format = array(595.28,841.89); break;}
   case ”: {$format = array(595.28,841.89); break;}
   case ‘A5′: {$format = array(419.53,595.28); break;}
   case ‘A6′: {$format = array(297.64,419.53); break;}
   case ‘A7′: {$format = array(209.76,297.64); break;}
   case ‘A8′: {$format = array(147.40,209.76); break;}
   case ‘A9′: {$format = array(104.88,147.40); break;}
   case ‘A10′: {$format = array(73.70,104.88); break;}
   case ‘B0′: {$format = array(2834.65,4008.19); break;}
   case ‘B1′: {$format = array(2004.09,2834.65); break;}
   case ‘B2′: {$format = array(1417.32,2004.09); break;}
   case ‘B3′: {$format = array(1000.63,1417.32); break;}
   case ‘B4′: {$format = array(708.66,1000.63); break;}
   case ‘B5′: {$format = array(498.90,708.66); break;}
   case ‘B6′: {$format = array(354.33,498.90); break;}
   case ‘B7′: {$format = array(249.45,354.33); break;}
   case ‘B8′: {$format = array(175.75,249.45); break;}
   case ‘B9′: {$format = array(124.72,175.75); break;}
   case ‘B10′: {$format = array(87.87,124.72); break;}
   case ‘C0′: {$format = array(2599.37,3676.54); break;}
   case ‘C1′: {$format = array(1836.85,2599.37); break;}
   case ‘C2′: {$format = array(1298.27,1836.85); break;}
   case ‘C3′: {$format = array(918.43,1298.27); break;}
   case ‘C4′: {$format = array(649.13,918.43); break;}
   case ‘C5′: {$format = array(459.21,649.13); break;}
   case ‘C6′: {$format = array(323.15,459.21); break;}
   case ‘C7′: {$format = array(229.61,323.15); break;}
   case ‘C8′: {$format = array(161.57,229.61); break;}
   case ‘C9′: {$format = array(113.39,161.57); break;}
   case ‘C10′: {$format = array(79.37,113.39); break;}
   case ‘RA0′: {$format = array(2437.80,3458.27); break;}
   case ‘RA1′: {$format = array(1729.13,2437.80); break;}
   case ‘RA2′: {$format = array(1218.90,1729.13); break;}
   case ‘RA3′: {$format = array(864.57,1218.90); break;}
   case ‘RA4′: {$format = array(609.45,864.57); break;}
   case ‘SRA0′: {$format = array(2551.18,3628.35); break;}
   case ‘SRA1′: {$format = array(1814.17,2551.18); break;}
   case ‘SRA2′: {$format = array(1275.59,1814.17); break;}
   case ‘SRA3′: {$format = array(907.09,1275.59); break;}
   case ‘SRA4′: {$format = array(637.80,907.09); break;}
   case ‘LETTER’: {$format = array(612.00,792.00); break;}
   case ‘LEGAL’: {$format = array(612.00,1008.00); break;}
   case ‘EXECUTIVE’: {$format = array(521.86,756.00); break;}
   case ‘FOLIO’: {$format = array(612.00,936.00); break;}
   default:   $this->Error(‘Unknown page format: ‘.$format);
  } 

替换FPDF中的如下代码

  $format=strtolower($format);
  if($format==’a3′)
   $format=array(841.89,1190.55);
  elseif($format==’a4′)
   $format=array(595.28,841.89);
  elseif($format==’a5′)
   $format=array(420.94,595.28);
  elseif($format==’letter’)
   $format=array(612,792);
  elseif($format==’legal’)
   $format=array(612,1008);
  else
   $this->Error(‘Unknown page format: ‘.$format);

  这样不但增进了更多常用的尺寸格式,而且通过字符串处理,你即使不小心在尺寸格式中敲入空格也没有关系了,以上代码根据http://www.ros.co.nz/pdf的PDFClass中部分代码修改而成,当然你也可以把这个尺寸格式和尺寸的对照表用于任何你感兴趣的程序代码中,比如以前我就专门写了一个Acrobat的javascript插件,专门用来生成标准格式(也可以自定义)的空白PDF文件。

2005年06月29日

例子参考:

Demo.php

<?php
//error_reporting (E_ALL);
define(‘FPDF_FONTPATH’,’../font/’);
require(‘../fpdf.php’);
require(‘Roman.php’);

class PDF extends fpdf

 //Page footer
 function Footer()
 {
  //Position at 1.5 cm from bottom
  $this->SetY(-15);
  //Arial italic 8
  $this->SetFont(‘Arial’,'I’,8);
  //Page number  
  $Roman= new Numbers_Roman();
  $this->Cell(0,10,$Roman->toRoman($this->PageNo()),0,0,’C');//默认转为大写  
 }
}

$pdf= new PDF();
$Roman= new Numbers_Roman();
for ($i = 1; $i <= 10; $i++) {
 $pdf->AddPage();
 $pdf->SetFont(‘Arial’,'B’,16);
 $pdf->Cell(40,10,’Page ‘.$Roman->toRoman($i,false));//显示小写罗马数字
}
$pdf->Output(‘roman.pdf’);
?>

Roman.php

<?php
//
// +———————————————————————-+
// | PHP Version 4                                                        |
// +———————————————————————-+
// | Copyright (c) 1997-2004 The PHP Group                                |
// +———————————————————————-+
// | This source file is subject to version 2.02 of the PHP license,      |
// | that is bundled with this package in the file LICENSE, and is        |
// | available at through the world-wide-web at                           |
// |
http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// |
license@php.net so we can mail you a copy immediately.               |
// +———————————————————————-+
// | Authors :  David Costa <
gurugeek@php.net>                            |
// |            Sterling Hughes <
sterling@php.net>                        |
// +———————————————————————-+
// $Id: Roman.php,v 1.14 2004/04/28 13:13:08 danielc Exp $

// {{{ Numbers_Roman

/**
 * Provides utilities to convert roman numerals to
 * arabic numbers and convert arabic numbers to roman numerals.
 *
 * Supports lower case input and output and some furthers conversion
 * functions.
 *
 * @access public
 * @author David Costa <
gurugeek@php.net>
 * @author Sterling Hughes <
sterling@php.net>
 * @package Numbers_Roman
 */
class Numbers_Roman
{
    // {{{ toNumber()

    /**
     * Converts a roman numeral to a number
     *
     * @param  string  $roman The roman numeral to convert
     *                        lower cased numerals are converted into
     *                        uppercase
     * @return integer $num   The number corresponding to the
     *                        given roman numeral
     * @access public
     */
    function toNumber($roman)
    {
        $roman = strtoupper($roman);

        /*
         * Replacing the Numerals representing an integer higher then 4000
         * e.g. _X represent 10 000 _L  represent 50 000 etc
         * we first convert them into single characters
         */
        $roman = str_replace(‘_V’, ‘S’, $roman);
        $roman = str_replace(‘_X’, ‘R’, $roman);
        $roman = str_replace(‘_L’, ‘Q’, $roman);
        $roman = str_replace(‘_C’, ‘P’, $roman);
        $roman = str_replace(‘_D’, ‘O’, $roman);
        $roman = str_replace(‘_M’, ‘N’, $roman);

        $conv = array(
            array(‘letter’ => ‘I’, ‘number’ => 1),
            array(‘letter’ => ‘V’, ‘number’ => 5),
            array(‘letter’ => ‘X’, ‘number’ => 10),
            array(‘letter’ => ‘L’, ‘number’ => 50),
            array(‘letter’ => ‘C’, ‘number’ => 100),
            array(‘letter’ => ‘D’, ‘number’ => 500),
            array(‘letter’ => ‘M’, ‘number’ => 1000),
            array(‘letter’ => ‘S’, ‘number’ => 5000),
            array(‘letter’ => ‘R’, ‘number’ => 10000),
            array(‘letter’ => ‘Q’, ‘number’ => 50000),
            array(‘letter’ => ‘P’, ‘number’ => 100000),
            array(‘letter’ => ‘O’, ‘number’ => 500000),
            array(‘letter’ => ‘N’, ‘number’ => 1000000),
            array(‘letter’ => 0, ‘number’ => 0)
        );

        $arabic = 0;
        $state = 0;
        $sidx = 0;
        $len = strlen($roman) – 1;

        while ($len >= 0) {
            $i = 0;
            $sidx = $len;

            while ($conv[$i]['number'] > 0) {
                if (strtoupper($roman[$sidx]) == $conv[$i]['letter']) {
                    if ($state > $conv[$i]['number']) {
                        $arabic -= $conv[$i]['number'];
                    } else {
                        $arabic += $conv[$i]['number'];
                        $state = $conv[$i]['number'];
                    }
                }
                $i++;
            }
            $len–;
        }

        return $arabic;
    }

    // }}}
    // {{{ toRoman()

    /**
     * A backwards compatibility alias for toNumeral()
     *
     * @access private
     */
    function toRoman($num, $uppercase = true)
    {
        return $this->toNumeral($num, $uppercase);
    }

    // }}}
    // {{{ toNumeral()

    /**
     * Converts a number to its roman numeral representation
     *
     * @param  integer $num         An integer between 0 and 3999
     *                              inclusive that should be converted
     *                              to a roman numeral integers higher than
     *                              3999 are supported from version 0.1.2
     *           Note:
     *           For an accurate result the integer shouldn’t be higher
     *           than 5 999 999. Higher integers are still converted but
     *           they do not reflect an historically correct Roman Numeral.
     *
     * @param  bool    $uppercase   Uppercase output: default true
     *
     * @param  bool    $html        Enable html overscore required for
     *                              integers over 3999. default true
     * @return string  $roman The corresponding roman numeral
     *
     * @access public
     */
    function toNumeral($num, $uppercase = true, $html = true)
    {
        $conv = array(10 => array(‘X’, ‘C’, ‘M’),
        5 => array(‘V’, ‘L’, ‘D’),
        1 => array(‘I’, ‘X’, ‘C’));
        $roman = ”;

        if ($num < 0) {
            return ”;
        }

        $num = (int) $num;

        $digit = (int) ($num / 1000);
        $num -= $digit * 1000;
        while ($digit > 0) {
            $roman .= ‘M’;
            $digit–;
        }

        for ($i = 2; $i >= 0; $i–) {
            $power = pow(10, $i);
            $digit = (int) ($num / $power);
            $num -= $digit * $power;

            if (($digit == 9) || ($digit == 4)) {
                $roman .= $conv[1][$i] . $conv[$digit+1][$i];
            } else {
                if ($digit >= 5) {
                    $roman .= $conv[5][$i];
                    $digit -= 5;
                }

                while ($digit > 0) {
                    $roman .= $conv[1][$i];
                    $digit–;
                }
            }
        }

        /*
         * Preparing the conversion of big integers over 3999.
         * One of the systems used by the Romans  to represent 4000 and
         * bigger numbers was to add an overscore on the numerals.
         * Because of the non ansi equivalent if the html output option
         * is true we will return the overline in the html code if false
         * we will return a _ to represent the overscore to convert from
         * numeral to arabic we will always expect the _ as a
         * representation of the html overscore.
         */
        if ($html == true) {
            $over = ‘<span style="text-decoration:overline;">’;
            $overe = ‘</span>’;
        } elseif ($html == false) {
            $over = ‘_’;
            $overe = ”;
        }

        /*
         * Replacing the previously produced multiple MM with the
         * relevant numeral e.g. for 1 000 000 the roman numeral is _M
         * (overscore on the M) for 900 000 is _C_M (overscore on both
         * the C and the M) We initially set the replace to AFS which
         * will be later replaced with the M.
         *
         * 500 000 is   _D (overscore D) in Roman Numeral
         * 400 000 is _C_D (overscore on both C and D) in Roman Numeral
         * 100 000 is   _C (overscore C) in Roman Numeral
         *  90 000 is _X_C (overscore on both X and C) in Roman Numeral
         *  50 000 is   _L (overscore L) in Roman Numeral
         *  40 000 is _X_L (overscore on both X and L) in Roman Numeral
         *  10 000 is   _X (overscore X) in Roman Numeral
         *   5 000 is   _V (overscore V) in Roman Numeral
         *   4 000 is M _V (overscore on the V only) in Roman Numeral
         *
         * For an accurate result the integer shouldn’t be higher then
         * 5 999 999. Higher integers are still converted but they do not
         * reflect an historically correct Roman Numeral.
         */
        $roman = str_replace(str_repeat(‘M’, 1000),
                             $over.’AFS’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 900),
                             $over.’C’.$overe.$over.’AFS’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 500),
                             $over.’D’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 400),
                             $over.’C’.$overe.$over.’D’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 100),
                             $over.’C’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 90),
                             $over.’X’.$overe.$over.’C’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 50),
                             $over.’L’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 40),
                             $over.’X’.$overe.$over.’L’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 10),
                             $over.’X’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 5),
                             $over.’V’.$overe, $roman);
        $roman = str_replace(str_repeat(‘M’, 4),
                             ‘M’.$over.’V’.$overe, $roman);

        /*
         * Replacing AFS with M used in both 1 000 000
         * and 900 000
         */
        $roman = str_replace(‘AFS’, ‘M’, $roman);

        /*
         * Checking for lowercase output
         */
        if ($uppercase == false) {
            $roman = strtolower($roman);
        }

        return $roman;
    }

    // }}}

}

// }}}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 */

?>

        FPDF ,一个纯PHP编写免费的用于PDF生成的类,也就是说不再需要PDFlib(该控件如果用于商业用途,是需要付费的),现在经过扩展的FPDF不仅仅可以用于PDF生成,还可以用于PDF的处理;你可以对FPDF做任意修改和用于商业用途;FPDF中的F就是Free的意思。

FPDF 还有很多其它的优点:高级函数;下面是一些主要特征:

  • 可设置尺寸单位,页面大小和页边距
  • 可定义页眉和页脚
  • 自动分页
  • 自动断行以及文本调整
  • 支持图片 (JPEG and PNG)
  • 颜色
  • 链接 
  • TrueType, Type1 及编码
  • 压缩

FPDF 可以工作在PHP4和PHP5环境下,并且不需要任何 动态扩展(除非使用zlib来激活压缩功能)。

英文官方网站是http://www.fpdf.org

最新版本的下载地址:

V1.53:http://www.fpdf.org/en/dl.php?v=153&f=zip

简体中文手册(V1.52):http://www.fpdf.org/en/dl.php?id=72

中文PDF支持类:http://www.fpdf.org/download/chinese.zip

FPDF.ORG上其它非常棒的脚本:http://www.fpdf.org/en/script/index.php

附简体中文PDF输出的例子:

<?php
require(‘chinese.php’);
class PDF extends PDF_Chinese
{
//Page header
function Header()
{
$pdf->SetFont(‘GB’,”,10);
$pdf->Write(10,’头Test中文测试’);
}
//Page footer
function Footer()
{
$pdf->SetFont(‘GB’,”,10);
$pdf->Write(10,’尾 Test中文测试’);
}
}
//Instanciation of inherited class
$pdf=new PDF_Chinese();
$pdf->AddGBFont();
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont(‘GB’,”,12);
for($i=1;$i<=40;$i++)
$pdf->Cell(0,10,’中文测试 ‘.$i,0,1); //this can output correct
$pdf->Output();
?>

2005年06月24日

       经过下午2个小时的研究,整合了我的PDF2IMG(PDF页面转为图片)和IMG2PPT(图片转为Powerpoint),终于生成了PDF2PPT;

       这次并非简单把PDF2IMG和IMG2PPT的功能结合起来,而是做了很多修改,让PDF到图片的转换以及把生成的图片插入Powerpoint的动作都放在内存中完成,不再生成临时的图片文件,一次提高速度和减少以外发生;

可以到http://soft.rubypdf.com/softwares/pdf2ppt/pdf2ppt-acrobat-free下载最新版本。

2005年06月20日

我从国外网站下载的Adobe Acrobat Professional 7 培训教程(Total.Training.For.[Adobe.Acrobat.7.Professional]),总计4CD,从名字就可以看出它包含了Acrobat Professioanl 7的方方面面,能帮助你尽快成为Acrobat的高手,图片和语音都非常清晰,只是有点难为我这英语水平不怎么样的人了。

下面是英文介绍          

                                                                        
               Released By: A[m]D                   Release Size: 120 x 15MB     
               Protection: None                     Compression Type: WinRAR     
               Developer: Total Training            File Type: CD-ROM (ISO)      
               Release Date: 05-18-05               Disc Qty: 4                  
                                                                                 
               _____________________________________________________________     
                                                                                 
                                                                                 
         Program Info:                                                           
                                                                                 
         Master the most powerful document management software with Total        
         Training For Adobe?Acrobat?7 Professional. We unveil the software    
         many capabilities to simplify sharing spreadsheets, presentations,      
         brochures, and graphics across different hardware and software platforms.
         You’ll get the job done faster and maximize your investment with        
         comprehensive lessons on how to create and combine multiple PDF files,  
         add bookmarks for quick navigation, secure documents with passwords, and
         integrate multimedia movies and sounds. The dynamic presentation format,
         applicable to both Mac and Windows users, is led by Tim Plumer, Jr., an 
         Adobe Acrobat Evangelist. Tim covers more than eight hours of lessons,  
         including two hours dedicated to advanced techniques.                   
                                                                                 
                                                                                 
         Tutorial Info:                                                          
                                                                                 
         Experience Level: Beginner Through Advanced                             
         Running Time: 8.6 Hours                                                 
         Project Files: Included                                                 
         Website: http://www.totaltraining.com/prod/adobe/acrobat7_pro.asp       
                                                                                 
                                                                                 
         CD1:                                                                    
                                                                                 
         CREATING ADOBE PDF FILES & BUILDING A DOCUMENT                          
         01.) An Overview Of Adobe Acrobat 7                                     
         02.) The Adobe Acrobat Interface                                        
         03.) Creating Adobe PDF Files                                           
         04.) Exploring Adobe Acrobat Distiller                                  
         05.) Assembling A Complete Document                                     
                                                                                 
         CD2:                                                                    
                                                                                 
         SEARCHING, REUSING & REVIEWING A PDF FILE                               
         01.) Cataloging PDF Files                                               
         02.) The Art Of Linking                                                 
         03.) Repurposing Content                                                
         04.) Using The Commenting Tools                                         
         05.) Managing The Review Process                                        
                                                                                 
         CD3:                                                                    
                                                                                 
         CREATING FORMS, SECURITY & OPTIMIZATION                                 
         01.) Basic Forms                                                        
         02.) Advanced Forms                                                     
         03.) Adding Security To A Document                                      
         04.) Optimizing PDF Files                                               
         05.) Integrating Multimedia With PDF Files                              
                                                                                 
         CD4:                                                                    
                                                                                 
         ADVANCED ACROBAT                                                        
         01.) Working With Layered Files                                         
         02.) Creating Print-Ready PDF Files                                     
         03.) Accepting Print-Ready PDF Files                                    
         04.) Javascripts & PDF Files                                         
                                                                                 

      这个程序还是去年写的了,当初因为有几个朋友询问PDF合并软件或者控件方面的问题,很巧有两个人要开发专利文献下载工具;觉得好奇就用delphi和网上的一个文件下载的雏形结合我自己写得PDF合并软件(PDFMerge)写了个专利文献下载工具,但这个工具没有公开过,现在也不知道留着还有多少价值,现在把记下这些主要是担心以后忘记了。

       最近几日失业在家,想到以前论坛里朋友提到要PDF2PPT(主要是把PPT转的PDF再转回来),当然网上也有一两个类似的软件,但我还是决定自己做些尝试。

       我的Delphi水平比较差些,以前用它写过一些小的软件,比如改写了一个用C语言开发的去除TrueType字体内嵌限制的小工具,一个利用Acrobat(不是Acrobat Reader)写得PDF2IMG(把PDF的每一页转成图片,不管这个PDF是纯图片的还是图文的,好像VB无法实现),这次决定再用Delphi写个图片转PPT的软件,并和PDF2IMG整合为PDF2PPT,当然也可以单独使用。

       把PDF转成PPT,其实是个比较专业的利用,一般人对这个软件没有什么兴趣,我感觉从实现上分两步走,第一步,把PDF的每页变成图片(img),然后在把这些图片转为一个PPT文档;关于图片转PPT方面网上有一个VB版本的源代码;还有一个C版本的。

      关于PDF转为图片,可以考虑利用Acrobat,GhostScript或者XPDF(针对纯图片的PDF),具体利用我这里就不细说了,有兴趣的可以一起探讨。

      手中有个Delphi版本的SWFSDK,不知道如果写个PDF2SWF或者IMG2SWF之类的,是否有意义呢?

 

PDFToPPT的免Acrobat版本可以这里下载http://soft.rubypdf.com/softwares/pdf2ppt/pdf2ppt-acrobat-free

2005年06月18日

前两天在网上看到PDF Hacks 一书,很想down个下来看看,一问朋友,说早有下载的了,于是google了下,国内没有一个好下载的,有的还要注册等繁琐工作,还不知道是否好用,于是想到google.ru上搜索了一下,找到如下这个网址:http://ebuki.apvs.ru/

该网站查找到的图书必须使用俄罗斯的代理服务器才可以下载,下面推荐两个地址:

80.92.29.98:80

195.145.214.67:8080(这个是一个朋友推荐的,说是更快)

2005年06月14日

本来打算测试itext.net的,这下又泡汤了;不知道哪里还有免费的aspx空间呢?