private void PdfCodeDemo() 05
{ 06
float PDFWidth = 100; //PDF宽度 (72DPI像素值) 07
float PDFHeight = 100; //PDF高度 (72DPI像素值) 08
09
Rectangle rect = new Rectangle(PDFWidth, PDFHeight); 10
Document doc = new Document(rect); 11
12
//将PDF和文件路径关联 13
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("PDF存储路径", FileMode.Create)); 14
writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7); 15
16
//PDF信息写入 17
doc.AddCreationDate(); 18
doc.AddAuthor("作者"); 19
doc.AddCreator("创建人"); 20
doc.AddKeywords("关键字"); 21
doc.AddSubject("主题"); 22
doc.AddTitle("标题"); 23
24
doc.Open(); 25
PdfContentByte cb = writer.DirectContent; 26
27
//绘制图片 28
Image imageTemp = Image.GetInstance("图片路径"); 29
imageTemp.ScaleAbsolute(100,
skechers women, 100); //设置宽高 30
imageTemp.SetAbsolutePosition(0, 0); //设置位置 31
doc.Add(imageTemp); 32
33
//绘制文字 34
cb.BeginText(); 35
BaseFont bfBar = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\FZYBKSJW.TT F", BaseFont.IDENTITY_H,
shape up shoes, BaseFont.NOT_EMBEDDED); 36
cb.SetRGBColorFill(255, 255, 255); 37
cb.SetTextMatrix(100, 100); //位置 38
//cb.SetTextMatrix(0,
shape ups skechers, 1,
skechers shoes, -1, 0, textLeft, textTop); 90度 39
cb.SetFontAndSize(bfBar, 12); //字体及大小 40
cb.ShowText("文字内容"); 41
cb.EndText(); 42
43
//加载绘制现有PDF 44
PdfReader reader = new PdfReader("现有PDF路径"); 45
PdfImportedPage page = writer.GetImportedPage(reader, 1); 46
Image imagePdf = Image.GetInstance(page); 47
imagePdf.ScaleAbsolute(100, 100); 48
imagePdf.SetAbsolutePosition(0,
skechers shape ups, 0); 49
doc.Add(imagePdf); 50
reader.Close(); 51
52
//画线 53
cb.SetLineWidth(1); 54
cb.SetColorStroke(BaseColor.RED); 55
cb.MoveTo(0,
skechers outlet, 0); 56
cb.LineTo(100, 100); 57
cb.Stroke(); 58
59
//创建新页 60
Rectangle rectNew = new Rectangle(PDFWidth * 2, PDFHeight); 61
bool bo = doc.SetPageSize(rectNew); //改变新页尺寸 62
doc.NewPage(); 63
64
doc.Close(); 65
}