在这个代码片段中,我使用它将HTML转换为PDF,然后再转换回
MemoryStream
.
private MemoryStream createPDF(string html)
{
try
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(html);
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
PdfWriter writer = PdfWriter.GetInstance(document, msOutput);
HTMLWorker worker = new HTMLWorker(document);
document.Open();
worker.StartDocument();
worker.Parse(reader); //error occurs in here
worker.EndDocument();
worker.Close();
document.Close();
var bytedata = msOutput.ToArray();
var pdfContent = new MemoryStream(bytedata);
return pdfContent;
}
catch (Exception ex)
{
throw;
}
}
但是当HTML内容与Base64图像一致时。我在这条线上遇到了这个错误(
worker.Parse(reader);
).
The URI prefix is not recognized.
我做了几次变通,并了解到出现这种情况是因为可以解释
itextsharp
必须没有数据前缀。我该怎么解决这个问题?