您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ExampleEPS.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package embedding;
  19. import java.awt.Font;
  20. import java.io.File;
  21. import java.io.FileOutputStream;
  22. import java.io.OutputStream;
  23. import org.apache.fop.configuration.Configuration;
  24. import org.apache.fop.configuration.DefaultConfigurationBuilder;
  25. import org.apache.xmlgraphics.java2d.GraphicContext;
  26. import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
  27. import org.apache.fop.fonts.FontInfo;
  28. import org.apache.fop.render.ps.NativeTextHandler;
  29. import org.apache.fop.svg.PDFDocumentGraphics2DConfigurator;
  30. public class ExampleEPS {
  31. /**
  32. * @param args
  33. */
  34. public static void main(String[] args) {
  35. try {
  36. String configFile = "examples/fop-eps.xconf";
  37. DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
  38. Configuration c = cfgBuilder.buildFromFile(new File(configFile));
  39. FontInfo fontInfo = PDFDocumentGraphics2DConfigurator.createFontInfo(c, false);
  40. OutputStream out = new FileOutputStream("example_eps.eps");
  41. EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
  42. g2d.setGraphicContext(new GraphicContext());
  43. g2d.setCustomTextHandler(new NativeTextHandler(g2d, fontInfo));
  44. g2d.setupDocument(out, 200, 100);
  45. g2d.setFont(new Font("Arial", Font.PLAIN, 12));
  46. g2d.drawString("Hi there Arial", 50, 50);
  47. g2d.finish();
  48. out.close();
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. }