如何解决未知协议:yahpjarloader

时间:2014-04-22 11:36:03

标签: java flying-saucer html2pdf

您好我正在使用YaHPConverter将我的html文件转换为PDF文件。当我从Eclipse运行时,我得到一个PDF文件,但是当我从命令提示符运行我的java文件时,我得到一个异常。我已将jar文件放入以下路径。

/usr/local/jdk1.7.0_21/jre/lib/ext

import java.awt.Color;
import java.awt.List;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.html.simpleparser.HTMLWorker;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.codec.Base64.OutputStream;
import com.itextpdf.tool.xml.XMLWorkerHelper;

import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import org.allcolor.yahp.converter.CYaHPConverter;
import org.allcolor.yahp.converter.IHtmlToPdfTransformer;

public class App {
    public static void main(String[] args) throws DocumentException, IOException {
        Document document = new Document();
        try {
            String root = "/home/ubuntu/Desktop";
            String input = "index.html";  // need to be charset utf-8
            htmlToPdfFile(new File(root, input), new File(root, input + ".pdf"));
            System.out.println("Done");
        } catch (Exception e) {
            System.out.println("Exception Generated======>>" + e);
        }
        document.close();
    }

    public static void htmlToPdfFile(File htmlIn, File pdfOut) throws Exception {
        Scanner scanner = new Scanner(htmlIn).useDelimiter("\\Z");
        String htmlContents = scanner.next();
        CYaHPConverter converter = new CYaHPConverter();
        FileOutputStream out = new FileOutputStream(pdfOut);
        Map properties = new HashMap();
        //ArrayList headerFooterList = new ArrayList();
        ArrayList<String> headerFooterList = new ArrayList<String>();
        //List<String> headerFooterList = new ArrayList<String>();

        properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS, IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);
        //properties.put(IHtmlToPdfTransformer.FOP_TTF_FONT_PATH, fontPath);
        converter.convertToPdf(htmlContents, IHtmlToPdfTransformer.A4P, headerFooterList, "file:///temp/html/", out, properties);
        out.flush();
        out.close();
    }

}

这是我的java文件,当我运行它时,我得到以下异常。

    Initializing...
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    java.net.MalformedURLException: unknown protocol: yahpjarloader
at java.net.URL.<init>(URL.java:592)
at java.net.URL.<init>(URL.java:482)
at java.net.URL.<init>(URL.java:431)
at org.allcolor.yahp.converter.CClassLoader.readDirectories(CClassLoader.java:2121)
at org.allcolor.yahp.converter.CClassLoader.init(CClassLoader.java:819)
at org.allcolor.yahp.converter.CYaHPConverter.init(CYaHPConverter.java:333)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:79)
at org.allcolor.yahp.converter.CYaHPConverter.<init>(CYaHPConverter.java:66)
at App.htmlToPdfFile(App.java:47)
at App.main(App.java:34)
    Apr 22, 2014 4:59:09 PM org.allcolor.yahp.converter.CClassLoader log
    SEVERE: unknown protocol: yahpjarloader
    init time: 150
    java.lang.ClassNotFoundException:         
    org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.allcolor.yahp.converter.CClassLoader.findClass(CClassLoader.java:1496)
at org.allcolor.yahp.converter.CClassLoader.findClass(CClassLoader.java:1478)
at org.allcolor.yahp.converter.CClassLoader.loadClass(CClassLoader.java:2056)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at 
    org.allcolor.yahp.converter.CYaHPConverter.getTransformer(CYaHPConverter.java:383)
at org.allcolor.yahp.converter.CYaHPConverter.convertToPdf(CYaHPConverter.java:246)
at App.htmlToPdfFile(App.java:56)
at App.main(App.java:34)
    SEVERE: Error while getting transformer   
    'org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer' ! : 
    org.allcolor.yahp.cl.converter.CHtmlToPdfFlyingSaucerTransformer
    Exception  
    enerated======>>org.allcolor.yahp.converter.IHtmlToPdfTransformer$CConvertException
    Destroying YAHP ClassLoader Tree
    Destroying YAHP ClassLoader Tree : done
    Finalizing classloader : rootLoader/main
    Finalizing classloader : rootLoader

使用此代码,我得到了我的pdf文件,但没有内容。告诉我:我错过了什么? 提前谢谢。

0 个答案:

没有答案