Package eas.startSetup.marbBuilder

Source Code of eas.startSetup.marbBuilder.CropBorder

package eas.startSetup.marbBuilder;

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;

/**
* Bisher nicht verwendet.
*
* @author Internet: http://www.local-guru.net/blog/2009/6/16/ebook-pdf-border-remover
*/
public class CropBorder {
    public static void main(String[] args) throws Exception {

        String input = "C:/Workspace/EAS-Framework/sharedDirectory/graph0.pdf";
        String output = "C:/Workspace/EAS-Framework/sharedDirectory/graph1.pdf";
        float factor = 1.2f;
        float left = -47.0f;
        float down = -45.0f;

        for ( int i= 0; i < args.length; i++) {
            if ("-h".equals(args[i])) {
                System.out.println( "Usage: java -jar cropborder.jar [-in <input.pdf>] [-out <output.pdf>] [-f <scaling factor>] [-l <dots to move the left border>] [-d <dots to move the lower border>]" );
                 System.exit(0);
            }  
        }

        for ( int i= 0; i < args.length -1; i++) {
            if ("-in".equals(args[i])) {
                input = args[i+1];
            } else if ( "-out".equals(args[i])) {
                output = args[i+1];
            } else if ( "-f".equals(args[i])) {
                factor = Float.parseFloat( args[i+1]);
            } else if ( "-l".equals(args[i])) {
                left = Float.parseFloat( args[i+1]);
            }else if ( "-d".equals(args[i])) {
                down = Float.parseFloat( args[i+1]);
            }
        }

        System.out.println( "Converting: " + input +  " to " + output + " scaling by " + factor + " shifting by (" + left + ", " + down + ")");

        PdfReader reader = new PdfReader( input );
        int n = reader.getNumberOfPages();

        Rectangle psize = reader.getPageSize(1);
        float width = psize.getHeight();
        float height = psize.getWidth();

        Document document = new Document(new Rectangle(height, width));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream( output ));

        document.open();

        PdfContentByte cb = writer.getDirectContent();

        int i = 0;
        while (i < n) {
            i++;
            document.newPage();
            PdfImportedPage page = writer.getImportedPage(reader, i);
            cb.addTemplate(page, factor, 0, 0, factor, left, down);
        }

        document.close();
    }
}
TOP

Related Classes of eas.startSetup.marbBuilder.CropBorder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.