0

我无法使用附加的 CSS 显示我的 xml 文件。下面是我的java代码

 package mainPackage;

 import com.lowagie.text.DocumentException;
 import org.xhtmlrenderer.pdf.ITextRenderer;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;

 public class pdf_test {

    public static void main(String[] args) throws IOException, DocumentException {
       String inputFile = "/Users/jgonzo4/Desktop/Coen174/COEN174/output.xml";
       String outputFile = "test1.pdf";

       OutputStream os = new FileOutputStream(outputFile);
       ITextRenderer renderer = new ITextRenderer();
       renderer.setDocument(new File(inputFile));
       renderer.layout();
       renderer.createPDF(os);
       os.close();
   }
 }

pdf被创建,但它只是空白。下面是xml文件

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css"    href="/Users/jgonzo4/Desktop/Coen174/COEN174/src/mainPackage/test.css"?>
<program_of_studies>
  <student_info firstName="Jesus" lastName="Gonzalez" primaryEmail="email"  secondaryEmail="email" home_phone="number" advisor="Teacher" last_modified="1383613851235" />
<grad_core_reqs />
<appl_math />
<focus_area_core />
<other_area_core />
<addit_elect_courses />
<transfer_cred_reqs />
<meta_data version="1.0.0" />
<history />

这是应该工作的CSS文件

student_info:before {
 font-size: 115%;
 content:attr(firstName)""attr(middleName)" "attr(lastName)" "attr(primaryEmail);
 display: block;
}
student_info:after {
 font-size: 115%;
 content:attr(secondaryEmail)" "attr(home_phone)" "attr(advisor);
 display: block;
}

这完全符合我在浏览器上想要的方式,所以我猜我在我的 java 函数中做错了什么。请让我知道任何建议

4

0 回答 0