本文整理汇总了C#中iTextSharp.tool.xml.pipeline.html.HtmlPipelineContext.SetAcceptUnknown方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlPipelineContext.SetAcceptUnknown方法的具体用法?C# HtmlPipelineContext.SetAcceptUnknown怎么用?C# HtmlPipelineContext.SetAcceptUnknown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.tool.xml.pipeline.html.HtmlPipelineContext
的用法示例。
在下文中一共展示了HtmlPipelineContext.SetAcceptUnknown方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneratePdfFromView
public byte[] GeneratePdfFromView(string viewString, string[] cssPaths, string fontPath)
{
using (var memoryStream = new MemoryStream())
{
var doc = new Document(PageSize.A4);
var writer = PdfWriter.GetInstance(doc, memoryStream);
doc.Open();
var tagProcessors = InitializeTagProcessor();
var cssResolver = InitializeCssFiles(cssPaths);
var fontProvider = new CustomFontFactory(fontPath);
var hpc = new HtmlPipelineContext(new CssAppliersImpl(fontProvider));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(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, Encoding.Unicode);
xmlParser.Parse(new StringReader(viewString));
doc.Close();
return memoryStream.ToArray();
}
}
示例2: MakePdf
protected override void MakePdf(string outPdf) {
Document doc = new Document(PageSize.A4.Rotate());
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create));
doc.SetMargins(45, 45, 0, 100);
doc.Open();
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"main.css")));
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"widget082.css")));
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc =
new HtmlPipelineContext(
new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts")));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
hpc.SetImageProvider(new SampleTestImageProvider());
hpc.SetPageSize(doc.PageSize);
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter));
IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8"));
p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8"));
doc.Close();
}
示例3: TransformHtml2Pdf
protected override void TransformHtml2Pdf() {
Document doc = new Document(PageSize.A1.Rotate());
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create));
doc.SetMargins(doc.LeftMargin - 10, doc.RightMargin - 10, doc.TopMargin, doc.BottomMargin);
doc.Open();
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + testName +
Path.DirectorySeparatorChar + "complexDiv02_files" + Path.DirectorySeparatorChar +
"minimum0.css")));
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + testName +
Path.DirectorySeparatorChar + "complexDiv02_files" + Path.DirectorySeparatorChar +
"print000.css")));
cssFiles.Add(XMLWorkerHelper.GetCSS(File.OpenRead(RESOURCES + @"\tool\xml\examples\" + "sampleTest.css")));
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc =
new HtmlPipelineContext(
new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts")));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
hpc.SetImageProvider(new SampleTestImageProvider());
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter));
IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8"));
p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8"));
doc.Close();
}
示例4: ParseXfaOnlyXML
virtual public void ParseXfaOnlyXML() {
StreamReader bis = File.OpenText(RESOURCE_TEST_PATH + SNIPPETS + TEST + "snippet.html");
Document doc = new Document(PageSize.A4);
float margin = utils.ParseRelativeValue("10%", PageSize.A4.Width);
doc.SetMargins(margin, margin, margin, margin);
PdfWriter writer = null;
try {
writer = PdfWriter.GetInstance(doc, new FileStream(
TARGET + TEST + "_charset.pdf", FileMode.Create));
}
catch (DocumentException e) {
Console.WriteLine(e);
}
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS());
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc = new HtmlPipelineContext(null);
hpc.SetAcceptUnknown(true)
.AutoBookmark(true)
.SetTagFactory(Tags.GetHtmlTagProcessorFactory())
.CharSet(Encoding.GetEncoding("ISO-8859-1"));
IPipeline pipeline = new CssResolverPipeline(cssResolver,
new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
doc.Open();
XMLParser p = new XMLParser(true, worker);
p.Parse(bis);
doc.Close();
}
示例5: MakePdf
protected override void MakePdf(string outPdf) {
Document doc = new Document(PageSize.A3.Rotate());
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create));
pdfWriter.CreateXmpMetadata();
doc.SetMargins(200, 200, 0, 0);
doc.Open();
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"main.css")));
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"widget082.css")));
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc =
new HtmlPipelineContext(
new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts")));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
hpc.SetImageProvider(new SampleTestImageProvider());
hpc.SetPageSize(doc.PageSize);
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter));
IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8"));
p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8"));
//ICC_Profile icc = ICC_Profile.getInstance(ComplexDiv01Test.class.getResourceAsStream("sRGB Color Space Profile.icm"));
//pdfWriter.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
doc.Close();
}
示例6: ParseXHtml
/**
* @param d the ElementHandler
* @param inp the Stream
* @throws IOException if something went seriously wrong with IO.
*/
public void ParseXHtml(IElementHandler d, Stream inp, Encoding charset) {
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(GetDefaultCSS());
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc = new HtmlPipelineContext(null);
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(GetDefaultTagProcessorFactory());
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(hpc, new ElementHandlerPipeline(d,
null)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, charset);
if (charset != null) {
p.Parse(inp, charset);
} else {
p.Parse(inp);
}
}
示例7: processHtml
private void processHtml(IElementHandler elementsHandler)
{
var cssResolver = new StyleAttrCSSResolver();
if (CssFilesPath != null && CssFilesPath.Any())
{
foreach (var cssFile in CssFilesPath)
{
cssResolver.AddCss(XmlWorkerUtils.GetCssFile(cssFile));
}
}
if (!string.IsNullOrEmpty(InlineCss))
{
cssResolver.AddCss(InlineCss, "utf-8", true);
}
var htmlContext = new HtmlPipelineContext(new CssAppliersImpl(new UnicodeFontProvider(DefaultFont)));
if (!string.IsNullOrEmpty(ImagesPath))
{
htmlContext.SetImageProvider(new ImageProvider { ImagesPath = ImagesPath });
}
htmlContext.CharSet(Encoding.UTF8);
var tagsProcessorFactory = (DefaultTagProcessorFactory)Tags.GetHtmlTagProcessorFactory();
if (PdfElement != null)
{
tagsProcessorFactory.AddProcessor("totalpagesnumber", new TotalPagesNumberXmlWorkerProcessor(PdfElement));
}
htmlContext.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(tagsProcessorFactory);
var pipeline = new CssResolverPipeline(cssResolver,
new HtmlPipeline(htmlContext, new ElementHandlerPipeline(elementsHandler, null)));
var worker = new XMLWorker(pipeline, parseHtml: true);
var parser = new XMLParser();
parser.AddListener(worker);
parser.Parse(new StringReader(Html));
}