Package com.adobe.dp.epub.ops

Examples of com.adobe.dp.epub.ops.OPSDocument


    super(epub, name, mediaType, null);
  }

  public OPSDocument getDocument() {
    if (document == null)
      document = new OPSDocument(this);
    return document;
  }
View Full Code Here


    if (!mediaType.equals("application/xhtml+xml"))
      return null;
    int targetSize = sizeToSplit;
    Vector res = new Vector();
    res.add(this);
    OPSDocument doc = document;
    while (true) {
      String name = pub.makeUniqueResourceName(getName());
      OPSResource r = pub.createOPSResource(name);
      if (!doc.peelOffBack(r.getDocument(), targetSize)) {
        pub.removeResource(r);
        break;
      }
      doc = r.getDocument();
      res.add(r);
View Full Code Here

  public void serialize(OutputStream out) throws IOException {
    getDocument().serialize(out);
  }

  public void load(DataSource data) throws Exception {
    document = new OPSDocument(this);
    document.load(data);
  }
View Full Code Here

    Iterator res = resources();
    while (res.hasNext()) {
      Object next = res.next();
      if (next instanceof OPSResource) {
        OPSResource ops = (OPSResource) next;
        OPSDocument doc = ops.getDocument();
        doc.addStyleResource(styleResource.getResourceRef());
        doc.addFonts(subsetter, styleResource);
      }
    }
    subsetter.addFonts(this);
    return subsetter;
  }
View Full Code Here

    list = resourcesByName.values().iterator();
    while (list.hasNext()) {
      Object next = list.next();
      if (next instanceof OPSResource) {
        OPSResource ops = (OPSResource) next;
        OPSDocument doc = ops.getDocument();
        doc.removeAllStyleResources();
        doc.setAssignStylesFlag();
        doc.addStyleResource(styleResource.getResourceRef());
        doc.generateStyles(styleResource.getStylesheet());
      }
    }
    return styleResource;
  }
View Full Code Here

  public XRef getXRef(String id) {
    Resource r = getResource();
    if( r == null )
      return null;
    if (r instanceof OPSResource) {
      OPSDocument ops = ((OPSResource) r).getDocument();
      if (id == null)
        return ops.getRootXRef();
      Element e = ops.getElementById(id);
      if (e != null)
        return e.getSelfRef();
    }
    XRef ref;
    if (unresolvedXRefMap == null || (ref = (XRef) unresolvedXRefMap.get(id)) == null) {
View Full Code Here

      // create first chapter resource
      OPSResource chapter1 = epub.createOPSResource("OPS/chapter1.html");
      epub.addToSpine(chapter1);

      // get chapter document
      OPSDocument chapter1Doc = chapter1.getDocument();

      // link our stylesheet
      chapter1Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter1TOCEntry = toc.createTOCEntry("Chapter 1",
          chapter1Doc.getRootXRef());
      rootTOCEntry.add(chapter1TOCEntry);

      // chapter XHTML body element
      Element body1 = chapter1Doc.getBody();

      // add a header
      Element header1 = chapter1Doc.createElement("h1");
      header1.add("One");
      body1.add(header1);

      // add a paragraph
      Element paragraph1 = chapter1Doc.createElement("p");
      StringBuffer sb1 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb1.append("This is sentence " + i
            + " of the first chapter's first paragraph. ");
      paragraph1.add(sb1.toString());
      body1.add(paragraph1);

      // add SVG graphics area
      SVGElement svg = chapter1Doc.createSVGElement("svg");
      svg.setAttribute("viewBox", "0 0 400 200");
      svg.setClassName("svgimage");
      body1.add(svg);

      // draw background
      SVGElement bg = chapter1Doc.createSVGElement("rect");
      bg.setAttribute("x", "1");
      bg.setAttribute("y", "1");
      bg.setAttribute("width", "398");
      bg.setAttribute("height", "198");
      bg.setAttribute("stroke", "black");
      bg.setAttribute("stroke-width", "2");
      bg.setAttribute("fill", "#FFF8EE");
      svg.add(bg);

      // draw a shape
      SVGElement path = chapter1Doc.createSVGElement("path");
      path.setAttribute("fill", "none");
      path.setAttribute("stroke", "black");
      path.setAttribute("stroke-width", "4");
      String resistorPath = "M90 120h50l10 20l20-40l20 40l20-40l20 40l20-40l20 40l20-40l20 40l10-20h50";
      path.setAttribute("d", resistorPath);
      svg.add(path);

      // draw a label
      SVGElement label1 = chapter1Doc.createSVGElement("text");
      label1.setClassName("label1");
      label1.setAttribute("x", "150");
      label1.setAttribute("y", "60");
      label1.add("R = 30\u03A9");
      svg.add(label1);

      // draw rotated label
      SVGElement label2 = chapter1Doc.createSVGElement("text");
      label2.setClassName("label2");
      label2.setAttribute("transform", "translate(40 110)rotate(-75)");
      SVGElement t1 = chapter1Doc.createSVGElement("tspan");
      t1.setAttribute("fill", "red");
      t1.add("S");
      label2.add(t1);
      SVGElement t2 = chapter1Doc.createSVGElement("tspan");
      t2.setAttribute("fill", "green");
      t2.add("V");
      label2.add(t2);
      SVGElement t3 = chapter1Doc.createSVGElement("tspan");
      t3.setAttribute("fill", "blue");
      t3.add("G");
      label2.add(t3);
      svg.add(label2);

      // create a small paragraph to use as a link target
      Element target = chapter1Doc.createElement("p");
      target.add("Link in the second chapter points here.");
      body1.add(target);

      // create second chapter resource
      OPSResource chapter2 = epub.createOPSResource("OPS/chapter2.html");
      epub.addToSpine(chapter2);

      // get chapter document
      OPSDocument chapter2Doc = chapter2.getDocument();

      // link our stylesheet
      chapter2Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter2TOCEntry = toc.createTOCEntry("Chapter 2",
          chapter2Doc.getRootXRef());
      rootTOCEntry.add(chapter2TOCEntry);

      // chapter XHTML body element
      Element body2 = chapter2Doc.getBody();

      // add a header
      Element header2 = chapter1Doc.createElement("h1");
      header2.add("Two");
      body2.add(header2);

      // add a paragraph
      Element paragraph2 = chapter2Doc.createElement("p");
      StringBuffer sb2 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb2.append("This is sentence " + i
            + " of the second chapter's first paragraph. ");
      paragraph2.add(sb2.toString());
      body2.add(paragraph2);

      // add a bitmap resource
      DataSource dataSource = new ResourceDataSource(HelloEPUB3.class,
          "cassini.jpg");
      BitmapImageResource imageResource = epub.createBitmapImageResource(
          "OPS/images/cassini.jpg", "image/jpeg", dataSource);

      // add a bitmap image
      Element container = chapter2Doc.createElement("p");
      container.setClassName("container");
      body2.add(container);
      ImageElement bitmap = chapter2Doc.createImageElement("img");
      bitmap.setClassName("bitmap");
      bitmap.setImageResource(imageResource);
      container.add(bitmap);

      // and another paragraph
      Element paragraph3 = chapter2Doc.createElement("p");
      StringBuffer sb3 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb3.append("This is sentence " + i
            + " of the second chapter's second paragraph. ");
      paragraph3.add(sb3.toString());
      body2.add(paragraph3);

      // add a link to the target paragraph in the first chapter
      HyperlinkElement a = chapter2Doc.createHyperlinkElement("a");
      a.setXRef(target.getSelfRef());
      a.add("Here is a link.");
      paragraph3.add(a);

      // embed fonts
View Full Code Here

      // create first chapter resource
      OPSResource chapter1 = epub.createOPSResource("OPS/chapter1.html");
      epub.addToSpine(chapter1);

      // get chapter document
      OPSDocument chapter1Doc = chapter1.getDocument();

      // link our stylesheet
      chapter1Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter1TOCEntry = toc.createTOCEntry("Chapter 1",
          chapter1Doc.getRootXRef());
      rootTOCEntry.add(chapter1TOCEntry);

      // chapter XHTML body element
      Element body1 = chapter1Doc.getBody();

      // add a header
      Element header1 = chapter1Doc.createElement("h1");
      header1.add("One");
      body1.add(header1);

      // add a paragraph
      Element paragraph1 = chapter1Doc.createElement("p");
      StringBuffer sb1 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb1.append("This is sentence " + i
            + " of the first chapter's first paragraph. ");
      paragraph1.add(sb1.toString());
      body1.add(paragraph1);

      // create second chapter resource
      OPSResource chapter2 = epub.createOPSResource("OPS/chapter2.html");
      epub.addToSpine(chapter2);

      // get chapter document
      OPSDocument chapter2Doc = chapter2.getDocument();

      // link our stylesheet
      chapter2Doc.addStyleResource(style);

      // add chapter to the table of contents
      TOCEntry chapter2TOCEntry = toc.createTOCEntry("Chapter 2",
          chapter2Doc.getRootXRef());
      rootTOCEntry.add(chapter2TOCEntry);

      // chapter XHTML body element
      Element body2 = chapter2Doc.getBody();

      // add a header
      Element header2 = chapter1Doc.createElement("h1");
      header2.add("Two");
      body2.add(header2);

      // add a paragraph
      Element paragraph2 = chapter2Doc.createElement("p");
      StringBuffer sb2 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb2.append("This is sentence " + i
            + " of the second chapter's first paragraph. ");
      paragraph2.add(sb2.toString());
      body2.add(paragraph2);

      // and another one
      Element paragraph3 = chapter2Doc.createElement("p");
      StringBuffer sb3 = new StringBuffer();
      for (int i = 1; i <= 6; i++)
        sb3.append("This is sentence " + i
            + " of the second chapter's second paragraph. ");
      paragraph3.add(sb3.toString());
View Full Code Here

      // create new chapter resource
      OPSResource main = epub.createOPSResource("OPS/main.html");
      epub.addToSpine(main);

      // get chapter document
      OPSDocument mainDoc = main.getDocument();

      // add chapter to the table of contents
      TOCEntry mainTOCEntry = toc.createTOCEntry("Intro", mainDoc
          .getRootXRef());
      rootTOCEntry.add(mainTOCEntry);

      // chapter XHTML body element
      Element body = mainDoc.getBody();

      // add a header
      Element h1 = mainDoc.createElement("h1");
      h1.add("My First EPUB");
      body.add(h1);

      // add a paragraph
      Element paragraph = mainDoc.createElement("p");
      paragraph.add("Hello, world!");
      body.add(paragraph);

      // save EPUB to an OCF container
      OCFContainerWriter writer = new OCFContainerWriter(
View Full Code Here

TOP

Related Classes of com.adobe.dp.epub.ops.OPSDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.