Пример #1
0
        /// <summary>
        /// Applies the first page of the PDF file located at waterMarkImagePdfPath as a watermark
        /// to each page of the PDF file located at inputFilePath
        /// </summary>
        /// <param name="inputFilePath">File path of document to be watermarked</param>
        /// <param name="waterMarkImagePdfPath">File path of watermark template</param>
        public void AddWatermark(string inputFilePath, string waterMarkImagePdfPath)
        {
            var temp = inputFilePath + ".watermark";

            var watermarkImage = this.ConvertSinglePdfPageToJpegImage(waterMarkImagePdfPath, 1);

            using (var doc = new Doc())
            {
                doc.Read(inputFilePath);
                int theCount = doc.PageCount;

                int theID = 0;
                for (int i = 1; i <= theCount; i++)
                {
                    doc.PageNumber = i;
                    doc.Layer      = doc.LayerCount + 1;
                    if (i == 1)
                    {
                        theID = doc.AddImageFile(watermarkImage.FullName, 1);
                    }
                    else
                    {
                        doc.AddImageCopy(theID);
                    }
                }
                doc.Save(temp);
                doc.Clear();
                doc.Dispose();
            }

            File.Delete(inputFilePath);
            File.Move(temp, inputFilePath);
            File.Delete(watermarkImage.FullName);
        }
Пример #2
0
 public bool ConvertPdfFromImage(string imageFilePath, string pdfPath)
 {
     using (var doc = new Doc())
     {
         doc.AddImageFile(imageFilePath);
         doc.Save(pdfPath);
         return(true);
     }
 }
Пример #3
0
        private string ConvertJpgAsPdf(string imageFile, string testNamePrefix, string folderLocationToSaveFile)
        {
            using (var doc = new Doc())
            {
                var pdfName  = testNamePrefix + "_" + DateTime.Now.ToFileTimeUtc() + ".pdf";
                var filePath = folderLocationToSaveFile + pdfName;
                doc.AddImageFile(imageFile);
                doc.Save(filePath);

                return(pdfName);
            }
        }