Okay... I'm trying to use the most recent version of ITextSharp to turn an XML file into a PDF. It isn't working.
The documentation on SourceForge doesn't seem to have kept up with the actual releases; the code in the provided example won't even compile under the newest version.
Here is my test XML:
<Remittance>
<RemitHeader>
<Payer>BlueCross</Payer>
<Provider>Maricopa</Provider>
<CheckDate>20100329</CheckDate>
<CheckNumber>123456789</CheckNumber>
</RemitHeader>
<RemitDetail>
<NPI>NPI_GOES_HERE</NPI>
<Patient>Patient Name</Patient>
<PCN>0034567</PCN>
<DateOfService>20100315</DateOfService>
<TotalCharge>125.57</TotalCharge>
<TotalPaid>55.75</TotalPaid>
<PatientShare>35</PatientShare>
</RemitDetail>
</Remittance>
And here is the code I开发者_Python百科'm attempting to use to turn that into a PDF.
Document doc = new Document(PageSize.LETTER, 36, 36, 36, 36);
iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
new StreamWriter(fileOutputPath).BaseStream);
doc.Open();
SimpleXMLParser.Parse((ISimpleXMLDocHandler)doc,
new StreamReader(fileInputPath).BaseStream);
doc.Close();
Now, I was pretty sure the (ISimpleXMLDocHandler)doc
piece wasn't going to work, but I can't actually find anything in the source that both a) implements ISimleXMLDocHandler and b) will accept a standard XML document and parse it to PDF.
FYI- I did try an older version which would compile using the example code from sourceforge, but it wasn't working either.
After browsing the 5.0.2 code, it looks like there is no document that will just take XML and turn it into a PDF for you. So, unless you can find similar code on the web or in an old release of iTextSharp, you'll need to write it yourself.
iText XML to PDF requires that the XML be formatted according to itext.dtd (please Google responsibly). You can also use a tagmap.xml to map your XML entities to those appropriate according to the DTD.
精彩评论