Java Tutorial/PDF/Viewer Preferences

Материал из Java эксперт
Версия от 05:21, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

display title, two page left

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer3 = PdfWriter.getInstance(document, new FileOutputStream(
    "2.pdf"));
    
    writer3.setPdfVersion(PdfWriter.VERSION_1_5);
    writer3.setViewerPreferences(PdfWriter.DisplayDocTitle | PdfWriter.PageLayoutTwoPageLeft);
    document.addTitle("Hello World");
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





Page Labels

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPageLabels;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("1. To the Universe:"));
    document.add(hello);
    PdfPageLabels pageLabels = new PdfPageLabels();
    pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
    pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
    pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);
    writer.setPageLabels(pageLabels);
    document.close();
  }
}





PdfWriter.HideMenubar | PdfWriter.CenterWindow

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer1 = PdfWriter.getInstance(document, new FileOutputStream(
    "2.pdf"));
    writer1.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.CenterWindow);
    document.addTitle("Hello World");
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.HideToolbar | PdfWriter.PageModeUseThumbs

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer4 = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer4.setViewerPreferences(PdfWriter.HideToolbar | PdfWriter.PageModeUseThumbs);
    document.addTitle("Hello World");
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.HideWindowUI | PdfWriter.FitWindow

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer2 = PdfWriter.getInstance(document,
        new FileOutputStream("2.pdf"));
    writer2.setViewerPreferences(PdfWriter.HideWindowUI | PdfWriter.FitWindow);
    document.addTitle("Hello World");
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.PageLayoutOneColumn

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer2 = PdfWriter.getInstance(document, new FileOutputStream("one_column.pdf"));
    writer2.setViewerPreferences(PdfWriter.PageLayoutOneColumn);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.PageLayoutTwoColumnLeft

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer3 = PdfWriter.getInstance(document, new FileOutputStream("two_column_left.pdf"));
    writer3.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.PageLayoutTwoColumnRight

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer4 = PdfWriter.getInstance(document,
        new FileOutputStream("two_column_right.pdf"));
    writer4.setViewerPreferences(PdfWriter.PageLayoutTwoColumnRight);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.PageLayoutTwoPageLeft

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer5 = PdfWriter.getInstance(document, new FileOutputStream("two_page_left.pdf"));
    writer5.setPdfVersion(PdfWriter.VERSION_1_5);
    writer5.setViewerPreferences(PdfWriter.PageLayoutTwoPageLeft);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.PageLayoutTwoPageRight

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer6 = PdfWriter.getInstance(document, new FileOutputStream("two_page_right.pdf"));
    writer6.setPdfVersion(PdfWriter.VERSION_1_5);
    writer6.setViewerPreferences(PdfWriter.PageLayoutTwoPageRight);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





PdfWriter.PageModeUseOutlines | PdfWriter.PageLayoutTwoColumnRight

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer1 = PdfWriter.getInstance(document, new FileOutputStream(
        "2.pdf"));
    writer1
        .setViewerPreferences(PdfWriter.PageModeUseOutlines | PdfWriter.PageLayoutTwoColumnRight);
    document.open();
    PdfWriter writer2 = PdfWriter.getInstance(document, new FileOutputStream("full_screen.pdf"));
    writer2.setViewerPreferences(PdfWriter.PageModeFullScreen
        | PdfWriter.NonFullScreenPageModeUseOutlines);
    document.open();
    
    document.setPageSize(PageSize.A4.rotate());
    document.add(new Paragraph("adf"));
    document.close();
  }
}





Set Viewer Preferences

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer1 = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer1.setViewerPreferences(PdfWriter.PageLayoutSinglePage);
    document.open();
    Paragraph hello = new Paragraph("(English:) hello, ");
    document.add(new Paragraph("asdf"));
    document.add(hello);
    document.close();
  }
}





Slide Show

import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfTransition;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document(new Rectangle(144, 115));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    writer.setPdfVersion(PdfWriter.VERSION_1_5);
    writer.setViewerPreferences(PdfWriter.PageModeFullScreen);
    document.open();
    Image img0 = Image.getInstance("0.gif");
    img0.setAbsolutePosition(0, 0);
    writer.setTransition(new PdfTransition(PdfTransition.OUTBOX, 3));
    document.add(img0);
    document.newPage();
    Image img1 = Image.getInstance("1.gif");
    img1.setAbsolutePosition(0, 0);
    writer.setTransition(new PdfTransition(PdfTransition.INBOX, 2));
    writer.setDuration(1);
    document.add(img1);
    document.newPage();
    document.close();
  }
}