0
pdf에 '&'과 같은 문자를 표시하는 방법. itextsharp를 사용하여 pdf를 만듭니다. 도와주세요.itextSharp를 사용하여 pdf에 특수 문자를 표시하려면
pdf에 '&'과 같은 문자를 표시하는 방법. itextsharp를 사용하여 pdf를 만듭니다. 도와주세요.itextSharp를 사용하여 pdf에 특수 문자를 표시하려면
함께 작업하려면 더 많이 제공해야합니다. "작동하지 않음"은 무엇을 의미합니까? 다른 뭔가가 표시되거나 등장하지 않습니다. HTML을 파싱하시는 중이거나 일반 Phrase
및 Paragraph
클래스를 사용하고 계십니까? 다음은 일반적인 iTextSharp 클래스를 사용하는 전체 샘플과 HTMLWorker
을 사용하여 앰퍼샌드를 표시하는 것입니다. 세 가지 모두 나를 위해 잘 작동합니다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Create a new document
iTextSharp.text.Document Doc = new iTextSharp.text.Document(PageSize.LETTER);
//Write it to a memory stream
using (FileStream FS = new FileStream(Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop), "Output.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
{
object writer = PdfWriter.GetInstance(Doc, FS);
//Open the PDF for writing
Doc.Open();
//Insert a page
Doc.NewPage();
//Add a phrase with an ampersand
Doc.Add(new Phrase("Hello & Goodbye"));
//Create some HTML with an escaped and also unescaped ampersand
string Html = "<html><head><title></title></head><body><p>This is an escaped ampersand : &</p><p>And this is a non-escaped ampersand : &</body></html";
//Read the HTML in a StringRead
using (StringReader SR = new StringReader(Html))
{
//Grab the elements
List<IElement> elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(SR, null);
//Loop through them
for (int i = 0; i < elements.Count; i++)
{
//Add them to the document
Doc.Add(elements[i]);
}
}
//Close the PDF
Doc.Close();
}
this.Close();
}
}
}