/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.examples.pdmodel;

import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;

/**
 * This will create a blank PDF and write the contents to a file.
 *
 * usage: java org.apache.pdfbox.examples.pdmodel.CreateBlankPDF &lt;outputfile.pdf&gt;
 *
 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
 * @version $Revision: 1.9 $
 */
public class CreateBlankPDF
{

    /**
     * This will create a blank PDF and write the contents to a file.
     *
     * @param file The name of the file to write to.
     *
     * @throws IOException If there is an error writing the data.
     */
    public void create( String file ) throws IOException
    {
        PDDocument document = null;
        try
        {
            document = new PDDocument();
            //Every document requires at least one page, so we will add one
            //blank page.
            PDPage blankPage = new PDPage();
            document.addPage( blankPage );
            document.save( file );
        }
        finally
        {
            if( document != null )
            {
                document.close();
            }
        }
    }

    /**
     * This will create a blank document.
     *
     * @param args The command line arguments.
     *
     * @throws IOException If there is an error writing the document data.
     */
    public static void main( String[] args ) throws IOException
    {
        if( args.length != 1 )
        {
            usage();
        }
        else
        {
            CreateBlankPDF creator = new CreateBlankPDF();
            creator.create( args[0] );
        }
    }

    /**
     * This will print the usage of this class.
     */
    private static void usage()
    {
        System.err.println( "usage: java org.apache.pdfbox.examples.pdmodel.CreateBlankPDF <outputfile.pdf>" );
    }
}

@@ -964,27 +964,17 @@
 %0A/**%0A * 
-This will c
+C
 reate a 
@@ -1021,200 +1021,8 @@
 le.%0A
- *%0A * usage: java org.apache.pdfbox.examples.pdmodel.CreateBlankPDF &lt;outputfile.pdf&gt;%0A *%0A * @author %3Ca href=%22mailto:ben@benlitchfield.com%22%3EBen Litchfield%3C/a%3E%0A * @version $Revision: 1.9 $%0A
  */%0A
@@ -1055,612 +1055,239 @@
 F%0A%7B%0A
-%0A
     
-/**%0A     * This will create a blank PDF and write the contents to a file.%0A     *%0A     * @param file The name of the file to write to.%0A     *%0A     * @throws IOException If there is an error writing the data.%0A     */%0A    public void create( String file ) throws IOException%0A    %7B%0A        PDDocument document = null;%0A        try%0A        %7B%0A            document = new PDDocument();%0A            //Every document requires at least one page, so we will add one%0A            //blank page.%0A            PDPage blankPage = new PDPage();%0A            document.addPage( blankPage );%0A            document.save( file 
+public static void main(String%5B%5D args) throws IOException%0A    %7B%0A        if (args.length != 1)%0A        %7B%0A            System.err.println(%22usage: %22 + CreateBlankPDF.class.getName() + %22 %3Coutputfile.pdf%3E%22);%0A            System.exit(1
 );%0A 
@@ -1295,24 +1295,25 @@
       %7D%0A
+%0A
         
 finally%0A
@@ -1308,15 +1308,34 @@
     
-finally
+String filename = args%5B0%5D;
 %0A   
@@ -1339,28 +1339,25 @@
         
-%7B%0A  
+%0A
         
   if( do
@@ -1352,23 +1352,19 @@
     
-  if( d
+PDD
 ocument 
 != n
@@ -1363,62 +1363,28 @@
 ent 
-!= null )%0A            %7B%0A                d
+doc = new PDD
 ocument
-.close
 ();%0A
@@ -1387,29 +1387,27 @@
 ();%0A        
-    %7D
+try
 %0A        %7D%0A 
@@ -1407,336 +1407,111 @@
     
-%7D
+%7B
 %0A    
-%7D%0A%0A
     
-/**%0A     * This will create a blank document.%0A     *%0A     * @param args The command line arguments.%0A     *%0A     * @throws IOException If there is an error writing the document data.
+    // a valid PDF document requires at least one page
 %0A     
-*/%0A
     
-public static void main( String%5B%5D args ) throws IOException%0A    %7B%0A        if( args.length != 1 )%0A        %7B%0A            us
+   PDPage blankPage = new PDP
 age(
@@ -1524,129 +1524,66 @@
     
- %7D%0A
      
-   else%0A        %7B%0A            CreateBlankPDF creator = new CreateBlankPDF();%0A            creator.create( args%5B0%5D 
+doc.addPage(blankPage);%0A            doc.save(filename
 );%0A 
@@ -1599,224 +1599,64 @@
     
-%7D%0A%0A
     
-/**%0A     * This will print the usage of this class.%0A     */%0A    private static void usage()%0A    %7B%0A        System.err.println( %22usage: java org.apache.pdfbox.examples.pdmodel.CreateBlankPDF %3Coutputfile.pdf%3E%22 );
+finally%0A        %7B%0A            doc.close();%0A        %7D
 %0A   

Clean up CreateBlankPDF example