English 中文(简体)
iTextShape SetListSymbol不工作
原标题:iTextSharp SetListSymbol does not work

我正试图在伊特沙普特产生的国防军中打碎。

在我试图将项目列入名单时,“SetListSymbol似乎不为我工作。

我使用的守则如下:

var elements = HTMLWorker.ParseToList(overviewReader,null);

foreach (var element in elements)
{
    //element
    var list = element as List;
    if (list != null)
    {
        //list.Symbol.GetImage();
        list.SetListSymbol("u25A0");
        list.IndentationLeft = 20f;
        doc.Add(list);
    }
    else
    {
        doc.Add(element);
    }
}
最佳回答

iTextSharp.text.html.simpleparser.StyleSheet。 这些风格松散地以超文本/特别安全局的特性为基础,但仅以最基本的特性(第3.2项)。

您希望做的三项主要事项是:(1) 装上字体,(2) 创建<条码>,注明该字体,(3) 约束<条码>, 括号 I m将部分从我的

iTextSharp 确实自动把整个系统推上了眼镜头,因此你需要人工登记。 (实际上,有一种方法,你可以打电话,把iTextSharp带给装船的gues,但速度要快得多)。)

页: 1

//Path to our font
string OurFont = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "CURLZ___.TTF");
//Register the font with iTextSharp
iTextSharp.text.FontFactory.Register(OurFont);

第2步,创立了<代码>StyleSheet,并将其贴在我们的前身。 我也把一些其他财产搁置一边。

//Create a new stylesheet
iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet();
//Set the default body font to our registered font s internal name
ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.LI, iTextSharp.text.html.HtmlTags.FACE, "Curlz MT");
ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.LI, iTextSharp.text.html.HtmlTags.COLOR, "FF0000");
ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.LI, iTextSharp.text.html.HtmlTags.SIZE, "50");

页: 1

//Use our StyleSheet from above when parsing
var elements = HTMLWorker.ParseToList(overviewReader, ST);

下面是针对ITextSharp5.2.0的C# WinForms全面运行的C# WinForms。

using System;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;

namespace WindowsFormsApplication2 {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            //Path to our font
            string FontArial = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "CURLZ___.TTF");
            //Register the font with iTextSharp
            iTextSharp.text.FontFactory.Register(FontArial);

            //Create a new stylesheet
            iTextSharp.text.html.simpleparser.StyleSheet ST = new iTextSharp.text.html.simpleparser.StyleSheet();
            //Set the default body font to our registered font s internal name
            ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.LI, iTextSharp.text.html.HtmlTags.FACE, "Curlz MT");
            ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.LI, iTextSharp.text.html.HtmlTags.COLOR, "FF0000");
            ST.LoadTagStyle(iTextSharp.text.html.HtmlTags.LI, iTextSharp.text.html.HtmlTags.SIZE, "50");

            //Sample HTML
            var html = @"<ul><li>Test</li></ul>";
            //File to output
            var outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
            //Basic PDF creation, nothing special here
            using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
                using (Document doc = new Document(PageSize.LETTER)) {
                    using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) {
                        doc.Open();
                        //Bind a reader to our HTML
                        using (StringReader overviewReader = new StringReader(html)) {
                            //Use our StyleSheet from above when parsing
                            var elements = HTMLWorker.ParseToList(overviewReader, ST);
                            //Loop through each element
                            foreach (var element in elements) {
                                //See if the element is a list item
                                var list = element as List;
                                if (list != null) {
                                    //Set some properties
                                    list.SetListSymbol("u25A0");
                                    list.IndentationLeft = 20f;
                                }
                                //Add the element to the document
                                doc.Add(element);
                            }
                        }
                        doc.Close();
                    }
                }
            }
            this.Close();
        }
    }
}
问题回答

清单目标=超文本工作员。

                foreach (IElement element in objects)
                {

                    List list = new List();
                    list.SetListSymbol("u2022");
                    list.IndentationLeft = 20f;                        
                    list.Add(element);
                    if (list.Chunks.Count == 0)
                    {
                        doc1.Add(element);
                    }
                    else
                    {
                        doc1.Add(list);
                    }
                }




相关问题
Tools to generate reportanalytics feeds from google

Can you recommend any programmable tools/extensions that can be used to generate reports out of google analytics feed on th fly? Essentially some kind of pdf generator from feed, not sure though. Or ...

Asynchronous generation of PDF - error handling

We have some code that uses a third party component to generate a PDF from a URL that we pass it (the URL being a page within our application). In the code, we instantiate the PDF generator and it ...

HTML to PDF vs. Programmatically creating PDF via PHP

I have a PHP application that needs to generate some PDF invoices and PDF timesheets with nice headers/footers. Some Stackoverflow users recommend using TCPDF to create the PDF documents. In my ...

Open PDF Programmatically in One Page View

I have a 2005 Reporting Services report that I display as a PDF through the report viewer control. I would like to know how I can have the PDF be viewed in the "one page at a time mode". Right now it ...

iTextSharp : pdfPTable overlapping with other content

I am using iTextsharp to generate a PDF document from C# application. I am having a PdfPTable to display some tabular data. My problem in the table is overlapping with the other paragraph .Is there ...

(pdflib) Table of contents with dynamic page numbers

I m on pdflib 7 under php5 and I m drawing a statistical report with several sub topics over several pages. Now, I want to include a table of contents on the first page where every sub topic is ...

热门标签