working on scripting engine
This commit is contained in:
parent
0e30fc69df
commit
86c1f6ed9d
40 changed files with 170 additions and 158 deletions
|
@ -198,10 +198,12 @@ public class Document implements Closeable, RenderListener {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save(OutputStream outputStream) throws IOException {
|
public synchronized Document save(OutputStream outputStream) throws IOException {
|
||||||
if (pdDocument != null) {
|
if (pdDocument != null && outputStream != null) {
|
||||||
pdDocument.save(outputStream);
|
pdDocument.save(outputStream);
|
||||||
|
outputStream.close();
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.xbib.graphics.pdfbox.layout.font;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order to easy handling with fonts, this enum bundles the
|
* In order to easy handling with fonts, this enum bundles the
|
||||||
* plain/italic/bold/bold-italic variants of the three standard font types
|
* plain/italic/bold/bold-italic variants of the three standard font types
|
||||||
|
@ -54,5 +56,4 @@ public enum BaseFont implements Font {
|
||||||
public PDFont getBoldItalicFont() {
|
public PDFont getBoldItalicFont() {
|
||||||
return boldItalicFont;
|
return boldItalicFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for a Font and size.
|
* A descriptor for a font and a size, and activated attributes for font selection.
|
||||||
*/
|
*/
|
||||||
public class FontDescriptor {
|
public class FontDescriptor {
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,23 @@ package org.xbib.graphics.pdfbox.layout.font;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public enum Fonts {
|
public enum Fonts {
|
||||||
HELVETICA,
|
HELVETICA,
|
||||||
TIMES,
|
TIMES,
|
||||||
COURIER,
|
COURIER,
|
||||||
NOTOSANS;
|
NOTOSANS;
|
||||||
|
|
||||||
|
private final Map<String, Font> map = new HashMap<>();
|
||||||
|
|
||||||
public Font getFont(Document document) {
|
public Font getFont(Document document) {
|
||||||
if ("notosans".equalsIgnoreCase(name())) {
|
return map.computeIfAbsent(name(), name -> {
|
||||||
return new NotoSansFont(document);
|
if ("notosans".equalsIgnoreCase(name())) {
|
||||||
}
|
return new NotoSansFont(document);
|
||||||
return BaseFont.valueOf(name());
|
}
|
||||||
|
return BaseFont.valueOf(name());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@ public class NotoSansFont implements Font {
|
||||||
|
|
||||||
private final PDDocument pdDocument;
|
private final PDDocument pdDocument;
|
||||||
|
|
||||||
private static PDType0Font regular;
|
private PDType0Font regular;
|
||||||
|
|
||||||
private static PDType0Font bold;
|
private PDType0Font bold;
|
||||||
|
|
||||||
private static PDType0Font italic;
|
private PDType0Font italic;
|
||||||
|
|
||||||
private static PDType0Font bolditalic;
|
private PDType0Font bolditalic;
|
||||||
|
|
||||||
public NotoSansFont(Document document) {
|
public NotoSansFont(Document document) {
|
||||||
this.pdDocument = document.getPdDocument();
|
this.pdDocument = document.getPdDocument();
|
||||||
|
@ -27,7 +27,7 @@ public class NotoSansFont implements Font {
|
||||||
@Override
|
@Override
|
||||||
public PDFont getRegularFont() {
|
public PDFont getRegularFont() {
|
||||||
if (regular == null) {
|
if (regular == null) {
|
||||||
regular = load("NotoSans-Regular.ttf");
|
regular = load("NotoSans-Regular.ttf");
|
||||||
}
|
}
|
||||||
return regular;
|
return regular;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,14 @@ package org.xbib.graphics.pdfbox.layout.script;
|
||||||
import org.xbib.graphics.pdfbox.layout.script.command.Command;
|
import org.xbib.graphics.pdfbox.layout.script.command.Command;
|
||||||
import org.xbib.settings.Settings;
|
import org.xbib.settings.Settings;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Engine implements Closeable {
|
||||||
|
|
||||||
public class Engine {
|
|
||||||
private final String packageName;
|
private final String packageName;
|
||||||
|
|
||||||
private final ClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
@ -24,14 +28,23 @@ public class Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(String prefix, State state, Settings settings) throws IOException {
|
public void execute(String prefix, State state, Settings settings) throws IOException {
|
||||||
Settings subSettings = settings.getByPrefix(prefix);
|
execute(List.of(prefix), state, settings);
|
||||||
Set<String> set = subSettings.getAsStructuredMap().keySet();
|
}
|
||||||
for (String string : set) {
|
|
||||||
|
public void execute(List<String> prefixes, State state, Settings settings) throws IOException {
|
||||||
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
for (String prefix : prefixes) {
|
||||||
|
Settings subSettings = settings.getByPrefix(prefix);
|
||||||
|
for (String string : subSettings.getAsStructuredMap().keySet()) {
|
||||||
|
map.put(prefix + string, prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Settings thisSettings = settings.getAsSettings(prefix + string);
|
Settings thisSettings = settings.getAsSettings(entry.getKey());
|
||||||
String type = thisSettings.get("type");
|
String type = thisSettings.get("type");
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = prefix;
|
type = entry.getValue();
|
||||||
}
|
}
|
||||||
String className = packageName + ".command." + type.substring(0, 1).toUpperCase() + type.substring(1) + "Command";
|
String className = packageName + ".command." + type.substring(0, 1).toUpperCase() + type.substring(1) + "Command";
|
||||||
Class<?> cl = classLoader.loadClass(className);
|
Class<?> cl = classLoader.loadClass(className);
|
||||||
|
@ -43,6 +56,10 @@ public class Engine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
public State getState() {
|
public State getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,17 @@ package org.xbib.graphics.pdfbox.layout.script;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.PathElement;
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public class State {
|
public class State {
|
||||||
|
|
||||||
public Document document;
|
public Stack<Document> documents = new Stack<>();
|
||||||
|
|
||||||
public Paragraph paragraph;
|
public Stack<Paragraph> paragraphs = new Stack<>();
|
||||||
|
|
||||||
public PathElement pathElement;
|
|
||||||
|
|
||||||
|
public Collection<Document> getDocuments() {
|
||||||
|
return documents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,6 @@ public class BarcodeCommand implements Command {
|
||||||
if (settings.containsSetting("scale")) {
|
if (settings.containsSetting("scale")) {
|
||||||
element.setScale(settings.getAsFloat("scale", element.getScale()));
|
element.setScale(settings.getAsFloat("scale", element.getScale()));
|
||||||
}
|
}
|
||||||
state.document.add(element);
|
state.documents.peek().add(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class DocumentCommand implements Command {
|
||||||
.pageFormat(settings.get("format", "A4"))
|
.pageFormat(settings.get("format", "A4"))
|
||||||
.orientation(settings.get("orientiation", "PORTRAIT"))
|
.orientation(settings.get("orientiation", "PORTRAIT"))
|
||||||
.build();
|
.build();
|
||||||
state.document = new Document(pageFormat);
|
state.documents.push(new Document(pageFormat));
|
||||||
engine.execute("image", state, settings);
|
engine.execute("image", state, settings);
|
||||||
engine.execute("barcode", state, settings);
|
engine.execute("barcode", state, settings);
|
||||||
engine.execute("path", state, settings);
|
engine.execute("path", state, settings);
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.xbib.graphics.pdfbox.layout.script.command;
|
||||||
|
|
||||||
|
import org.xbib.graphics.pdfbox.layout.color.ColorFactory;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.elements.HorizontalRuler;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.script.Engine;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.script.State;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.shape.Stroke;
|
||||||
|
import org.xbib.settings.Settings;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class HorizontalrulerCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public void execute(Engine engine, State state, Settings settings) throws IOException {
|
||||||
|
Stroke.StrokeBuilder strokeBuilder = Stroke.builder()
|
||||||
|
.capStyle(Stroke.CapStyle.valueOf(settings.get("capstyie", "Cap")))
|
||||||
|
.joinStyle(Stroke.JoinStyle.valueOf(settings.get("joinstyle", "Miter")))
|
||||||
|
.lineWidth(settings.getAsFloat("linewidth", 1f));
|
||||||
|
if (settings.containsSetting("dash")) {
|
||||||
|
strokeBuilder.dashPattern(new Stroke.DashPattern(settings.getAsFloat("dash", 1f)));
|
||||||
|
}
|
||||||
|
Color color = ColorFactory.web(settings.get("color", "black"));
|
||||||
|
HorizontalRuler horizontalRuler = new HorizontalRuler(strokeBuilder.build(), color);
|
||||||
|
state.documents.peek().add(horizontalRuler);
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,6 @@ public class ImageCommand implements Command {
|
||||||
if (settings.containsSetting("scale")) {
|
if (settings.containsSetting("scale")) {
|
||||||
element.setScale(settings.getAsFloat("scale", element.getScale()));
|
element.setScale(settings.getAsFloat("scale", element.getScale()));
|
||||||
}
|
}
|
||||||
state.document.add(element, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true));
|
state.documents.peek().add(element, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,15 @@ public class ParagraphCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Engine engine, State state, Settings settings) throws IOException {
|
public void execute(Engine engine, State state, Settings settings) throws IOException {
|
||||||
state.paragraph = new Paragraph();
|
Paragraph paragraph = new Paragraph();
|
||||||
|
state.paragraphs.push(paragraph);
|
||||||
if (settings.containsSetting("x") && settings.containsSetting("y")) {
|
if (settings.containsSetting("x") && settings.containsSetting("y")) {
|
||||||
state.paragraph.setAbsolutePosition(new Position(settings.getAsFloat("x", 0f), settings.getAsFloat("y", 0f)));
|
paragraph.setAbsolutePosition(new Position(settings.getAsFloat("x", 0f), settings.getAsFloat("y", 0f)));
|
||||||
}
|
}
|
||||||
if (settings.containsSetting("width")) {
|
if (settings.containsSetting("width")) {
|
||||||
state.paragraph.setMaxWidth(settings.getAsFloat("width", state.document.getPageWidth()));
|
paragraph.setMaxWidth(settings.getAsFloat("width", state.documents.peek().getPageWidth()));
|
||||||
}
|
}
|
||||||
state.document.add(state.paragraph);
|
state.documents.peek().add(paragraph);
|
||||||
engine.execute("text", state, settings);
|
engine.execute("text", state, settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,6 @@ public class PathCommand implements Command {
|
||||||
strokeBuilder.dashPattern(new Stroke.DashPattern(settings.getAsFloat("dash", 1f)));
|
strokeBuilder.dashPattern(new Stroke.DashPattern(settings.getAsFloat("dash", 1f)));
|
||||||
}
|
}
|
||||||
Color color = ColorFactory.web(settings.get("color", "black"));
|
Color color = ColorFactory.web(settings.get("color", "black"));
|
||||||
state.document.add(new PathElement(path, strokeBuilder.build(), color, position));
|
state.documents.peek().add(new PathElement(path, strokeBuilder.build(), color, position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,12 @@ import org.xbib.graphics.pdfbox.layout.script.State;
|
||||||
import org.xbib.settings.Settings;
|
import org.xbib.settings.Settings;
|
||||||
|
|
||||||
public class TextCommand implements Command {
|
public class TextCommand implements Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Engine engine, State state, Settings settings) {
|
public void execute(Engine engine, State state, Settings settings) {
|
||||||
String value = settings.get("value");
|
String value = settings.get("value");
|
||||||
float size = settings.getAsFloat("size", 12.0f);
|
float size = settings.getAsFloat("size", 11.0f);
|
||||||
Font font = Fonts.valueOf(settings.get("font", "HELVETICA")).getFont(state.document);
|
Font font = Fonts.valueOf(settings.get("font", "HELVETICA")).getFont(state.documents.peek());
|
||||||
state.paragraph.addMarkup(value, size, font);
|
state.paragraphs.peek().addMarkup(value, size, font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,6 @@ import java.awt.Color;
|
||||||
*/
|
*/
|
||||||
public class ControlFragment implements TextFragment {
|
public class ControlFragment implements TextFragment {
|
||||||
|
|
||||||
protected final static FontDescriptor DEFAULT_FONT_DESCRIPTOR =
|
|
||||||
new FontDescriptor(BaseFont.HELVETICA, 11);
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.xbib.graphics.pdfbox.layout.text;
|
package org.xbib.graphics.pdfbox.layout.text;
|
||||||
|
|
||||||
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
import org.xbib.graphics.pdfbox.layout.font.FontDescriptor;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -10,10 +11,12 @@ import java.io.UncheckedIOException;
|
||||||
*/
|
*/
|
||||||
public class Indent extends ControlFragment {
|
public class Indent extends ControlFragment {
|
||||||
|
|
||||||
|
public static final FontDescriptor DEFAULT_FONT_DESCRIPTOR = new FontDescriptor(BaseFont.HELVETICA, 11);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant for the indentation of 0.
|
* Constant for the indentation of 0.
|
||||||
*/
|
*/
|
||||||
public final static Indent UNINDENT = new Indent(0);
|
public static final Indent UNINDENT = new Indent(0);
|
||||||
|
|
||||||
protected Alignment alignment = Alignment.LEFT;
|
protected Alignment alignment = Alignment.LEFT;
|
||||||
|
|
||||||
|
@ -31,7 +34,7 @@ public class Indent extends ControlFragment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new line with the
|
* Creates a new line with the
|
||||||
* {@link ControlFragment#DEFAULT_FONT_DESCRIPTOR}'s font and the given
|
* {@link #DEFAULT_FONT_DESCRIPTOR}'s font and the given
|
||||||
* height.
|
* height.
|
||||||
*
|
*
|
||||||
* @param label the label of the indentation.
|
* @param label the label of the indentation.
|
||||||
|
@ -45,7 +48,7 @@ public class Indent extends ControlFragment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new line with the
|
* Creates a new line with the
|
||||||
* {@link ControlFragment#DEFAULT_FONT_DESCRIPTOR}'s font and the given
|
* {@link #DEFAULT_FONT_DESCRIPTOR}'s font and the given
|
||||||
* height.
|
* height.
|
||||||
*
|
*
|
||||||
* @param label the label of the indentation.
|
* @param label the label of the indentation.
|
||||||
|
|
|
@ -72,24 +72,19 @@ public class TextFlow implements TextSequence, WidthRespecting {
|
||||||
add(TextFlowUtil.createTextFlow(text, new FontDescriptor(font, fontSize)));
|
add(TextFlowUtil.createTextFlow(text, new FontDescriptor(font, fontSize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void addMarkup(String markup, FontDescriptor fontDescriptor) {
|
||||||
* Adds some markup to the text flow.
|
add(TextFlowUtil.createTextFlowFromMarkup(markup, fontDescriptor));
|
||||||
*
|
}
|
||||||
* @param markup the markup to add.
|
|
||||||
* @param fontSize the font size to use.
|
|
||||||
* @param font the font
|
|
||||||
*/
|
|
||||||
public void addMarkup(String markup, float fontSize, Font font) {
|
public void addMarkup(String markup, float fontSize, Font font) {
|
||||||
add(TextFlowUtil.createTextFlowFromMarkup(markup, new FontDescriptor(font, fontSize)));
|
add(TextFlowUtil.createTextFlowFromMarkup(markup, new FontDescriptor(font, fontSize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit,
|
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, Font font) {
|
||||||
float fontsize, Font font) {
|
|
||||||
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(font, fontsize)));
|
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(font, fontsize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit,
|
public void addIndent(String label, float indentWidth, SpaceUnit indentUnit, float fontsize, Font font, Alignment alignment) {
|
||||||
float fontsize, Font font, Alignment alignment) {
|
|
||||||
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(font, fontsize), alignment));
|
add(new Indent(label, indentWidth, indentUnit, new FontDescriptor(font, fontsize), alignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,6 @@ public class AlignedTest {
|
||||||
paragraph.setMaxWidth(40);
|
paragraph.setMaxWidth(40);
|
||||||
document.add(paragraph, VerticalLayoutHint.CENTER);
|
document.add(paragraph, VerticalLayoutHint.CENTER);
|
||||||
OutputStream outputStream = new FileOutputStream("build/aligned.pdf");
|
OutputStream outputStream = new FileOutputStream("build/aligned.pdf");
|
||||||
document.render().save(outputStream);
|
document.render().save(outputStream).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,6 @@ public class ColumnsTest {
|
||||||
document.add(paragraph3);
|
document.add(paragraph3);
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
final OutputStream outputStream = new FileOutputStream("build/columns.pdf");
|
document.render().save(new FileOutputStream("build/columns.pdf")).close();
|
||||||
document.render().save(outputStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,8 +214,7 @@ public class CustomAnnotationTest {
|
||||||
10, BaseFont.HELVETICA);
|
10, BaseFont.HELVETICA);
|
||||||
paragraph.setMaxWidth(150);
|
paragraph.setMaxWidth(150);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
final OutputStream outputStream = new FileOutputStream("build/customannotation.pdf");
|
document.render().save(new FileOutputStream("build/customannotation.pdf")).close();
|
||||||
document.render().save(outputStream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PDColor toPDColor(final Color color) {
|
private static PDColor toPDColor(final Color color) {
|
||||||
|
|
|
@ -22,9 +22,8 @@ import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class CustomRenderer {
|
public class CustomRendererTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
@ -67,10 +66,7 @@ public class CustomRenderer {
|
||||||
document.add(new Section(3));
|
document.add(new Section(3));
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
document.render().save(new FileOutputStream("build/customrenderer.pdf")).close();
|
||||||
final OutputStream outputStream = new FileOutputStream("build/customrenderer.pdf");
|
|
||||||
document.render().save(outputStream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SectionRenderer implements Renderer, RenderListener {
|
public static class SectionRenderer implements Renderer, RenderListener {
|
|
@ -38,7 +38,6 @@ public class FramesTest {
|
||||||
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n";
|
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n";
|
||||||
|
|
||||||
Document document = new Document(PageFormats.A5_PORTRAIT);
|
Document document = new Document(PageFormats.A5_PORTRAIT);
|
||||||
|
|
||||||
Paragraph paragraph = new Paragraph();
|
Paragraph paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("Am I living in a box?", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Am I living in a box?", 11, BaseFont.TIMES);
|
||||||
Frame frame = new Frame(paragraph);
|
Frame frame = new Frame(paragraph);
|
||||||
|
@ -47,7 +46,6 @@ public class FramesTest {
|
||||||
frame.setPadding(10, 10, 5, 5);
|
frame.setPadding(10, 10, 5, 5);
|
||||||
frame.setMargin(40, 40, 20, 10);
|
frame.setMargin(40, 40, 20, 10);
|
||||||
document.add(frame, VerticalLayoutHint.CENTER);
|
document.add(frame, VerticalLayoutHint.CENTER);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
||||||
frame = new Frame(paragraph, 200f, null);
|
frame = new Frame(paragraph, 200f, null);
|
||||||
|
@ -56,7 +54,6 @@ public class FramesTest {
|
||||||
frame.setPadding(10, 10, 5, 5);
|
frame.setPadding(10, 10, 5, 5);
|
||||||
frame.setMargin(40, 40, 20, 10);
|
frame.setMargin(40, 40, 20, 10);
|
||||||
document.add(frame);
|
document.add(frame);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("{color:#aa00aa}*Ain't no rectangle*", 22, BaseFont.HELVETICA);
|
paragraph.addMarkup("{color:#aa00aa}*Ain't no rectangle*", 22, BaseFont.HELVETICA);
|
||||||
paragraph.setAlignment(Alignment.CENTER);
|
paragraph.setAlignment(Alignment.CENTER);
|
||||||
|
@ -66,7 +63,6 @@ public class FramesTest {
|
||||||
frame.setBackgroundColor(Color.pink);
|
frame.setBackgroundColor(Color.pink);
|
||||||
frame.setPadding(50, 0, 35, 0);
|
frame.setPadding(50, 0, 35, 0);
|
||||||
document.add(frame);
|
document.add(frame);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("Frames also paginate, see here:\n\n", 13, BaseFont.TIMES);
|
paragraph.addMarkup("Frames also paginate, see here:\n\n", 13, BaseFont.TIMES);
|
||||||
paragraph.addMarkup(text2, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text2, 11, BaseFont.TIMES);
|
||||||
|
@ -77,14 +73,11 @@ public class FramesTest {
|
||||||
frame.setBackgroundColor(new Color(255, 240, 180));
|
frame.setBackgroundColor(new Color(255, 240, 180));
|
||||||
frame.setPadding(20, 15, 10, 15);
|
frame.setPadding(20, 15, 10, 15);
|
||||||
frame.setMargin(50, 50, 20, 10);
|
frame.setMargin(50, 50, 20, 10);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup(text2, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text2, 11, BaseFont.TIMES);
|
||||||
paragraph.addMarkup(text2, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text2, 11, BaseFont.TIMES);
|
||||||
frame.add(paragraph);
|
frame.add(paragraph);
|
||||||
|
|
||||||
document.add(frame);
|
document.add(frame);
|
||||||
|
document.render().save(new FileOutputStream("build/frames.pdf")).close();
|
||||||
document.render().save(new FileOutputStream("build/frames.pdf"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.Indent;
|
import org.xbib.graphics.pdfbox.layout.text.Indent;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
|
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class HelloBarcodeTest {
|
public class HelloBarcodeTest {
|
||||||
|
|
||||||
|
@ -31,7 +30,6 @@ public class HelloBarcodeTest {
|
||||||
symbol.setHumanReadableLocation(HumanReadableLocation.BOTTOM);
|
symbol.setHumanReadableLocation(HumanReadableLocation.BOTTOM);
|
||||||
BarcodeElement barcodeElement = new BarcodeElement(symbol);
|
BarcodeElement barcodeElement = new BarcodeElement(symbol);
|
||||||
document.add(barcodeElement, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true));
|
document.add(barcodeElement, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true));
|
||||||
OutputStream outputStream = new FileOutputStream("build/hellobarcode.pdf");
|
document.render().save(new FileOutputStream("build/hellobarcode.pdf")).close();
|
||||||
document.render().save(outputStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import org.xbib.graphics.pdfbox.layout.elements.render.VerticalLayoutHint;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.Alignment;
|
import org.xbib.graphics.pdfbox.layout.text.Alignment;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
public class HelloCatTest {
|
public class HelloCatTest {
|
||||||
|
@ -22,7 +21,6 @@ public class HelloCatTest {
|
||||||
ImageElement imageElement = new ImageElement(ImageIO.read(getClass().getResourceAsStream("cat.jpg")));
|
ImageElement imageElement = new ImageElement(ImageIO.read(getClass().getResourceAsStream("cat.jpg")));
|
||||||
imageElement.setScale(0.1f);
|
imageElement.setScale(0.1f);
|
||||||
document.add(imageElement, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true));
|
document.add(imageElement, new VerticalLayoutHint(Alignment.LEFT, 10, 10, 10, 10, true));
|
||||||
final OutputStream outputStream = new FileOutputStream("build/hellocat.pdf");
|
document.render().save(new FileOutputStream("build/hellocat.pdf")).close();
|
||||||
document.render().save(outputStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,15 @@ import org.xbib.graphics.pdfbox.layout.elements.Document;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class HelloDoc {
|
public class HelloDocTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
Document document = new Document(40, 60, 40, 60);
|
Document document = new Document(40, 60, 40, 60);
|
||||||
|
|
||||||
Paragraph paragraph = new Paragraph();
|
Paragraph paragraph = new Paragraph();
|
||||||
paragraph.addText("Hello Document", 20, BaseFont.HELVETICA);
|
paragraph.addText("Hello Document", 20, BaseFont.HELVETICA);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
final OutputStream outputStream = new FileOutputStream("build/hellodoc.pdf");
|
document.render().save(new FileOutputStream("build/hellodoc.pdf")).close();
|
||||||
document.render().save(outputStream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,11 +4,11 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
import org.xbib.graphics.pdfbox.layout.elements.Document;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.PageFormats;
|
import org.xbib.graphics.pdfbox.layout.elements.PageFormats;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
||||||
|
import org.xbib.graphics.pdfbox.layout.font.Font;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.NotoSansFont;
|
import org.xbib.graphics.pdfbox.layout.font.NotoSansFont;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.Indent;
|
import org.xbib.graphics.pdfbox.layout.text.Indent;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
|
import org.xbib.graphics.pdfbox.layout.text.SpaceUnit;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class HelloNotoFontTest {
|
public class HelloNotoFontTest {
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ public class HelloNotoFontTest {
|
||||||
Document document = new Document(PageFormats.A4_PORTRAIT);
|
Document document = new Document(PageFormats.A4_PORTRAIT);
|
||||||
Paragraph paragraph = new Paragraph();
|
Paragraph paragraph = new Paragraph();
|
||||||
paragraph.add(new Indent(32, SpaceUnit.pt));
|
paragraph.add(new Indent(32, SpaceUnit.pt));
|
||||||
paragraph.addMarkup("Hello Noto Regular\n", 12, new NotoSansFont(document));
|
Font font = new NotoSansFont(document);
|
||||||
paragraph.addMarkup("*Hello Noto Bold*\n", 12, new NotoSansFont(document));
|
paragraph.addMarkup("Hello Noto Regular\n", 12, font);
|
||||||
paragraph.addMarkup("_Hello Noto Italic_\n", 12, new NotoSansFont(document));
|
paragraph.addMarkup("*Hello Noto Bold*\n", 12, font);
|
||||||
paragraph.addMarkup("*_Hello Noto Bold Italic_*\n", 12, new NotoSansFont(document));
|
paragraph.addMarkup("_Hello Noto Italic_\n", 12, font);
|
||||||
|
paragraph.addMarkup("*_Hello Noto Bold Italic_*\n", 12, font);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
final OutputStream outputStream = new FileOutputStream("build/hellonotofont.pdf");
|
document.render().save(new FileOutputStream("build/hellonotofont.pdf")).close();
|
||||||
document.render().save(outputStream);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.xbib.graphics.pdfbox.layout.util.Enumerators.LowerCaseAlphabeticEnume
|
||||||
import org.xbib.graphics.pdfbox.layout.util.Enumerators.LowerCaseRomanEnumerator;
|
import org.xbib.graphics.pdfbox.layout.util.Enumerators.LowerCaseRomanEnumerator;
|
||||||
import org.xbib.graphics.pdfbox.layout.util.Enumerators.RomanEnumerator;
|
import org.xbib.graphics.pdfbox.layout.util.Enumerators.RomanEnumerator;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class IndentationTest {
|
public class IndentationTest {
|
||||||
|
|
||||||
|
@ -21,7 +20,6 @@ public class IndentationTest {
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
String bulletOdd = getBulletCharacter(1) + " ";
|
String bulletOdd = getBulletCharacter(1) + " ";
|
||||||
String bulletEven = getBulletCharacter(2) + " ";
|
String bulletEven = getBulletCharacter(2) + " ";
|
||||||
|
|
||||||
Document document = new Document(40, 60, 40, 60);
|
Document document = new Document(40, 60, 40, 60);
|
||||||
Paragraph paragraph = new Paragraph();
|
Paragraph paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("This is an example for the new indent feature. Let's do some empty space indentation:\n",
|
paragraph.addMarkup("This is an example for the new indent feature. Let's do some empty space indentation:\n",
|
||||||
|
@ -33,36 +31,27 @@ public class IndentationTest {
|
||||||
paragraph.add(new Indent(70, SpaceUnit.pt));
|
paragraph.add(new Indent(70, SpaceUnit.pt));
|
||||||
paragraph.addMarkup("any new indent comes.\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("any new indent comes.\n", 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("New paragraph, now indentation is gone. But we can indent with a label also:\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("New paragraph, now indentation is gone. But we can indent with a label also:\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent("This is some label", 100, SpaceUnit.pt, 11, BaseFont.TIMES);
|
paragraph.addIndent("This is some label", 100, SpaceUnit.pt, 11, BaseFont.TIMES);
|
||||||
paragraph.addMarkup("Here we go indented.\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Here we go indented.\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addMarkup("And again, the Indentation holds for the rest of the paragraph, or any new indent comes.\nLabels can be aligned:\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("And again, the Indentation holds for the rest of the paragraph, or any new indent comes.\nLabels can be aligned:\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent("Left", 100, SpaceUnit.pt, 11, BaseFont.TIMES, Alignment.LEFT);
|
paragraph.addIndent("Left", 100, SpaceUnit.pt, 11, BaseFont.TIMES, Alignment.LEFT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.LEFT));
|
|
||||||
paragraph.addMarkup("Indent with label aligned to the left.\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Indent with label aligned to the left.\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent("Center", 100, SpaceUnit.pt, 11, BaseFont.TIMES, Alignment.CENTER);
|
paragraph.addIndent("Center", 100, SpaceUnit.pt, 11, BaseFont.TIMES, Alignment.CENTER);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.CENTER));
|
|
||||||
paragraph.addMarkup("Indent with label aligned to the center.\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Indent with label aligned to the center.\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent("Right", 100, SpaceUnit.pt, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent("Right", 100, SpaceUnit.pt, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("Indent with label aligned to the right.\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Indent with label aligned to the right.\n", 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
paragraph.addMarkup("So, what can you do with that? How about lists:\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("So, what can you do with that? How about lists:\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(bulletOdd, 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(bulletOdd, 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("This is a list item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("This is a list item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(bulletOdd, 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(bulletOdd, 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("Another list item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Another list item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(bulletEven, 8, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(bulletEven, 8, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("Sub list item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Sub list item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(bulletOdd, 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(bulletOdd, 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("And yet another one\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("And yet another one\n", 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
|
@ -71,19 +60,14 @@ public class IndentationTest {
|
||||||
RomanEnumerator e1 = new RomanEnumerator();
|
RomanEnumerator e1 = new RomanEnumerator();
|
||||||
LowerCaseAlphabeticEnumerator e2 = new LowerCaseAlphabeticEnumerator();
|
LowerCaseAlphabeticEnumerator e2 = new LowerCaseAlphabeticEnumerator();
|
||||||
paragraph.addIndent(e1.next() + ". ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(e1.next() + ". ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("First item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("First item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(e1.next() + ". ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(e1.next() + ". ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("Second item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Second item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(e2.next() + ") ", 8, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(e2.next() + ") ", 8, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("A sub item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("A sub item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(e2.next() + ") ", 8, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(e2.next() + ") ", 8, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("Another sub item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Another sub item\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(e1.next() + ". ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(e1.next() + ". ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("Third item\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("Third item\n", 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
|
@ -91,23 +75,17 @@ public class IndentationTest {
|
||||||
paragraph.addMarkup("The following types are built in:\n", 11,
|
paragraph.addMarkup("The following types are built in:\n", 11,
|
||||||
BaseFont.TIMES);
|
BaseFont.TIMES);
|
||||||
paragraph.addIndent(new ArabicEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(new ArabicEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("ArabicEnumerator\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("ArabicEnumerator\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(new RomanEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(new RomanEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("RomanEnumerator\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("RomanEnumerator\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(new LowerCaseRomanEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(new LowerCaseRomanEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("LowerCaseRomanEnumerator\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("LowerCaseRomanEnumerator\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(new AlphabeticEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(new AlphabeticEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("AlphabeticEnumerator\n", 11, BaseFont.TIMES);
|
paragraph.addMarkup("AlphabeticEnumerator\n", 11, BaseFont.TIMES);
|
||||||
paragraph.addIndent(new LowerCaseAlphabeticEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
paragraph.addIndent(new LowerCaseAlphabeticEnumerator().next() + " ", 4, SpaceUnit.em, 11, BaseFont.TIMES, Alignment.RIGHT);
|
||||||
//PDType1Font.TIMES_BOLD, Alignment.RIGHT));
|
|
||||||
paragraph.addMarkup("LowerCaseAlphabeticEnumerator\n", 11,
|
paragraph.addMarkup("LowerCaseAlphabeticEnumerator\n", 11,
|
||||||
BaseFont.TIMES);
|
BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
paragraph = new Paragraph();
|
paragraph = new Paragraph();
|
||||||
String text1 = "For your convenience, you can do all that much easier with markup, e.g. simple indentation\n"
|
String text1 = "For your convenience, you can do all that much easier with markup, e.g. simple indentation\n"
|
||||||
+ "--At vero eos et accusam\n\n"
|
+ "--At vero eos et accusam\n\n"
|
||||||
|
@ -128,8 +106,7 @@ public class IndentationTest {
|
||||||
+ "-#{I ->:5}And yet another one\n\n";
|
+ "-#{I ->:5}And yet another one\n\n";
|
||||||
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
document.render().save(new FileOutputStream("build/indentation.pdf")).close();
|
||||||
document.render().save(new FileOutputStream("build/indentation.pdf"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getBulletCharacter(final int level) {
|
private static String getBulletCharacter(final int level) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.xbib.graphics.pdfbox.layout.elements.render.VerticalLayoutHint;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
public class Landscape {
|
public class LandscapeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void main() throws Exception {
|
public void main() throws Exception {
|
||||||
|
@ -103,6 +103,6 @@ public class Landscape {
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
document.add(paragraph3);
|
document.add(paragraph3);
|
||||||
|
|
||||||
document.render().save(new FileOutputStream("build/landscape.pdf"));
|
document.render().save(new FileOutputStream("build/landscape.pdf")).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,10 +12,9 @@ import org.xbib.graphics.pdfbox.layout.text.Position;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
public class Letter {
|
public class LetterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
@ -80,6 +79,6 @@ public class Letter {
|
||||||
paragraph.setAbsolutePosition(new Position(hMargin, vMargin));
|
paragraph.setAbsolutePosition(new Position(hMargin, vMargin));
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
document.render().save(new FileOutputStream("build/letter.pdf"));
|
document.render().save(new FileOutputStream("build/letter.pdf")).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,6 @@ import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.render.ColumnLayout;
|
import org.xbib.graphics.pdfbox.layout.elements.render.ColumnLayout;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class LineSpacingTest {
|
public class LineSpacingTest {
|
||||||
|
|
||||||
|
@ -44,9 +43,6 @@ public class LineSpacingTest {
|
||||||
|
|
||||||
document.add(right);
|
document.add(right);
|
||||||
document.add(right);
|
document.add(right);
|
||||||
|
document.render().save(new FileOutputStream("build/linespacing.pdf")).close();
|
||||||
final OutputStream outputStream = new FileOutputStream("build/linespacing.pdf");
|
|
||||||
document.render().save(outputStream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import org.xbib.graphics.pdfbox.layout.elements.Document;
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class LinksTest {
|
public class LinksTest {
|
||||||
|
|
||||||
|
@ -51,22 +50,16 @@ public class LinksTest {
|
||||||
|
|
||||||
Paragraph paragraph4 = new Paragraph();
|
Paragraph paragraph4 = new Paragraph();
|
||||||
paragraph4.addMarkup("\n\n{anchor:hello}Here{anchor} comes the internal anchor named *hello*\n\n", 15, BaseFont.COURIER);
|
paragraph4.addMarkup("\n\n{anchor:hello}Here{anchor} comes the internal anchor named *hello*\n\n", 15, BaseFont.COURIER);
|
||||||
|
|
||||||
document.add(paragraph1);
|
document.add(paragraph1);
|
||||||
document.add(paragraph3);
|
document.add(paragraph3);
|
||||||
document.add(paragraph1);
|
document.add(paragraph1);
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
document.add(paragraph1);
|
document.add(paragraph1);
|
||||||
document.add(paragraph3);
|
document.add(paragraph3);
|
||||||
|
|
||||||
document.add(paragraph4);
|
document.add(paragraph4);
|
||||||
|
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
document.add(paragraph1);
|
document.add(paragraph1);
|
||||||
document.add(paragraph1);
|
document.add(paragraph1);
|
||||||
|
document.render().save(new FileOutputStream("build/links.pdf")).close();
|
||||||
final OutputStream outputStream = new FileOutputStream("build/links.pdf");
|
|
||||||
document.render().save(outputStream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,8 @@ import org.xbib.graphics.pdfbox.layout.text.TextFlow;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil;
|
import org.xbib.graphics.pdfbox.layout.text.TextFlowUtil;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
|
import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class Listener {
|
public class ListenerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
@ -71,9 +70,6 @@ public class Listener {
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
document.render().save(new FileOutputStream("build/listener.pdf")).close();
|
||||||
final OutputStream outputStream = new FileOutputStream("build/listener.pdf");
|
|
||||||
document.render().save(outputStream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,6 @@ import org.xbib.graphics.pdfbox.layout.text.TextSequenceUtil;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
|
import org.xbib.graphics.pdfbox.layout.text.annotations.AnnotationDrawListener;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class LowLevelText {
|
public class LowLevelText {
|
||||||
|
|
||||||
|
@ -103,11 +102,8 @@ public class LowLevelText {
|
||||||
|
|
||||||
annotationDrawListener.afterPage(null);
|
annotationDrawListener.afterPage(null);
|
||||||
contentStream.close();
|
contentStream.close();
|
||||||
|
|
||||||
annotationDrawListener.afterRender();
|
annotationDrawListener.afterRender();
|
||||||
|
pdDocument.save(new FileOutputStream("build/lowleveltext.pdf"));
|
||||||
final OutputStream outputStream = new FileOutputStream("build/lowleveltext.pdf");
|
|
||||||
pdDocument.save(outputStream);
|
|
||||||
pdDocument.close();
|
pdDocument.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,8 @@ import org.xbib.graphics.pdfbox.layout.elements.render.VerticalLayoutHint;
|
||||||
import org.xbib.graphics.pdfbox.layout.text.Alignment;
|
import org.xbib.graphics.pdfbox.layout.text.Alignment;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class Margin {
|
public class MarginTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
|
@ -50,9 +49,6 @@ public class Margin {
|
||||||
paragraph.addText(text3, 11, BaseFont.HELVETICA);
|
paragraph.addText(text3, 11, BaseFont.HELVETICA);
|
||||||
document.add(paragraph, new VerticalLayoutHint(Alignment.RIGHT, 150,
|
document.add(paragraph, new VerticalLayoutHint(Alignment.RIGHT, 150,
|
||||||
150, 20, 0));
|
150, 20, 0));
|
||||||
|
document.render().save(new FileOutputStream("build/margin.pdf")).close();
|
||||||
final OutputStream outputStream = new FileOutputStream("build/margin.pdf");
|
|
||||||
document.render().save(outputStream);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -68,6 +68,6 @@ public class MarkupTest {
|
||||||
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
paragraph.addMarkup(text1, 11, BaseFont.TIMES);
|
||||||
document.add(paragraph);
|
document.add(paragraph);
|
||||||
|
|
||||||
document.render().save( new FileOutputStream("build/markup.pdf"));
|
document.render().save( new FileOutputStream("build/markup.pdf")).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,6 @@ public class MultiplePagesTest {
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
|
|
||||||
document.render().save(new FileOutputStream("build/multiplepages.pdf"));
|
document.render().save(new FileOutputStream("build/multiplepages.pdf")).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,6 @@ public class RotationTest {
|
||||||
document.add(paragraph2);
|
document.add(paragraph2);
|
||||||
document.add(paragraph3);
|
document.add(paragraph3);
|
||||||
|
|
||||||
document.render().save(new FileOutputStream("build/rotation.pdf"));
|
document.render().save(new FileOutputStream("build/rotation.pdf")).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,11 @@ package org.xbib.graphics.pdfbox.layout.test;
|
||||||
|
|
||||||
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
import org.xbib.graphics.pdfbox.layout.elements.Paragraph;
|
||||||
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
import org.xbib.graphics.pdfbox.layout.font.BaseFont;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class Section extends Paragraph {
|
public class Section extends Paragraph {
|
||||||
private final int number;
|
private final int number;
|
||||||
|
|
||||||
public Section(int number) throws IOException {
|
public Section(int number) {
|
||||||
super();
|
super();
|
||||||
this.number = number;
|
this.number = number;
|
||||||
addMarkup(String.format("*Section %d", number), 16, BaseFont.TIMES);
|
addMarkup(String.format("*Section %d", number), 16, BaseFont.TIMES);
|
||||||
|
|
|
@ -11,11 +11,14 @@ public class ScriptTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void script() throws Exception {
|
public void script() throws Exception {
|
||||||
Settings settings = Settings.settingsBuilder().loadFromResource("json", getClass().getResourceAsStream("script.json"))
|
Settings settings = Settings.settingsBuilder()
|
||||||
|
.loadFromResource("json", getClass().getResourceAsStream("script.json"))
|
||||||
.build();
|
.build();
|
||||||
Engine engine = new Engine();
|
Engine engine = new Engine();
|
||||||
engine.execute(settings);
|
engine.execute(settings);
|
||||||
Document document = engine.getState().document;
|
for (Document document : engine.getState().getDocuments()) {
|
||||||
document.render().save(new FileOutputStream("build/script.pdf"));
|
document.render().save(new FileOutputStream("build/script.pdf")).close();
|
||||||
|
}
|
||||||
|
engine.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,35 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"paragraph2": {
|
"paragraph2": {
|
||||||
|
"text1": {
|
||||||
|
"value": "Hello World",
|
||||||
|
"size": 24,
|
||||||
|
"font": "HELVETICA"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paragraph3": {
|
||||||
|
"text1": {
|
||||||
|
"value": "Hello World",
|
||||||
|
"size": 24,
|
||||||
|
"font": "HELVETICA"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"paragraph4": {
|
||||||
|
"type": "horizontalruler"
|
||||||
|
},
|
||||||
|
"paragraph5": {
|
||||||
"text1": {
|
"text1": {
|
||||||
"value": "*Hello World*",
|
"value": "*Hello World*",
|
||||||
"size": 16,
|
"size": 16,
|
||||||
"font": "NOTOSANS"
|
"font": "NOTOSANS"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"paragraph6": {
|
||||||
|
"text1": {
|
||||||
|
"value": "*Hello World*",
|
||||||
|
"size": 20,
|
||||||
|
"font": "NOTOSANS"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue