diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFCatalog.java gnujpdf-1.7.1/src/gnu/jpdf/PDFCatalog.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFCatalog.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFCatalog.java 2012-06-10 00:21:15.000000000 +0200 @@ -47,6 +47,30 @@ */ private int pagemode; + /* page layout SinglePage + */ + public static final int SINGLE_PAGE = 0 ; + /* page layout OneColumn + */ + public static final int ONE_COLUMN = 1 ; + /* page layout TwoColumnLeft + */ + public static final int TWO_COLUMN_LEFT = 2 ; + /* page layout TwoColumnRight + */ + public static final int TWO_COLUMN_RIGHT = 3 ; + + /** 2-letter language abbreviation. + * default is none (=unknown) + */ + public String lang ; + + /** + * The page layout + * @since 2012-06-09 + */ + private int pagelayout; + /** * This constructs a PDF Catalog object * @@ -59,6 +83,8 @@ super("/Catalog"); this.pdfPageList = pdfPageList; this.pagemode = pagemode; + pagelayout = SINGLE_PAGE ; + lang = new String() ; } /** @@ -69,6 +95,15 @@ this.outlines = outline; } + /** One of SINGLE_PAGE (default), ONE_COLUMN, TWO_COLUMN_LEFT, TWO_COLUMN_RIGHT + * @param play + * @since 2012-06-09 + * @author R. J. Mathar + */ + public void setPageLayout( int play) { + pagelayout = play; + } + /** * @param os OutputStream to send the object to * @exception IOException on error @@ -98,6 +133,36 @@ os.write(PDFDocument.PDF_PAGE_MODES[pagemode].getBytes()); os.write("\n".getBytes()); + // the /PageLayout setting, added 2012-06-09 by R. J. Mathar + os.write("/PageLayout ".getBytes()); + switch(pagelayout) + { + case SINGLE_PAGE : + os.write("/SinglePage".getBytes()); + break; + case ONE_COLUMN : + os.write("/OneColumn".getBytes()); + break; + case TWO_COLUMN_LEFT : + os.write("/TwoColumnLeft".getBytes()); + break; + case TWO_COLUMN_RIGHT : + os.write("/TwoColumnRight".getBytes()); + break; + } + os.write("\n".getBytes()); + + if ( lang != null) + { + if ( lang.length() == 2) + { + // the /Language setting, added 2012-06-09 by R. J. Mathar + os.write("/Lang ".getBytes()); + os.write(PDFStringHelper.makePDFString(lang).getBytes()); + os.write("\n".getBytes()); + } + } + // finish off with its footer writeEnd(os); } diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFDocument.java gnujpdf-1.7.1/src/gnu/jpdf/PDFDocument.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFDocument.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFDocument.java 2012-06-10 00:01:45.000000000 +0200 @@ -282,6 +282,17 @@ return this.info; } + /** + *

Get the PDFCatalog object, which contains language, page layout + * etc

+ * @return the PDFCatalog object for this document. + * @since 2012-06-10 + * @author R. J. Mathar + */ + public PDFCatalog getPDFCatalog() { + return this.catalog; + } + /** * This writes the document to an OutputStream. diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFInfo.java gnujpdf-1.7.1/src/gnu/jpdf/PDFInfo.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFInfo.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFInfo.java 2012-06-09 19:01:06.000000000 +0200 @@ -22,6 +22,8 @@ package gnu.jpdf; import java.io.*; +import java.util.Date ; +import java.text.SimpleDateFormat ; /** *

This class stores details of the author, the PDF generator etc. @@ -152,9 +154,9 @@ // now the objects body if(author!=null) { - os.write("/Author (".getBytes()); + os.write("/Author ".getBytes()); os.write(PDFStringHelper.makePDFString(author).getBytes()); - os.write(")\n".getBytes()); + os.write("\n".getBytes()); } if(creator!=null) { @@ -186,6 +188,14 @@ os.write(")\n".getBytes()); } + /* generate date, added 2012-06-09, R. J. Mathar + */ + Date today = new Date() ; + SimpleDateFormat dfPdf = new SimpleDateFormat("'D:'yyyyMMddHHmm") ; + os.write("/CreationDate ".getBytes()); + os.write(PDFStringHelper.makePDFString(dfPdf.format(today)).getBytes()); + os.write("\n".getBytes()); + // finish off with its footer writeEnd(os); } // end write diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFOutput.java gnujpdf-1.7.1/src/gnu/jpdf/PDFOutput.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFOutput.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFOutput.java 2012-06-09 15:39:55.000000000 +0200 @@ -74,6 +74,7 @@ * * @param os The output stream to write the PDF file to. * @throws IOException if there is an I/O error. + * @since 2012-06-09 Use 1.5 instead of 1.2 PDF versioning */ public PDFOutput(OutputStream os) throws IOException { @@ -86,7 +87,8 @@ // // Note: As the encoding is fixed here, we use getBytes(). // - baos.write("%PDF-1.2\n".getBytes()); + // baos.write("%PDF-1.2\n".getBytes()); + baos.write("%PDF-1.5\n".getBytes()); // This second comment is advised in the PDF Reference manual // page 61 diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFPage.java gnujpdf-1.7.1/src/gnu/jpdf/PDFPage.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFPage.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFPage.java 2012-06-10 15:49:59.000000000 +0200 @@ -253,7 +253,7 @@ * problems. * * @param orientation a PageFormat orientation constant: - * PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE + * PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFormat.REVERSE_LANDSACPE */ public void setOrientation(int orientation) { pageFormat.setOrientation(orientation); @@ -261,7 +261,7 @@ /** * Returns the pages orientation: - * PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFromat.REVERSE_LANDSACPE + * PageFormat.PORTRAIT, PageFormat.LANDSACPE or PageFormat.REVERSE_LANDSACPE * * @see java.awt.print.PageFormat * @return current orientation of the page @@ -473,6 +473,21 @@ os.write(Integer.toString((int)pageFormat.getHeight()).getBytes()); os.write("]\n".getBytes()); + /* the /CropBox for the page size + * The cbox measures from the upper left corner of the rectangle (in X11-windows style) + * added 2012-06-10, R. J. Mathar + */ + Rectangle cbox = getImageableArea() ; + os.write("/CropBox [".getBytes()); + os.write(Integer.toString(cbox.x).getBytes()); + os.write(" ".getBytes()); + os.write(Integer.toString((int)pageFormat.getHeight()-cbox.y-cbox.height).getBytes()); + os.write(" ".getBytes()); + os.write(Integer.toString(cbox.x+cbox.width).getBytes()); + os.write(" ".getBytes()); + os.write(Integer.toString((int)pageFormat.getHeight()-cbox.y).getBytes()); + os.write("]\n".getBytes()); + // Rotation (if not zero) // if(rotate!=0) { // os.write("/Rotate ".getBytes()); @@ -577,6 +592,9 @@ // Our default procset (use addElement not add, as we dont want a // leading space) set.addElement("/PDF"); + /* additional element /Text added by PDFFont.getFont() if needed, R. J. Mathar, 2012-06-09 + set.addElement("/Text"); + */ } /** diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFStream.java gnujpdf-1.7.1/src/gnu/jpdf/PDFStream.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFStream.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFStream.java 2012-06-09 18:22:01.000000000 +0200 @@ -83,7 +83,7 @@ buf = new ByteArrayOutputStream(); // default deflate mode - deflate = false; + deflate = true; } /** @@ -126,6 +126,14 @@ return buf; } + /** Append a string and a line feed to the stream. + * @since 2012-06-09 + * @author R. J. Mathar + */ + public void append(String str) throws IOException { + buf.write( PDFStringHelper.getBytes(str + "\n")) ; + } + /** * @param os OutputStream to send the object to * @exception IOException on error diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/PDFStringHelper.java gnujpdf-1.7.1/src/gnu/jpdf/PDFStringHelper.java --- gnujpdf-1.7.0/src/gnu/jpdf/PDFStringHelper.java 2007-09-22 09:36:08.000000000 +0200 +++ gnujpdf-1.7.1/src/gnu/jpdf/PDFStringHelper.java 2012-06-09 17:17:56.000000000 +0200 @@ -50,6 +50,22 @@ } /** + * @since 2012-06-09 + * @author R. J. Mathar + */ + public static byte[] getBytes(String str) + { + try + { + return str.getBytes("US-ASCII") ; + } + catch( Exception ex) + { + return str.getBytes() ; + } + } + + /** * Helper method for toString() * @param s source string * @param f string to remove diff -NEwBatru '--tabsize=8' --strip-trailing-cr gnujpdf-1.7.0/src/gnu/jpdf/makefile gnujpdf-1.7.1/src/gnu/jpdf/makefile --- gnujpdf-1.7.0/src/gnu/jpdf/makefile 1970-01-01 01:00:00.000000000 +0100 +++ gnujpdf-1.7.1/src/gnu/jpdf/makefile 2012-06-09 15:34:41.000000000 +0200 @@ -0,0 +1,4 @@ +JFILES = BoundingBox.java PDFAnnot.java PDFBorder.java PDFCatalog.java PDFDocument.java PDFFont.java PDFGraphics.java PDFImage.java PDFInfo.java PDFJob.java PDFObject.java PDFOutline.java PDFOutput.java PDFPage.java PDFPageList.java PDFPrinterJob.java PDFStream.java PDFStringHelper.java PDFXref.java StringTooLongException.java + +all: $(JFILES) + javac -classpath . $(JFILES)