簡體   English   中英

如何在 PDF 中顯示“Times New Roman 字體”?

[英]How to display "Times New Roman font" in PDF?

我想將內容的字體更改為 TIMES NEW roman

iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(textSharpDocument);
#pragma warning restore 612, 618
String[] content = letterContent.Split(new string[] { AppUtil.GetAppSettings(AppConfigKey.ReceiptLetterPDFSeparator) }, StringSplitOptions.None);

//Add Content to File
if (content.Length > AppConstants.DEFAULT_PARAMETER_ZERO)
{
    string imageFolderPath = AppUtil.GetAppSettings(AppConfigKey.UploadedImageFolderPath);
    for (int counter = 0; counter < content.Length - 1; counter++)
    {
        textSharpDocument.Add(new Paragraph());
        if (!String.IsNullOrEmpty(imageUrlList[counter]))
        {
            string imageURL = imageFolderPath + imageUrlList[counter];
            textSharpDocument.Add(new Paragraph());
            string imagePath = AppUtil.GetAppSettings(AppConfigKey.ParticipantCommunicationFilePhysicalPath) + imageUrlList[counter];
            imagePath = imagePath.Replace(@"\", "/");
            if (File.Exists(imagePath))
            {
                iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(imageURL);
                imageLocationIDs[counter] = imageLocationIDs[counter] != null ? AppUtil.ConvertToInt(imageLocationIDs[counter], AppConstants.DEFAULT_PARAMETER_ONE) : AppUtil.ConvertEnumToInt(AppImageLocation.Left);

                if (imageLocationIDs[counter] == AppUtil.ConvertEnumToInt(AppImageLocation.Left))
                    png.Alignment = iTextSharp.text.Image.ALIGN_LEFT;
                if (imageLocationIDs[counter] == AppUtil.ConvertEnumToInt(AppImageLocation.Right))
                    png.Alignment = iTextSharp.text.Image.ALIGN_RIGHT;
                if (imageLocationIDs[counter] == AppUtil.ConvertEnumToInt(AppImageLocation.Center))
                    png.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
                textSharpDocument.Add(png);
            }
        }
        hw.Parse(new StringReader(content[counter]));
        hw.EndElement("</html>");
        hw.Parse(new StringReader(AppUtil.GetAppSettings(AppConfigKey.ReceiptLetterPDFSeparator)));
    }
}

你可以在 basefont 設置這樣的東西

BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
Font times = new Font(bfTimes, 12, Font.ITALIC, Color.BLACK);

Document doc = new Document();
PdfWriter.GetInstance(doc, new FileStream("c:\\Font.pdf", FileMode.Create));
doc.Open();
doc.Add(new Paragraph("This is a test using Times Roman", times));
doc.Close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM