/*
 * 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;

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;

import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

/**
 * This is an example that creates a simple document.
 *
 * The example is taken from the pdf file format specification.
 *
 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
 * @version $Revision: 1.6 $
 */
public class HelloWorld
{
    /**
     * Constructor.
     */
    public HelloWorld()
    {
        super();
    }

    /**
     * create the second sample document from the PDF file format specification.
     *
     * @param file The file to write the PDF to.
     * @param message The message to write in the file.
     *
     * @throws IOException If there is an error writing the data.
     */
    public void doIt( String file, String message) throws IOException
    {
        // the document
        PDDocument doc = null;
        try
        {
            doc = new PDDocument();

            PDPage page = new PDPage();
            doc.addPage( page );
            PDFont font = PDType1Font.HELVETICA_BOLD;

            PDPageContentStream contentStream = new PDPageContentStream(doc, page);
            contentStream.beginText();
            contentStream.setFont( font, 12 );
            contentStream.newLineAtOffset(100, 700);
            contentStream.showText(message);
            contentStream.endText();
            contentStream.close();
            doc.save( file );
        }
        finally
        {
            if( doc != null )
            {
                doc.close();
            }
        }
    }

    /**
     * This will create a hello world PDF document.
     * <br />
     * see usage() for commandline
     *
     * @param args Command line arguments.
     */
    public static void main(String[] args) throws IOException
    {
        HelloWorld app = new HelloWorld();
        if( args.length != 2 )
        {
            app.usage();
        }
        else
        {
            app.doIt( args[0], args[1] );
        }
    }

    /**
     * This will print out a message telling how to use this example.
     */
    private void usage()
    {
        System.err.println( "usage: " + this.getClass().getName() + " <output-file> <Message>" );
    }
}

@@ -1126,55 +1126,67 @@
 %0A * 
-This is an example that creates a simple docume
+Creates a %22Hello World%22 PDF using the built-in Helvetica fo
 nt.%0A
@@ -1221,19 +1221,19 @@
 rom the 
-pdf
+PDF
  file fo
@@ -1258,202 +1258,134 @@
 .%0A *
-%0A * @author %3Ca href=%22mailto:ben@benlitchfield.com%22%3EBen Litchfield%3C/a%3E%0A * @version $Revision: 1.6 $%0A */%0Apublic class HelloWorld%0A%7B%0A    /**%0A     * Constructor.
+/%0Apublic class HelloWorld%0A%7B%0A    public static void main(String%5B%5D args) throws IOException
 %0A    
- */
+%7B
 %0A    
-public HelloWorld()%0A    %7B
+    if( args.length != 2 )
 %0A   
@@ -1393,405 +1393,227 @@
     
-super();
+%7B
 %0A    
-%7D%0A%0A
     
-/**%0A     * create the second sample document from the PDF file format specification.%0A     *%0A     * @param file The file to write the PDF to.%0A     * @param message The message to write in the file.%0A
+    System.err.println(%22usage: %22 + HelloWorld.class.getName() + %22 %3Coutput-file%3E %3CMessage%3E%22);%0A            System.exit(1);%0A   
      
-*%0A
+%7D%0A%0A 
      
-* @throws IOException If there is an error writing the data.%0A     */%0A    public void doIt( String file, String message) throws IOException
+  String filename = args%5B0%5D;%0A        String message = args%5B1%5D;
 %0A    
-%7B%0A
     
-    // the document
 %0A   
@@ -1635,19 +1635,31 @@
  doc = n
-ull
+ew PDDocument()
 ;%0A      
@@ -1678,45 +1678,8 @@
   %7B%0A
-            doc = new PDDocument();%0A%0A
     
@@ -1742,17 +1742,28 @@
 age(
- 
 page
- 
 );%0A
+            %0A
     
@@ -1852,22 +1852,17 @@
  content
-Stream
+s
  = new P
@@ -1911,22 +1911,17 @@
  content
-Stream
+s
 .beginTe
@@ -1945,22 +1945,17 @@
  content
-Stream
+s
 .setFont
@@ -1959,17 +1959,16 @@
 ont(
- 
 font, 12
  );%0A
@@ -1963,17 +1963,16 @@
 font, 12
- 
 );%0A     
@@ -1985,22 +1985,17 @@
  content
-Stream
+s
 .newLine
@@ -2033,22 +2033,17 @@
  content
-Stream
+s
 .showTex
@@ -2073,22 +2073,17 @@
  content
-Stream
+s
 .endText
@@ -2109,153 +2109,9 @@
 tent
-Stream.close();%0A            doc.save( file );%0A        %7D%0A        finally%0A        %7B%0A            if( doc != null )%0A            %7B%0A                doc
+s
 .clo
@@ -2120,33 +2120,32 @@
 ();%0A            
-%7D
 %0A        %7D%0A    %7D
@@ -2141,667 +2141,102 @@
     
-%7D%0A
     
-%7D%0A%0A    /**%0A     * This will create a hello world PDF document.%0A     * %3Cbr /%3E%0A     * see usage() for commandline%0A     *%0A     * @param args Command line arguments.%0A     */%0A    public static void main(String%5B%5D args) throws IOException%0A    %7B%0A        HelloWorld app = new HelloWorld();%0A        if( args.length != 2 )%0A        %7B%0A            app.usage();%0A        %7D%0A        else%0A        %7B%0A            app.doIt( args%5B0%5D, args%5B1%5D );%0A        %7D%0A    %7D%0A%0A    /**%0A     * This will print out a message telling how to use this example.%0A     */%0A    private void usag
+doc.save(filename);%0A        %7D%0A        finally%0A        %7B%0A            doc.clos
 e()
+;
 %0A    
-%7B%0A
     
-    System.err.println( %22usage: %22 + this.getClass().getName() + %22 %3Coutput-file%3E %3CMessage%3E%22 );
+%7D
 %0A   

Simplify HelloWorld example