Skip to content

Commit

Permalink
Merge pull request #2 from zilverline/upgrade-fop-scala-java
Browse files Browse the repository at this point in the history
Upgrade fop to fix transparant logo bug
  • Loading branch information
lvonk authored Nov 30, 2016
2 parents afc3ec8 + 3c109be commit dac162d
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 90 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ The server uses the [Unfiltered](http://unfiltered.databinder.net/) Scala HTTP s

Testing is done using the [Dispatch](http://dispatch.databinder.net/) HTTP client library.

### How to build

mvn assembly:assembly

### How to use
Download one of the tar.gz from the downloads page

tar xvzf apache-server-fop-[version].tar.gz
./apache-fop-server start

This will start the server in the background and will lsiten on port 9999. To stop the server you can use:
tar xvzf apache-fop-server-[version].tar.gz
java -cp apache-fop-server.jar:lib/* org.zilverline.fop.FopServer

./apache-fop-server stop
This will start the server on port 9999.

To generate a pdf one should POST to `http://localhost:9999/pdf` with 2 parameters: `xml` containing the XML representation of the pdf and `xsl` as the stylesheet to be used.

Expand All @@ -39,7 +41,7 @@ Example on how to use in Ruby using httpclient

An example upstart script for installing this on the server could be

# apache-fop-server - simple webserver to enable generation of pdfs
# apache-fop-server - simple webserver to enable generation of pdfs
#
# Simple embedded Jetty server to enable generation of pdfs using apache-fop

Expand All @@ -48,11 +50,11 @@ An example upstart script for installing this on the server could be
start on runlevel [2345]
stop on runlevel [!2345]

expect fork
expect fork

script
chdir /opt/apps/apache-fop-server
exec sudo -u some-user ./apache-fop-server start
exec java -cp apache-fop-server.jar:lib/* org.zilverline.fop.FopServer
end script

Fork and patch to contribute!
Fork and patch to contribute!
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 17 additions & 17 deletions fop/fop-config.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<auto-detect/>
<fonts>
<font embed-url="res:font/Calibri.ttf">
<font-triplet name="Calibri" style="normal" weight="normal" />
<renderers>
<renderer mime="application/pdf">
<auto-detect/>
<fonts>
<font embed-url="font/Calibri.ttf">
<font-triplet name="Calibri" style="normal" weight="normal"/>
</font>
<font embed-url="res:font/Calibri Bold Italic.ttf">
<font-triplet name="Calibri" style="italic" weight="bold" />
<font embed-url="font/Calibri Bold Italic.ttf">
<font-triplet name="Calibri" style="italic" weight="bold"/>
</font>
<font embed-url="res:font/Calibri Bold.ttf">
<font-triplet name="Calibri" style="normal" weight="bold" />
<font embed-url="font/Calibri Bold.ttf">
<font-triplet name="Calibri" style="normal" weight="bold"/>
</font>
<font embed-url="res:font/Calibri Italic.ttf">
<font-triplet name="Calibri" style="italic" weight="normal" />
<font embed-url="font/Calibri Italic.ttf">
<font-triplet name="Calibri" style="italic" weight="normal"/>
</font>
<font embed-url="res:font/Calibri.ttf">
<font-triplet name="Calibri" style="normal" weight="normal" />
<font embed-url="font/Calibri.ttf">
<font-triplet name="Calibri" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fonts>
</renderer>
</renderers>
</fop>
81 changes: 31 additions & 50 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,17 @@
<packaging>jar</packaging>
<name>Apache FOP Server: ${project.artifactId}</name>
<properties>
<scala.version>2.10.1</scala.version>
<scala.binary.version>2.10</scala.binary.version>
<scala.version>2.11.7</scala.version>
<scala.binary.version>2.11</scala.binary.version>
<http.client.version>4.1.1</http.client.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>zilverline-nexus</id>
<name>zilverline-mirror</name>
<url>http://nexus.zilverline.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>zilverline-nexus</id>
<name>zilverline-mirror</name>
<url>http://nexus.zilverline.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<scm>
<connection>scm:git:git://github.com/zilverline/apache-fop-server.git</connection>
<developerConnection>scm:git:git@github.com:zilverline/apache-fop-server.git</developerConnection>
<url>https://github.com/zilverline/apache-fop-server</url>
<tag>HEAD</tag>
</scm>
<distributionManagement>
<repository>
<id>zilverline-releases</id>
<name>zilverline-releases</name>
<url>http://nexus.zilverline.com/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>zilverline-releases</id>
<name>zilverline-snapshots</name>
<url>http://nexus.zilverline.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -88,22 +49,22 @@
<dependency>
<groupId>net.databinder</groupId>
<artifactId>unfiltered_${scala.binary.version}</artifactId>
<version>0.6.7</version>
<version>0.8.4</version>
</dependency>
<dependency>
<groupId>net.databinder</groupId>
<artifactId>unfiltered-filter_${scala.binary.version}</artifactId>
<version>0.6.7</version>
<version>0.8.4</version>
</dependency>
<dependency>
<groupId>net.databinder</groupId>
<artifactId>unfiltered-jetty_${scala.binary.version}</artifactId>
<version>0.6.7</version>
<version>0.8.4</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>1.0</version>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand All @@ -118,7 +79,7 @@
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.binary.version}</artifactId>
<version>1.9.1</version>
<version>2.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -130,7 +91,7 @@
<dependency>
<groupId>net.databinder.dispatch</groupId>
<artifactId>dispatch-core_${scala.binary.version}</artifactId>
<version>0.9.5</version>
<version>0.11.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -233,7 +194,7 @@
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.3</version>
<version>3.2.2</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -271,8 +232,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -312,6 +273,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Name>font/Calibri Bold Italic.ttf</Name>
<Content-Type>application/x-font</Content-Type>
<Name>font/Calibri Bold.ttf</Name>
<Content-Type>application/x-font</Content-Type>
<Name>font/Calibri Italic.ttf</Name>
<Content-Type>application/x-font</Content-Type>
<Name>font/Calibri.ttf</Name>
<Content-Type>application/x-font</Content-Type>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
7 changes: 6 additions & 1 deletion src/main/scala/org/zilverline/fop/FopServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ object FopServer extends Logging {
}

def main(args: Array[String]): Unit = {
System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "4000000")
val maxSize = args match {
case Array(max) => max
case Array() => "4000000"
}

System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", maxSize)

unfiltered.jetty.Http.local(DefaultPort).filter(plan).run { server =>
sys.addShutdownHook(server.stop)
Expand Down
20 changes: 7 additions & 13 deletions src/main/scala/org/zilverline/fop/PdfDocument.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import javax.xml.transform.{Transformer, TransformerFactory, URIResolver}
import javax.xml.transform.sax.SAXResult
import javax.xml.transform.stream.StreamSource
import org.apache.commons.io.IOUtils
import org.apache.fop.apps.{Fop, FopFactory}
import org.apache.fop.apps.{FopConfParser, Fop, FopFactory}
import org.apache.xmlgraphics.util.MimeConstants
import uk.co.opsb.butler.ButlerIO

Expand All @@ -16,9 +16,10 @@ case class PdfDocument(xsl: String, xml: String, configFileName: String = "fop/f

val bos = new java.io.ByteArrayOutputStream()
try {
info("Generating PDF")
val start = System.currentTimeMillis();
transform(createFop(bos))
info("PDF generated!")
val time = System.currentTimeMillis() - start;
info(f"PDF generated in $time ms")
bos.toByteArray()
} finally {
IOUtils.closeQuietly(bos)
Expand All @@ -32,16 +33,9 @@ case class PdfDocument(xsl: String, xml: String, configFileName: String = "fop/f
}

private def createFopFactory(): FopFactory = {
val fopFactory = FopFactory.newInstance()

fopFactory.setURIResolver(new URIResolver {
def resolve(href: String, base: String) = {
new StreamSource(ButlerIO.inputStreamFrom(href))
}
})

fopFactory.setUserConfig(new File(configFileName))
fopFactory
val parser = new FopConfParser(new File(configFileName))
val builder = parser.getFopFactoryBuilder
builder.build();
}

private def transform(fop: Fop): Unit = {
Expand Down
1 change: 1 addition & 0 deletions src/test/scala/org/zilverline/fop/FopServerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.io.File
import org.apache.commons.io.FileUtils
import org.scalatest.{BeforeAndAfterAll, FunSuite}
import org.scalatest.matchers.ShouldMatchers
import scala.concurrent.ExecutionContext.Implicits.global

/*
* Test the FopServer using the http://dispatch.databinder.net/ HTTP
Expand Down

0 comments on commit dac162d

Please sign in to comment.