i am trying to convert .jsp to .pdf format using pd4ml. when start executing my code i am getting execption below

huangapple go评论75阅读模式
英文:

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.(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>
<summary>英文:</summary>

    public static void main(String[] args) {
        try {
            PdfViewerStarter jt = new PdfViewerStarter();
            jt.doConversion(&quot;http://pd4ml.com/sample.htm&quot;, &quot;D:/pd4ml.pdf&quot;);
        } 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(&quot;c:/windows/fonts&quot;, true);
        pd4ml.render(new URL(url), fos);
        fos.close();
    
        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(output);
        } else {
            System.out.println(&quot;Awt Desktop is not supported!&quot;);
        }
    
        System.out.println(outputPath + &quot;\ndone.&quot;);
    }


Error:


Error. ss_css2.jar is not in the classpath. See README.txt

 

Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/w3c/css/sac/CSSException

              at org.zefer.html.doc.PD4MLHtmlParser.o00000(Unknown Source)

              at org.zefer.html.doc.PD4MLHtmlParser.&lt;init&gt;(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 .;&quot;The full path where the Jar File is\jarfile.jar&quot; YourRunningClassFile



</details>



huangapple
  • 本文由 发表于 2020年10月21日 13:03:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64456988.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定