Trouble with ITextSharp - Converting XML to PDF

Posted by AllenG on Stack Overflow See other posts from Stack Overflow or by AllenG
Published on 2010-05-06T19:24:21Z Indexed on 2010/05/06 19:28 UTC
Read the original article Hit count: 1023

Filed under:
|
|
|

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'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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about itextsharp