如何使用iTextSharp的编写UTF-8字符到PDF文件?如何使用、字符、文件、UTF

2023-09-02 10:51:56 作者:心中有梦闯天下

我已经尝试了很多谷歌,但不能找到。

任何帮助是AP preciated ..

PLZ帮助..

请在下面找到了code: -

 保护无效的Page_Load(对象发件人,EventArgs的)
    {
        StreamReader的阅读=新的StreamReader(@D: queryUni code.txt,Encoding.Uni code);
        字符串str = read.ReadToEnd();

        para段落=新段(STR);

        的FileStream文件=新的FileStream(@D: Query.pdf,FileMode.Create);

        文档pdfDoc =新的文件();
        PdfWriter作家= PdfWriter.GetInstance(pdfDoc,文件);

        pdfDoc.Open();
        pdfDoc.Add(对位);
        pdfDoc.Close();

        回复于(PDF格式文件生成);
    }
 

解决方案 PDF之itextsharp的使用开发最终成品软件 3个

您将HTML转换为PDF格式?如果是这样,你应该注意的是,否则没关系。我想问的唯一原因是,你对获得最后的评论&放大器;#230; 让我觉得。如果你是,看看这个帖子: iTextSharp的5指甲油字符

此外,有时当人们说统一code他们真正想要做的是得到像Wingdings符号转换成PDF格式。如果你的意思是看看这篇文章,知道统一code和狂欢的符号真的是一点都没有关系。在iTextSharp的 统一code符号

下面是一个使用两种方式使用使用C#转义序列字符本身,一个写的Uni code字,一个完整的工作示例。确保将文件保存在支持宽字符格式。此示例使用iTextSharp的5.0.5。

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;
使用iTextSharp.text;
使用iTextSharp.text.pdf;
使用System.IO;

命名空间ConsoleApplication1
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            //创建我们的文档对象
            文档文档=新的文件(PageSize.LETTER);

            //创建我们的文件流
            使用(的FileStream FS =新的FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)的test.pdf),FileMode.Create,FileAccess.Write,FileShare.Read))
            {
                //绑定PDF作家文档和流
                PdfWriter作家= PdfWriter.GetInstance(DOC,FS);

                //写入打开文件
                Doc.Open();

                //添加页面
                Doc.NewPage();

                //完整路径统一code宋体文件
                串ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),ARIALUNI.TTF);

                //创建一个基本字体对象,并确保指定Identity-H
                BASEFONT BF = BaseFont.CreateFont(ARIALUNI_TFF,BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);

                //创建一个特定的字体对象
                字体F =新的字体(BF,12,Font.NORMAL);

                //写一些文字,最后一个字符是0x0278  - 拉丁小写字母PHI
                Doc.Add(新词(这是一个测试ɸ,F));

                //写一些文字,最后一个字符是0x0682  - 在两个点以上垂直阿拉伯字母HAH
                Doc.Add(新词(你好 u0682,F));

                //关闭PDF
                Doc.Close();
            }
        }
    }
}
 

当与iTextSharp的工作,你必须确保你正在使用支持单向code code要使用点的字体。您还需要指定身份-H 使用字体时。我不完全知道这意味着什么,但有一些关于它的谈话在这里: iTextSharp的国际文本

I have tried a lot on google but not able to find..

Any help is appreciated..

Plz help..

Please find the code below:-

protected void Page_Load(object sender, EventArgs e)
    {
        StreamReader read = new StreamReader(@"D:queryUnicode.txt", Encoding.Unicode);
        string str = read.ReadToEnd();

        Paragraph para = new Paragraph(str);

        FileStream file = new FileStream(@"D:Query.pdf",FileMode.Create);

        Document pdfDoc = new Document();
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, file );

        pdfDoc.Open();
        pdfDoc.Add(para);
        pdfDoc.Close();

        Response.Write("Pdf file generated");
    }

解决方案

Are you converting HTML to PDF? If so, you should note that, otherwise never mind. The only reason I ask is that your last comment about getting æ makes me think that. If you are, check out this post: iTextSharp 5 polish character

Also, sometimes when people say "Unicode" what they're really trying to do is to get symbols like Wingdings into a PDF. If you mean that check out this post and know that Unicode and Wingding Symbols really aren't related at all. Unicode Symbols in iTextSharp

Here's a complete working example that uses two ways to write Unicode characters, one using the character itself and one using the C# escape sequence. Make sure to save your file in a format that supports wide characters. This sample uses iTextSharp 5.0.5.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create our document object
            Document Doc = new Document(PageSize.LETTER);

            //Create our file stream
            using (FileStream fs = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                //Bind PDF writer to document and stream
                PdfWriter writer = PdfWriter.GetInstance(Doc, fs);

                //Open document for writing
                Doc.Open();

                //Add a page
                Doc.NewPage();

                //Full path to the Unicode Arial file
                string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");

                //Create a base font object making sure to specify IDENTITY-H
                BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                //Create a specific font object
                Font f = new Font(bf, 12, Font.NORMAL);

                //Write some text, the last character is 0x0278 - LATIN SMALL LETTER PHI
                Doc.Add(new Phrase("This is a test ɸ", f));

                //Write some more text, the last character is 0x0682 - ARABIC LETTER HAH WITH TWO DOTS VERTICAL ABOVE
                Doc.Add(new Phrase("Hellou0682", f));

                //Close the PDF
                Doc.Close();
            }
        }
    }
}

When working with iTextSharp you have to make sure that you're using a font that supports the Unicode code points that you want to use. You also need to specify IDENTITY-H when using your font. I don't completely know what it means but there's some talk about it here: iTextSharp international text

 
精彩推荐
图片推荐