Created
April 18, 2012 02:12
-
-
Save rirakkumya/2410594 to your computer and use it in GitHub Desktop.
iTextとscala-ioでpdfを出力しちゃうコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-core" % "0.3.0" | |
libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-file" % "0.3.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalax.io._ | |
import scalax.file.Path | |
import Path.string2path | |
import com.itextpdf.text._ | |
import com.itextpdf.text.pdf._ | |
import com.itextpdf.text.pdf.fonts._ | |
object PdfWriterOpt { | |
implicit def str2Elem(s:String)(implicit font:Font) = new Paragraph(s,font) | |
def A4PdfWriter(fileName:String)(f:(Font) => (Document) => Unit) { | |
val font = new Font( | |
BaseFont.createFont("HeiseiKakuGo-W5", "UniJIS-UCS2-H",BaseFont.NOT_EMBEDDED),18) | |
fileName outputStream() foreach {stream => | |
val doc = new Document(PageSize.A4,50,50,50,50) | |
PdfWriter.getInstance(doc,stream) | |
doc.open | |
f(font)(doc) | |
doc.close | |
} | |
} | |
} | |
object Itext extends App { | |
import PdfWriterOpt._ | |
A4PdfWriter("aa.pdf"){implicit font => doc => | |
doc.add("あい") | |
} | |
} |
scala-io 0.4.0にしてみたら、compileエラーになったよ…
API変わってるのかorz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://sourceforge.net/projects/itext/files/iText/iText5.2.1/itext-5.2.1.zip/download
と
http://sourceforge.net/projects/itext/files/extrajars/extrajars-2.2.zip/download
をダウンロードして、"itext-asian.jar", "itextpdf-5.2.1.jar"を取り出し"lib/"に突っ込む