private static void WatermarkFile(PDFDoc doc, WaterMarkInfo watermarkInfo) { using (var stamp = new Stamper(Stamper.SizeType.e_relative_scale, 1, 1)) { doc.InitSecurityHandler(); stamp.SetAlignment(Stamper.HorizontalAlignment.e_horizontal_center, Stamper.VerticalAlignment.e_vertical_center); stamp.SetFontColor(new ColorPt(0, 0, 0)); // set text color to red stamp.SetOpacity(0.1); stamp.SetRotation(-67); stamp.ShowsOnPrint(true); stamp.ShowsOnScreen(true); stamp.SetAsBackground(false); stamp.StampText(doc, watermarkInfo.CustomMessage + "\n" + watermarkInfo.UserIPAddress, new PageSet(1, doc.GetPageCount())); } }
public FileStreamWithPdftron(string pdfFilePath, FileItemStreamType streamType, WaterMarkInfo watermarkInfo) { var tempFilePath = string.Empty; try { tempFilePath = Path.GetTempFileName(); pdftron.PDFNet.Initialize(Properties.Settings.Default.PDFTronLicense); using (var doc = new PDFDoc(pdfFilePath)) { if (null != watermarkInfo) { WatermarkFile(doc, watermarkInfo); } if (streamType == FileItemStreamType.Downloadable) { doc.Save(tempFilePath, SDFDoc.SaveOptions.e_compatibility); } else { Convert.ToXod(doc, tempFilePath); } doc.Close(); } _wrappedStream = new FileStreamWithDelete(tempFilePath, FileMode.Open); } catch { if (File.Exists(tempFilePath)) { File.Delete(tempFilePath); } throw; } finally { if (File.Exists(pdfFilePath)) { File.Delete(pdfFilePath); } } }