1

私は次のコードを持っています。その出力はpdfファイルです:

フォーム MTR 17

官報の支払い請求書

                                DDO Code: 703

コードは次のとおりです。

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

using iTextSharp.text;
using iTextSharp.text.pdf;
public partial class new_salary : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/pdf";

        // Create PDF document
        Document pdfDocument = new Document(PageSize.A4, 70, 45, 40, 25);

        PdfWriter wri = PdfWriter.GetInstance(pdfDocument, new FileStream("d://JudgeSalary.pdf", FileMode.Create));

        PdfWriter.GetInstance(pdfDocument, HttpContext.Current.Response.OutputStream);

        pdfDocument.Open();

        Chunk boo = new Chunk("Form M.T.R. 17");


        Paragraph main1 = new Paragraph("Form M.T.R. 17 \nPAY-BILL OF GAZETTED OFFICER");
        main1.Alignment = Element.ALIGN_CENTER;
        main1.Font.SetStyle(Font.BOLD);

        Paragraph main1a = new Paragraph("          DDO Code: 703");
        main1a.Alignment = Element.ALIGN_RIGHT;





        pdfDocument.Add(main1);
        pdfDocument.Add(main1a);

        pdfDocument.Close();
        HttpContext.Current.Response.End();
    }
}

出力を次のようにしたい:

               **Form M.T.R. 17**

               **PAY-BILL OF GAZETTED OFFICER**                           DDO Code: 703

段落の 2 行目に「DDO コード: 703」があり、テキストの書式設定がない場合、上記の出力を取得するにはどうすればよいですか。「para1」に「DDO Code: 703」を含めると、テキストが太字で表示されます。この出力を中央揃えにして、右揃えにしたい「DDOコード:703」を受け入れます。

太字にしたくないし、段落の 2 行目に入れたい。どうすればできますか?

4

2 に答える 2

2

iTextSharp を使用すると、ChunkPhrase、またはでテキストを追加できますParagraph。これらがどのように機能するかについては、こちらのリファレンスを参照してください。基本的に、段落をいくつかのフレーズまたはチャンクとしてまとめて、さまざまなフォント スタイルを使用できるようにする必要があります。

必要な配置を実現するには、要素PdfPTableを適切に配置した が最適です。PdfPCell次のようなもの:

PdfPTable table = new PdfPTable(2);
PdfPCell cell = new PdfPCell(new Phrase("Form M.T.R. 17", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLD)));
cell.Colspan = 2;
cell.Border = 0;
cell.HorizontalAlignment = Element.ALIGN_LEFT; 
table.AddCell(cell);
table.AddCell(new Phrase("PAY-BILL OF GAZETTED OFFICER"));

PdfPCell rCell = new PdfPCell(new Phrase("DDO Code: 703", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12)));
rCell.Border = 0;
rCell.HorizontalAlignment = Element.ALIGN_RIGHT; 
table.AddCell(rCell);
pdfDocument.Add(table);
于 2011-02-21T07:27:04.873 に答える
0

段落は新しい行になります。次のように Phrase を使用してみてください。

Phrase main1 = new Phrase("Form M.T.R. 17 \nPAY-BILL OF GAZETTED OFFICER");
main1.Font.SetStyle(Font.BOLD);

Phrase main1a = new Paragraph(" DDO Code: 703");

pdfDocument.Add(main1);
pdfDocument.Add(main1a);
于 2011-02-21T21:04:13.667 に答える