Left side table is distorted while comparing two HTML table data using daisydiff.jar.
I need your support to fix this issue. Thanks in advance
Using below code
StringWriter finalResult = new StringWriter();
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); TransformerHandler result = tf.newTransformerHandler();
result.getTransformer().setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
result.getTransformer().setOutputProperty(OutputKeys.INDENT, "no");
result.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
result.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
result.setResult(new StreamResult(finalResult));
ContentHandler postProcess = result;
Locale locale = Locale.getDefault();
String prefix = "diff";
NekoHtmlParser cleaner = new NekoHtmlParser();
InputSource oldSource = new InputSource (new String reader(html1));
InputSource newSource = new InputSource (new String reader(html2));
DomTreeBuilder oldHandler = new DomTreeBuilder ();
cleaner.parse(oldSource, oldHandler);
TextNodeComparator leftComparator = new TextNodeComparator (oldHandler, locale);
DomTreeBuilder newHandler = new DomTreeBuilder ();
cleaner.parse(newSource, newHandler);
TextNodeComparator rightComparator = new TextNodeComparator (newHandler, locale);
HtmlSaxDiffOutput output = new HtmlSaxDiffOutput (postProcess, prefix);
HTMLDiffer differ = new HTMLDiffer(output);
differ.diff(leftComparator, rightComparator);
I am trying to send mail in asp.net whit AegisImplicitMail. My code is:
string OggettoEmailIta = "Oggetto email";
string TestoEmailIta = "<p>aaa</p><br/><div>bbb</div>";
var mailMessage = new MimeMailMessage();
mailMessage.Subject = OggettoEmailIta;
mailMessage.IsBodyHtml = true;
mailMessage.Body = TestoEmailIta;
mailMessage.Sender = new MimeMailAddress("XXX", "XXX");
mailMessage.From = new MimeMailAddress("XXX", "XXX");
mailMessage.To.Add(new MimeMailAddress("XXX", "XXX"));
mailMessage.To.Add(new MimeMailAddress("XXX", "XXX"));
var emailer = new SmtpSocketClient();
emailer.Host = "smtp.XXX.XX";
emailer.Port = 465;
emailer.SslType = SslMode.Ssl;
emailer.User = "XXX";
emailer.Password = "XXX";
emailer.AuthenticationMode = AuthenticationType.Base64;
emailer.MailMessage.IsBodyHtml = true;
emailer.MailMessage = mailMessage;
emailer.SendMailAsync();
The mail is sent correctly but it is not in HTML format.
Can someone help me?
you might try string literals "#" for your html message, so all chars are kept
string TestoEmailIta = #"<p>aaa</p><br/><div>bbb</div>";
I would like to create dynamic PDF documents using HTML and dynamic images. My code works fine with standard HTML and full paths for the images, but when I try to embed the image inline in the document I get the error
Exception Details: System.IO.IOException: The document has no pages.
Is there a way to embed the images without an HTTP call per image? I don't want that because I think it will cause scalability issues and the images are sensitive.
Here is my code that gives the IOException:
public ActionResult MakePdf()
{
string html = #"<?xml version=""1.0"" encoding=""UTF-8""?>
<!DOCTYPE html
PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN""
""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en"">
<head>
<title>Minimal XHTML 1.0 Document with W3C DTD</title>
</head>
<body><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAABQCAMAAAB24TZcAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGAUExURdSmeJp2SHlbQIRoSUg2J499a8KebqeHZuGufBEVJPz7+3NWPVxGMduwhPXEktnX1mtROLq7t5WDc2VMNv3LmKB8TMSidMbFxLGlmXlhSMSddpJUL+y8i3VlVqedlOzr6gUIF2lXRLCLY4ZyXLyYaYhtUYiJhJFyU1dBLLiVZnlwZrWRY/Hx8b+2rbySaJh9YqeooDw4NygnKvvJlpyblzksIUhGRryYckc7MPjGlKODX5x8VVA8K+azgM3FvDInHK2JW2ZbUOHh4Xt2cFpaWKeAUM6kel1RRJmUjo5vSrWzrJJ1WFhLQCQmMuK1iJiMgmthWPPCkOm3hEtBOunm5LCNXnJtZquEXmNkYvG+i7Ctq+y5hrWRbKqSeaN/WqmFVYFgQh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D2OR4hMnhHfiPtYiJr4a8Jj4MbHNe7UC4RtTfc5wsd+DD6RbxxTZ8chtkrcJGIlqX41GqTVzFp3wmfmCNi5rNT74Z3nwHi2BjZW11AtdzgvxIfSBl4l/Klzr+bfLvzSNYA1u9xTfmz8f4lLmA5HWfgV8eTa7BEohxox1xeZ1F5Ef4fTrYnL4oGjb7QZ3JVgk2W4KJPMZvmWbo9KWJ27QsXKHm3DkhJT/Gs6z55lo0abV5wCSL5txL/CMa4PYPUXN+5qwTj68aXwa5MP4Efj/VDA4TW3BV3PQMp7Wlgnfg555mcPFO8RbXMbXv8Oh6pG3J7IRM8bq3Q/zKLFqUQ3GteNYvbepG1XG57O0Qt9Hmd1bOKC1qbZH/zbK78FWzYMJ2aZoXPq7kr8ZvORr+iUSjJzQb/Gpa5l8BBgBZTppAyfsf0wAAAABJRU5ErkJggg==' width='62' height='80' style='float: left; margin-right: 28px;' /></body></html>";
var bytes = Encoding.UTF8.GetBytes(html);
using (MemoryStream input = new MemoryStream(bytes))
{
MemoryStream output = new MemoryStream();
using (Document document = new Document(PageSize.LETTER, 50, 50, 50, 50))
{
using (PdfWriter writer = PdfWriter.GetInstance(document, output))
{
writer.CloseStream = false;
document.Open();
XMLWorkerHelper xmlWorker = XMLWorkerHelper.GetInstance();
xmlWorker.ParseXHtml(writer, document, input, null);
document.Close();
output.Position = 0;
return new FileStreamResult(output, "application/pdf");
}
}
}
}
We need to write our own ImageTagProcessor to support processing of base 64 images:
public class CustomImageTagProcessor : iTextSharp.tool.xml.html.Image
{
public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent)
{
IDictionary<string, string> attributes = tag.Attributes;
string src;
if (!attributes.TryGetValue(HTML.Attribute.SRC, out src))
return new List<IElement>(1);
if (string.IsNullOrEmpty(src))
return new List<IElement>(1);
if (src.StartsWith("data:image/", StringComparison.InvariantCultureIgnoreCase))
{
// data:[<MIME-type>][;charset=<encoding>][;base64],<data>
var base64Data = src.Substring(src.IndexOf(",") + 1);
var imagedata = Convert.FromBase64String(base64Data);
var image = iTextSharp.text.Image.GetInstance(imagedata);
var list = new List<IElement>();
var htmlPipelineContext = GetHtmlPipelineContext(ctx);
list.Add(GetCssAppliers().Apply(new Chunk((iTextSharp.text.Image)GetCssAppliers().Apply(image, tag, htmlPipelineContext), 0, 0, true), tag, htmlPipelineContext));
return list;
}
else
{
return base.End(ctx, tag, currentContent);
}
}
}
Then we can inject this new processor into the HtmlPipelineContext:
using (var doc = new Document(PageSize.A4))
{
var writer = PdfWriter.GetInstance(doc, new FileStream("test.pdf", FileMode.Create));
doc.Open();
var html = #"<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAABQCAMAAAB24TZcAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGAUExURdSmeJp2SHlbQIRoSUg2J499a8KebqeHZuGufBEVJPz7+3NWPVxGMduwhPXEktnX1mtROLq7t5WDc2VMNv3LmKB8TMSidMbFxLGlmXlhSMSddpJUL+y8i3VlVqedlOzr6gUIF2lXRLCLY4ZyXLyYaYhtUYiJhJFyU1dBLLiVZnlwZrWRY/Hx8b+2rbySaJh9YqeooDw4NygnKvvJlpyblzksIUhGRryYckc7MPjGlKODX5x8VVA8K+azgM3FvDInHK2JW2ZbUOHh4Xt2cFpaWKeAUM6kel1RRJmUjo5vSrWzrJJ1WFhLQCQmMuK1iJiMgmthWPPCkOm3hEtBOunm5LCNXnJtZquEXmNkYvG+i7Ctq+y5hrWRbKqSeaN/WqmFVYFgQh8aGOa4isWkd8mcby4vONDNy0AwI5h2U19JMxkdLzIuL1JBMjQ3P5Z6Ve6/j93c2+Xi34KAfJ5/Xvj4+O/u7sSKVJd4Wo6QjXE+IeOwfQcNJoBeQ8Gdbf/Mmf///5GX6NEAAAcrSURBVHja3JbpX9pIGMchiWkgEaOBtaGinBLEyopFBeMqtYKI4kGt2lILFsUoXa3WdZcc/dd3JheHAvaz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27QsXKHm3DkhJT/Gs6z55lo0abV5wCSL5txL/CMa4PYPUXN+5qwTj68aXwa5MP4Efj/VDA4TW3BV3PQMp7Wlgnfg555mcPFO8RbXMbXv8Oh6pG3J7IRM8bq3Q/zKLFqUQ3GteNYvbepG1XG57O0Qt9Hmd1bOKC1qbZH/zbK78FWzYMJ2aZoXPq7kr8ZvORr+iUSjJzQb/Gpa5l8BBgBZTppAyfsf0wAAAABJRU5ErkJggg==' width='62' height='80' style='float: left; margin-right: 28px;' />";
var tagProcessors = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory();
tagProcessors.RemoveProcessor(HTML.Tag.IMG); // remove the default processor
tagProcessors.AddProcessor(HTML.Tag.IMG, new CustomImageTagProcessor()); // use our new processor
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS());
var cssResolver = new StyleAttrCSSResolver(cssFiles);
cssResolver.AddCss(#"code { padding: 2px 4px; }", "utf-8", true);
var charset = Encoding.UTF8;
var hpc = new HtmlPipelineContext(new CssAppliersImpl(new XMLWorkerFontProvider()));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagProcessors); // inject the tagProcessors
var htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer));
var pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
var worker = new XMLWorker(pipeline, true);
var xmlParser = new XMLParser(true, worker, charset);
xmlParser.Parse(new StringReader(html));
}
Process.Start("test.pdf");
string originalFile = "Original1.pdf";
string copyOfOriginal = "Re-copia.pdf";
byte[] bytes = Convert.FromBase64String(archivo);
System.IO.FileStream stream = new FileStream(originalFile, FileMode.CreateNew);
System.IO.BinaryWriter writer = new BinaryWriter(stream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
PdfReader reader1 = new PdfReader(originalFile);
using (FileStream fs = new FileStream(copyOfOriginal, FileMode.Create, FileAccess.Write, FileShare.None))
// Creating iTextSharp.text.pdf.PdfStamper object to write
// Data from iTextSharp.text.pdf.PdfReader object to FileStream object
using (PdfStamper stamper = new PdfStamper(reader1, fs))
{
int pageCount = reader1.NumberOfPages;
// Create New Layer for Watermark
PdfLayer layer = new PdfLayer("WatermarkLayer", stamper.Writer);
// Loop through each Page
for (int i = pageCount; i <= pageCount; i++)
{
// Getting the Page Size
Rectangle rect = reader1.GetPageSize(i);
// Get the ContentByte object
PdfContentByte cb = stamper.GetUnderContent(i);
// Tell the cb that the next commands should be "bound" to this new layer
cb.BeginLayer(layer);
cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 50);
PdfGState gState = new PdfGState();
cb.SetGState(gState);
string codbartest = codBarras;
BarcodePDF417 bcpdf417 = new BarcodePDF417();
//Asigna el código de barras en base64 a la propiedad text del objeto..
bcpdf417.Text = ASCIIEncoding.ASCII.GetBytes(codbartest);
Image imgpdf417 = bcpdf417.GetImage();
imgpdf417.SetAbsolutePosition(50, 50);
imgpdf417.ScalePercent(100);
cb.AddImage(imgpdf417);
// Close the layer
cb.EndLayer();
}[enter image description here][1]
I'm trying to convert html to pdf using iTextSharp.dll. Although on the output pdf document, it renders the html markup without formatted text. Please tell me what am I missing.
Document pdfDoc = new Document(PageSize.A4, 50, 50, 25, 25);
var textInput = Label1.Text;
try
{
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(pdfDoc, output);
pdfDoc.Open();
var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Image/image1.jpg"));
logo.SetAbsolutePosition(400, 750);
pdfDoc.Add(logo);
Paragraph para = new Paragraph(textInput);
para.Alignment = Element.PARAGRAPH;
pdfDoc.Add(para);
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Doc-{0}.pdf", TextBox3.Text));
Response.BinaryWrite(output.ToArray());
}
catch (DocumentException dex)
{
throw (dex);
}
catch (IOException ioex)
{
throw (ioex);
}
finally
{
pdfDoc.Close();
}
}
I would greatly appreciate any help.
I'm facing style issue while converting .doc files to html texts using Apache POI's HWPFDocument class. Another problem is that it converts style tags too like this:
.b1{white-space-collapsing:preserve;} .b2{margin: 1.1798611in 1.1798611in 1.1798611in 1.1798611in;} .s1{font-weight:bold;color:black;} .s2{color:black;} .s3{font-style:italic;color:black;} .p1{text-align:center;hyphenate:none;font-family:Times New Roman;font-size:12pt;} .p2{text-align:justify;hyphenate:none;font-family:Times New Roman;font-size:12pt;} .p3{text-align:end;hyphenate:none;font-family:Times New Roman;font-size:12pt;}
Main Title
Here's my code:
HWPFDocumentCore wordDocument = WordToHtmlUtils.loadDoc(multipartFile.getInputStream());
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
wordToHtmlConverter.processDocument(wordDocument);
org.w3c.dom.Document htmlDocument = wordToHtmlConverter.getDocument();
ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StreamResult streamResult = new StreamResult(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult);
out.close();
String html = new String(out.toByteArray());
All I need is getting .doc file's content into HTML text format properly.