求:
获取PDF文件的页面属性(size,方向)等的代码(库)。
谢谢。

解决方案 »

  1.   


    itext就可以了,很简单。
      

  2.   

    hi,各位,
    能说详细点吗?我看了一下itext只能设置要,怎么获取?
    麻烦大家给段代码解释一下好吗? 能告诉在哪里能得到这个库吗?谢谢了。
      

  3.   

    一定要能判别页面的方向。 单纯的如“A4”不能完全满足要求。 因为我需要在PDF文档4个角上放标志。
      

  4.   


    DOWNLOAD IT HERE.   http://sourceforge.net/projects/itext/files/iText/iText5.0.2/iText-5.0.2.jar/download

    /*
     * This class is part of the book "iText in Action - 2nd Edition"
     * written by Bruno Lowagie (ISBN: 9781935182610)
     * For more info, go to: http://itextpdf.com/examples/
     * This example only works with the AGPL version of iText.
     */
     
    package part2.chapter06;
     
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.PrintWriter;
     
    import com.itextpdf.text.DocumentException;
    import com.itextpdf.text.Rectangle;
    import com.itextpdf.text.pdf.PdfReader;
     
    import part1.chapter01.HelloWorldLandscape1;
    import part1.chapter01.HelloWorldLandscape2;
    import part1.chapter03.MovieTemplates;
    import part1.chapter05.Hero1;
     
    public class PageInformation {
     
    /** The resulting text file with info about a PDF. */
        public static final String RESULT
            = "results/part2/chapter06/page_info.txt";
     
        /**
         * Main method.
         * @param args no arguments needed
         * @throws DocumentException 
         * @throws IOException
         */
        public static void main(String[] args)
            throws DocumentException, IOException {
         // Use old examples to create PDFs
            HelloWorldLandscape1.main(args);
            HelloWorldLandscape2.main(args);
            MovieTemplates.main(args);
            Hero1.main(args);
            // Inspecting PDFs
            PrintWriter writer = new PrintWriter(new FileOutputStream(RESULT));
            inspect(writer, HelloWorldLandscape1.RESULT);
            inspect(writer, HelloWorldLandscape2.RESULT);
            inspect(writer, MovieTemplates.RESULT);
            inspect(writer, Hero1.RESULT);
            writer.close();
        }
     
        /**
         * Inspect a PDF file and write the info to a txt file
         * @param writer Writer to a text file
         * @param filename Path to the PDF file
         * @throws IOException
         */
        public static void inspect(PrintWriter writer, String filename)
            throws IOException {
            PdfReader reader = new PdfReader(filename);
            writer.println(filename);
            writer.print("Number of pages: ");
            writer.println(reader.getNumberOfPages());
            Rectangle mediabox = reader.getPageSize(1);
            writer.print("Size of page 1: [");
            writer.print(mediabox.getLeft());
            writer.print(',');
            writer.print(mediabox.getBottom());
            writer.print(',');
            writer.print(mediabox.getRight());
            writer.print(',');
            writer.print(mediabox.getTop());
            writer.println("]");
            writer.print("Rotation of page 1: ");
            writer.println(reader.getPageRotation(1));
            writer.print("Page size with rotation of page 1: ");
            writer.println(reader.getPageSizeWithRotation(1));
            writer.print("Is rebuilt? ");
            writer.println(reader.isRebuilt());
            writer.print("Is encrypted? ");
            writer.println(reader.isEncrypted());
            writer.println();
            writer.flush();
        }
      

  5.   

    To coldanimal,
    谢谢,已经好使了。再请教一下,iText是免费的吗?
      

  6.   

    最后一个问题:
    iText是免费的吗?
      

  7.   


    In the end of 2009, iText version 5 is released under Affero GPL license. This license is drastically different from the previous license that iText had been distributed under, in that it requires anyone using iText 5 under a free license to provide the users with the full source of their application. Projects that do not want to provide their source code are required to purchase a commercial license for a non-disclosed price or they cannot upgrade to iText 5. (Projects can continue using previous versions of iText under the more liberal license without any changes.)
      

  8.   

    我翻译下好了简单的说  他说  如果你用了他的东西也就是itext 就需要把你的软件开源
    如果你选择不开源  那你就要去购买他们的商业证书  其实在你不把这个东西放到外包的什么软件里面去  是没关系的  管他哇 哈哈哈