AFIAK HTMLWorker is deprecated. Use XMLWorker.
On 03/07/2013 12:02 PM, chaitanya krishna wrote:
Hi team,
I am usingthe ITextsharp to generate a PDF file for the attachec html
file. Sample PDF was also attached.
I am missing the background color and borders to that, can you please
suggest a sample code to generate appropriately. below is the code.
byte[] pdfContents = Render();
stringpdfName = "file.pdf";
pafPdfPath = Path.Combine(path, pdfName);
// // Create a new stream to write to the file
using(BinaryWriterWriter =
newBinaryWriter(System.IO.File.Open(pafPdfPath, FileMode.CreateNew)))
{
Writer.Write(pdfContents);
Writer.Flush();
Writer.Close();
}
publicbyte[] Render()
{
htmlText = System.IO.File.ReadAllText("c:\\file.html");
byte[] renderedBuffer;
using(varoutputMemoryStream = newMemoryStream())
{
using(varpdfDocument = newDocument())
{
PdfWriterpdfWriter = PdfWriter.GetInstance(pdfDocument,
outputMemoryStream);
pdfWriter.CloseStream = false;
//pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
pdfDocument.Open();
using(varhtmlViewReader = newStringReader(htmlText))
{
using(varhtmlWorker = newHTMLWorker(pdfDocument))
{
////Create a provider collection to set various processing properties
//System.Collections.Generic.Dictionary<string, object> providers =
new System.Collections.Generic.Dictionary<string, object>();
////Set the image base. This will be prepended to the SRC so watch
your forward slashes
//providers.Add(HTMLWorker.IMG_BASEURL, "http://YOUR_DOMAIN");
////Bind the providers to the worker
//htmlWorker.SetProviders(providers);
htmlWorker.Parse(htmlViewReader);
}
}
}
renderedBuffer = newbyte[outputMemoryStream.Position];
outputMemoryStream.Position = 0;
outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
}
returnrenderedBuffer;
}
Regards,
Chaitanya Kolla.
9885155441
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php