PDF ye Filigran Ekleme

Excel dosyasını PDF’e dönüştürürken, PDF dosyasına filigran eklemek gibi gereksinimleriniz olabilir. Aşağıdaki örnekler, PDF dosyasına metin ve görüntü filigranı eklemenin nasıl yapıldığını gösterir.

Metin filigranı PDF’ye ekleme

Metin filigranını PDF’ye kolayca ekleyebilirsiniz, metni ve ilgili yazı tipini belirleyerek. Ayrıca, hizalama, ofset, döndürme, opaklık, ön/arka plan ve sayfaya ölçek gibi özellikleri RenderingWatermark içinde ayarlayabilirsiniz.

//prepare a workbook with 3 pages.
Workbook wb = new Workbook();
wb.Worksheets[0].Cells["A1"].PutValue("Page1");
int index = wb.Worksheets.Add();
wb.Worksheets[index].Cells["A1"].PutValue("Page2");
index = wb.Worksheets.Add();
wb.Worksheets[index].Cells["A1"].PutValue("Page3");
wb.Worksheets[index].PageSetup.PaperSize = PaperSizeType.PaperA3;
//create a font for watermark, and specify bold, italic, color.
RenderingFont font = new RenderingFont("Calibri", 68);
font.Italic = true;
font.Bold = true;
font.Color = Color.Blue;
//create a watermark from text and the specified font.
RenderingWatermark watermark = new RenderingWatermark("Watermark", font);
//specify horizontal and vertical alignment
watermark.HAlignment = TextAlignmentType.Center;
watermark.VAlignment = TextAlignmentType.Center;
//specify rotation
watermark.Rotation = 30;
//specify opacity
watermark.Opacity = 0.6f;
//specify the scale to page(e.g. 100, 50) in percent.
watermark.ScaleToPagePercent = 50;
//spcify watermark for rendering to pdf.
PdfSaveOptions options = new PdfSaveOptions();
options.Watermark = watermark;
wb.Save("output_text_watermark.pdf", options);

Görüntü filigranı PDF’ye ekleme

Görüntü filigranını PDF’ye sadece görüntünün baytlarını belirleyerek ekleyebilirsiniz. Ayrıca, hizalama, ofset, döndürme, opaklık, ön/arka plan ve sayfaya ölçek gibi özellikleri RenderingWatermark içinde ayarlayabilirsiniz.

//prepare a workbook with 3 pages.
Workbook wb = new Workbook();
wb.Worksheets[0].Cells["A1"].PutValue("Page1");
int index = wb.Worksheets.Add();
wb.Worksheets[index].Cells["A1"].PutValue("Page2");
index = wb.Worksheets.Add();
wb.Worksheets[index].Cells["A1"].PutValue("Page3");
wb.Worksheets[index].PageSetup.PaperSize = PaperSizeType.PaperA3;
//create a watermark from image(you need to prepare image bytes).
byte[] imageBytes = null;
RenderingWatermark watermark = new RenderingWatermark(imageBytes);
//specify offset to alignment.
watermark.OffsetX = 100;
watermark.OffsetY = 200;
//specify rotation
watermark.Rotation = 30;
//specify watermark to background.
watermark.IsBackground= true;
//specify opacity
watermark.Opacity = 0.6f;
//specify the scale to page(e.g. 100, 50) in percent.
watermark.ScaleToPagePercent = 50;
//spcify watermark for rendering to pdf.
PdfSaveOptions options = new PdfSaveOptions();
options.Watermark = watermark;
wb.Save("oputput_image_watermark.pdf", options);