[Kod C#]
using System;
using System.Text;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.xml;
using iTextSharp.text.pdf;
using iTextSharp.text.factories;
using iTextSharp.text.html;
namespace generationDocument
{
public class xmlToPdf
{
public static void Main()
{
Console.WriteLine("XML to PDF conversion");
BaseFont arial = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\arial.ttf", "iso-8859-2", BaseFont.EMBEDDED);
Font font = newFont(arial, 9);
//creation of a document-object
Document document = newDocument();
try
{
PdfWriter.GetInstance(document, newFileStream("generowanyDokument.pdf", FileMode.Create));
//create a parser
ITextHandler xmlHandler = newITextHandler(document, newHtmlTagMap(), arial);
//parse the document
xmlHandler.Parse("generowanyDokument.xml");
}
catch (Exception e)
{
Console.Error.WriteLine(e.StackTrace);
Console.Error.WriteLine(e.Message);
if (e.InnerException != e)
{
Console.Error.WriteLine(e.InnerException.Message);
}
}
finally
{
Console.WriteLine("Finished - Hit any enter to close this window.");
}
Console.ReadLine();
}
}
}
|