English 中文(简体)
iTextSharp RUS to PDF conservationspace
原标题:iTextSharp HTML to PDF preserving spaces

我正在利用自由卫星软件接收用户,并在数据库中以超文本格式储存这些信息。 用户意见摘要如下:

133 Peachtree St NE
,《亚特兰大》,GA 303
404-652-77

Cindyqiaobr/>www.somecompany.com
。 产品管理:产品管理 测试 St
Atlanta,GA 303

试验

我希望超文本工作员能保护用户进入的白色空间,但会将其排除在外。 是否有办法保护用户的白色空间? 下文是我如何编写我国人民抵抗力量文件的一个例子。

公共共同创建 PreviewPDF

        Dim output As New MemoryStream()
        Dim oDocument As New Document(PageSize.LETTER)
        Dim writer As PdfWriter = PdfWriter.GetInstance(oDocument, output)
        Dim oFont As New Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK)

        Using output
            Using writer
                Using oDocument
                    oDocument.Open()
                    Using sr As New StringReader(vsHTML)
                        Using worker As New html.simpleparser.HTMLWorker(oDocument)

                            worker.StartDocument()
                            worker.SetInsidePRE(True)
                            worker.Parse(sr)
                            worker.EndDocument()
                            worker.Close()
                            oDocument.Close()

                        End Using
                    End Using

                    HttpContext.Current.Response.ContentType = "application/pdf"
                    HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}.pdf", vsFileName))
                    HttpContext.Current.Response.BinaryWrite(output.ToArray())
                    HttpContext.Current.Response.End()

                End Using
            End Using
            output.Close()
        End Using


    End Sub
最佳回答

感谢大家的帮助。 我通过采取以下行动,找到了小的工作:

vsHTML.Replace("  ", "&nbsp;&nbsp;").Replace(Chr(9), "&nbsp;&nbsp;&nbsp;&nbsp;").Replace(Chr(160), "&nbsp;").Replace(vbCrLf, "<br />")

实际代码没有适当显示,但第一个替代物是将白色空间替换为<代码>&nbsp;,Chr(9) with 5 &nbsp;;Chr(160) with &nbsp;

问题回答

在iText和iTextSharp有了一个冰川,但是如果你不想下载来源并与之相匹配,你可以很容易地加以固定。 你们需要改变两个档案。 在法典中,对Ive所作的任何改动都作了评论。 线路数是根据5.1.2.0代码第240号编码计算的。

第一部载于iTextSharp.text.html.HtmlUtilities.cs。 查阅第249行的<条码>消除白空间,将其改为:

    public static String EliminateWhiteSpace(String content) {
        // multiple spaces are reduced to one,
        // newlines are treated as spaces,
        // tabs, carriage returns are ignored.
        StringBuilder buf = new StringBuilder();
        int len = content.Length;
        char character;
        bool newline = false;
        bool space = false;//Detect whether we have written at least one space already
        for (int i = 0; i < len; i++) {
            switch (character = content[i]) {
            case    :
                if (!newline && !space) {//If we are not at a new line AND ALSO did not just append a space
                    buf.Append(character);
                    space = true;  //flag that we just wrote a space
                }
                break;
            case  
 :
                if (i > 0) {
                    newline = true;
                    buf.Append(   );
                }
                break;
            case  
 :
                break;
            case  	 :
                break;
            default:
                newline = false;
                space = false;  //reset flag
                buf.Append(character);
                break;
            }
        }
        return buf.ToString();
    }

第二个改动见iTextSharp.text.xml.simpleparser.SimpleXMLParser.cs。 在职能<代码>Go上,第185条修改项目248改为:

if (html /*&& nowhite*/) {//removed the nowhite check from here because that should be handled by the HTML parser later, not the XML parser

我建议使用wkhtmltopdf。 不是iText. wkhtmltopdf,而是将网络kit(谷歌 Chrome、Sato)而不是iText的转换结果输出到html。 这只是你可以呼吁的双手。 尽管如此,我可以检查html,以确保用户投入中有段落和(或)细线的中断。 在进行转换之前,他们可能被剥夺权利。





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签