英文:
i am trying to convert .jsp to .pdf format using pd4ml. when start executing my code i am getting execption below
问题
public static void main(String[] args) {
    try {
        PdfViewerStarter jt = new PdfViewerStarter();
        jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public void doConversion(String url, String outputPath)
    throws InvalidParameterException, MalformedURLException, IOException {
    File output = new File(outputPath);
    java.io.FileOutputStream fos = new java.io.FileOutputStream(output);
    PD4ML pd4ml = new PD4ML();
    pd4ml.setHtmlWidth(userSpaceWidth);
    pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
    pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
    pd4ml.useTTF("c:/windows/fonts", true);
    pd4ml.render(new URL(url), fos);
    fos.close();
    if (Desktop.isDesktopSupported()) {
        Desktop.getDesktop().open(output);
    } else {
        System.out.println("Awt Desktop is not supported!");
    }
    System.out.println(outputPath + "\ndone.");
}
Error:
Error. ss_css2.jar is not in the classpath. See README.txt
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/css/sac/CSSException
at org.zefer.html.doc.PD4MLHtmlParser.o00000(Unknown Source)
at org.zefer.html.doc.PD4MLHtmlParser.
at org.zefer.pd4ml.PD4ML.super(Unknown Source)
at org.zefer.pd4ml.PD4ML.render(Unknown Source)
at TestForPdfPD4ML.doConversion(TestForPdfPD4ML.java:42)
at TestForPdfPD4ML.main(TestForPdfPD4ML.java:24)
Caused by: java.lang.ClassNotFoundException: org.w3c.css.sac.CSSException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 6 more
<details>
<summary>英文:</summary>
    public static void main(String[] args) {
        try {
            PdfViewerStarter jt = new PdfViewerStarter();
            jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void doConversion(String url, String outputPath)
        throws InvalidParameterException, MalformedURLException, IOException {
        File output = new File(outputPath);
        java.io.FileOutputStream fos = new java.io.FileOutputStream(output);
    
        PD4ML pd4ml = new PD4ML();
        pd4ml.setHtmlWidth(userSpaceWidth);
        pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
        pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
        pd4ml.useTTF("c:/windows/fonts", true);
        pd4ml.render(new URL(url), fos);
        fos.close();
    
        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(output);
        } else {
            System.out.println("Awt Desktop is not supported!");
        }
    
        System.out.println(outputPath + "\ndone.");
    }
Error:
Error. ss_css2.jar is not in the classpath. See README.txt
 
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/css/sac/CSSException
              at org.zefer.html.doc.PD4MLHtmlParser.o00000(Unknown Source)
              at org.zefer.html.doc.PD4MLHtmlParser.<init>(Unknown Source)
              at org.zefer.pd4ml.PD4ML.super(Unknown Source)
              at org.zefer.pd4ml.PD4ML.render(Unknown Source)
              at TestForPdfPD4ML.doConversion(TestForPdfPD4ML.java:42)
              at TestForPdfPD4ML.main(TestForPdfPD4ML.java:24)
Caused by: java.lang.ClassNotFoundException: org.w3c.css.sac.CSSException
              at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
              ... 6 more
</details>
# 答案1
**得分**: 1
可能是在请求 Jar 文件的 ClassPath,其中包含所需(导入的)库。如果您是从命令行运行,请尝试类似这样的操作:
java -cp .;"Jar 文件所在的完整路径\jarfile.jar" 您的运行类文件名
<details>
<summary>英文:</summary>
It may be asking for the ClassPath of the Jar File where the needed (imported) libraries are contained. If you are running from Command Line try something like this:
java -cp .;"The full path where the Jar File is\jarfile.jar" YourRunningClassFile
</details>
				通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论