* 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.
package org.apache.fop.pdf;
-// Java
+/// Java
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Iterator;
import java.util.ArrayList;
+import java.util.Collections;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.fop.pdf.DestinationComparator;
+
/* image support modified from work of BoBoGi */
/* font support based on work by Takayuki Takeuchi */
public class PDFDocument {
private static final Integer LOCATION_PLACEHOLDER = new Integer(0);
-
+
/** Integer constant to represent PDF 1.3 */
public static final int PDF_VERSION_1_3 = 3;
/** Integer constant to represent PDF 1.4 */
public static final int PDF_VERSION_1_4 = 4;
-
+
/**
* the encoding to use when converting strings to PDF commandos.
*/
/** Indicates what PDF version is active */
protected int pdfVersion = PDF_VERSION_1_4;
-
+
/**
* Indicates which PDF profiles are active (PDF/A, PDF/X etc.)
*/
protected PDFProfile pdfProfile = new PDFProfile(this);
-
+
/**
* the /Root object
*/
public int getPDFVersion() {
return this.pdfVersion;
}
-
+
/** @return the String representing the active PDF version */
public String getPDFVersionString() {
switch (getPDFVersion()) {
public PDFProfile getProfile() {
return this.pdfProfile;
}
-
+
/**
* Returns the factory for PDF objects.
* @return PDFFactory the factory
/**
* Set the creation date of the document.
- *
+ *
* @param date Date to be stored as creation date in the PDF.
*/
public void setCreationDate(Date date) {
this.position = 0;
getProfile().verifyPDFVersion();
-
+
byte[] pdf = ("%PDF-" + getPDFVersionString() + "\n").getBytes();
stream.write(pdf);
this.position += pdf.length;
}
}
}
-
+
/**
* write the trailer
*
*/
public void outputTrailer(OutputStream stream) throws IOException {
if (hasDestinations) {
+ Collections.sort((ArrayList)destinations, new DestinationComparator());
limits = getFactory().makeLimits((ArrayList)destinations);
dests = getFactory().makeDests(limits.referencePDF());
this.root.setNames(dests.referencePDF());
return pdfBytes.length;
}
-}
+}
\ No newline at end of file