String fontFileName = "simhei.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f); PdfDocument doc = new PdfDocument();
doc.LoadFromFile("test.pdf");
PdfPageBase page = doc.Pages[0];
String fontFileName = "simhei.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);
PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
brush.Graphics.SetTransparency(0.3f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
brush.Graphics.RotateTransform(-45);
brush.Graphics.DrawString("中文字体", trueTypeFont, PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
brush.Graphics.Restore();
brush.Graphics.SetTransparency(1);
page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
doc.SaveToFile("5622.pdf");String fontFileName = "C:\\Windows\\Fonts\\simhei.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f);String fontFileName = "simhei.ttf";
PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(fontFileName, 20f); brush.Graphics.DrawString("中文字体1\n中文字体2中文字体3\n中文字体4中文字体5", trueTypeFont, PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center)); string PDFPath = @"C:\PDFLocation\" + attachmentname + Guid.NewGuid().ToString() + ".pdf"; ;
FileStream WriteStream = File.Open(PDFPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
ReadWriteStream(attachmentFile.OpenBinaryStream(), WriteStream);
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(PDFPath);
foreach (PdfPageBase page in doc.Pages)
{
PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
brush.Graphics.SetTransparency(0.3f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
brush.Graphics.RotateTransform(-45);
brush.Graphics.DrawString(WaterMark, trueTypeFont, PdfBrushes.Black, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
brush.Graphics.Restore();
brush.Graphics.SetTransparency(1);
page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
}
Stream contentStream = attachmentFile.OpenBinaryStream();
//doc.SaveToFile(@"C:\LegalDatabasePDFLocation\" +Guid.NewGuid()+ "TestMark.pdf");
doc.SaveToFile(PDFPath);private void ReadWriteStream(Stream readStream, Stream writeStream)
{
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
// write the required bytes
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
}