以下是程式碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using iText.Kernel.Pdf.Canvas.Draw;
using iText.IO.Image;
namespace GeneratePdfDemo
{
class Program
{
static void Main(string[] args)
{
PdfWriter writer = new PdfWriter("D:\\demo.pdf");
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
Paragraph header = new Paragraph("HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(20);
document.Add(header);
Paragraph subheader = new Paragraph("SUB HEADER")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(15);
document.Add(subheader);
LineSeparator ls = new LineSeparator(new SolidLine());
document.Add(ls);
Paragraph paragraph1 = new Paragraph("Lorem ipsum " +
"dolor sit amet, consectetur adipiscing elit, " +
"sed do eiusmod tempor incididunt ut labore " +
"et dolore magna aliqua.");
document.Add(paragraph1);
Image img = new Image(ImageDataFactory
.Create(@"image.png"))
.SetTextAlignment(TextAlignment.CENTER);
document.Add(img);
document.Close();
}
}
}
輸出結果圖:
請問為什麼pdf中的圖沒有置中?