• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# pdf.PdfStamper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中iTextSharp.text.pdf.PdfStamper的典型用法代码示例。如果您正苦于以下问题:C# PdfStamper类的具体用法?C# PdfStamper怎么用?C# PdfStamper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PdfStamper类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PdfStamper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DoGet

// ---------------------------------------------------------------------------
    /**
     * Show keys and values passed to the query string with GET
     */    
    protected void DoGet(byte[] pdf, Stream stream) {
      // We get a resource from our web app
      PdfReader reader = new PdfReader(pdf);
      // Now we create the PDF
      using (PdfStamper stamper = new PdfStamper(reader, stream)) {
        // We add a submit button to the existing form
        PushbuttonField button = new PushbuttonField(
          stamper.Writer, new Rectangle(90, 660, 140, 690), "submit"
        );
        button.Text = "POST";
        button.BackgroundColor = new GrayColor(0.7f);
        button.Visibility = PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT;
        PdfFormField submit = button.Field;
        submit.Action = PdfAction.CreateSubmitForm(
          WebContext.Request.RawUrl, null, 0
        );
        stamper.AddAnnotation(submit, 1);
        // We add an extra field that can be used to upload a file
        TextField file = new TextField(
          stamper.Writer, new Rectangle(160, 660, 470, 690), "image"
        );
        file.Options = TextField.FILE_SELECTION;
        file.BackgroundColor = new GrayColor(0.9f);
        PdfFormField upload = file.GetTextField();
        upload.SetAdditionalActions(PdfName.U,
          PdfAction.JavaScript(
            "this.getField('image').browseForFileToSubmit();"
            + "this.getField('submit').setFocus();",
            stamper.Writer
          )
        );
        stamper.AddAnnotation(upload, 1);
      }
    }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:38,代码来源:FDFServlet.cs


示例2: Write

 // --------------------------------------------------------------------------- 
 public void Write(Stream stream)
 {
     using (ZipFile zip = new ZipFile())
     {
         Stationery s = new Stationery();
         StampStationery ss = new StampStationery();
         byte[] stationery = s.CreateStationary();
         byte[] sStationery = ss.ManipulatePdf(
           ss.CreatePdf(), stationery
         );
         byte[] insertPages = ManipulatePdf(sStationery, stationery);
         zip.AddEntry(RESULT1, insertPages);
         // reorder the pages in the PDF
         PdfReader reader = new PdfReader(insertPages);
         reader.SelectPages("3-41,1-2");
         using (MemoryStream ms = new MemoryStream())
         {
             using (PdfStamper stamper = new PdfStamper(reader, ms))
             {
             }
             zip.AddEntry(RESULT2, ms.ToArray());
         }
         zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
         zip.AddEntry(Utility.ResultFileName(ss.ToString() + ".pdf"), sStationery);
         zip.Save(stream);
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:28,代码来源:InsertPages.cs


示例3: DecryptFile

        internal Boolean DecryptFile(
            string inputFile,
            string outputFile,
            IEnumerable<string> userPasswords)
        {
            foreach (var pwd in userPasswords)
            {
                try
                {
                    using (var reader = new PdfReader(inputFile, new ASCIIEncoding().GetBytes(pwd)))
                    {
                        reader.GetType().Field("encrypted").SetValue(reader, false);

                        using (var outStream = File.OpenWrite(outputFile))
                        {
                            using (var stamper = new PdfStamper(reader, outStream))
                            {
                                stamper.Close();
                            }
                        }
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat(ex, "Error trying to decrypt file {0}: {1}", inputFile, ex.Message);
                }
            }
            return false;

        }
开发者ID:ProximoSrl,项目名称:Jarvis.DocumentStore,代码行数:32,代码来源:PdfDecrypt.cs


示例4: Write

// ---------------------------------------------------------------------------    
    public virtual void Write(Stream stream) {  
      using (ZipFile zip = new ZipFile()) { 
        // Get the movies
        IEnumerable<Movie> movies = PojoFactory.GetMovies();
        string datasheet = Path.Combine(Utility.ResourcePdf, DATASHEET); 
        string className = this.ToString();            
        // Fill out the data sheet form with data
        foreach (Movie movie in movies) {
          if (movie.Year < 2007) continue;
          PdfReader reader = new PdfReader(datasheet);          
          string dest = string.Format(RESULT, movie.Imdb);
          using (MemoryStream ms = new MemoryStream()) {
            using (PdfStamper stamper = new PdfStamper(reader, ms)) {
              AcroFields fields = stamper.AcroFields;
              fields.GenerateAppearances = true;
              Fill(fields, movie);
              if (movie.Year == 2007) stamper.FormFlattening = true;
            }
            zip.AddEntry(dest, ms.ToArray());
          }         
        }
        zip.AddFile(datasheet, "");
        zip.Save(stream);
      }              
    }
开发者ID:,项目名称:,代码行数:26,代码来源:


示例5: WatermarkPDF_SN

 public bool WatermarkPDF_SN(string SourcePdfPath, string OutputPdfPath, string WatermarkPath, int positionX, int positionY, int WatermarkHeight, int WatermarkWidth, out string msg)
 {
     try
     {
         PdfReader reader = new PdfReader(SourcePdfPath);
         PdfStamper stamp = new PdfStamper(reader, new FileStream(OutputPdfPath, FileMode.Create));
         int n = reader.NumberOfPages;
         int i = 0;
         PdfContentByte under;
         iTextSharp.text.Image im = iTextSharp.text.Image.GetInstance(WatermarkPath);
         im.SetAbsolutePosition(positionX, positionY);
         im.ScaleAbsolute(WatermarkWidth, WatermarkHeight);
         while (i < n)
         {
             i++;
             under = stamp.GetUnderContent(i);
             under.AddImage(im, true);
         }
         stamp.Close();
         reader.Close();
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         return false;
     }
     msg = "��ˮӡ�ɹ���";
     return true;
 }
开发者ID:kingofhawks,项目名称:kcsj,代码行数:29,代码来源:ReadAttachFileWithZhang.aspx.cs


示例6: ManipulatePdf

// ---------------------------------------------------------------------------    
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
    // Create a table with named actions
      Font symbol = new Font(Font.FontFamily.SYMBOL, 20);
      PdfPTable table = new PdfPTable(4);
      table.DefaultCell.Border = Rectangle.NO_BORDER;
      table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
      Chunk first = new Chunk( ((char)220).ToString() , symbol);
      first.SetAction(new PdfAction(PdfAction.FIRSTPAGE));
      table.AddCell(new Phrase(first));
      Chunk previous = new Chunk( ((char)172).ToString(), symbol);
      previous.SetAction(new PdfAction(PdfAction.PREVPAGE));
      table.AddCell(new Phrase(previous));
      Chunk next = new Chunk( ((char)174).ToString(), symbol);
      next.SetAction(new PdfAction(PdfAction.NEXTPAGE));
      table.AddCell(new Phrase(next));
      Chunk last = new Chunk( ((char)222).ToString(), symbol);
      last.SetAction(new PdfAction(PdfAction.LASTPAGE));
      table.AddCell(new Phrase(last));
      table.TotalWidth = 120;
      
      // Create a reader
      PdfReader reader = new PdfReader(src);
      using (MemoryStream ms = new MemoryStream()) {
        // Create a stamper
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          // Add the table to each page
          PdfContentByte canvas;
          for (int i = 0; i < reader.NumberOfPages; ) {
            canvas = stamper.GetOverContent(++i);
            table.WriteSelectedRows(0, -1, 696, 36, canvas);
          }
        }
        return ms.ToArray();
      }    
    }    
开发者ID:,项目名称:,代码行数:40,代码来源:


示例7: Open

        /// <summary>
        /// uses itextsharp 4.1.6 to convert any pdf to 1.4 compatible pdf, called instead of PdfReader.open
        /// </summary>
        public static PdfDocument Open(MemoryStream sourceStream, string password = null)
        {
            PdfDocument outDoc;
            sourceStream.Position = 0;
            var mode = PdfDocumentOpenMode.Modify;

            try
            {
                outDoc = PdfReader.Open(sourceStream, mode);
            }
            catch (PdfReaderException)
            {
                sourceStream.Position = 0;
                var outputStream = new MemoryStream();

                var reader = password == null ?
                    new TextSharp.PdfReader(sourceStream) :
                    new TextSharp.PdfReader(sourceStream, Encoding.UTF8.GetBytes(password));

                var pdfStamper = new iTextSharp.text.pdf.PdfStamper(reader, outputStream) { FormFlattening = true };
                pdfStamper.Writer.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4);
                pdfStamper.Writer.CloseStream = false;
                pdfStamper.Close();

                outDoc = PdfReader.Open(outputStream, mode);
            }

            return outDoc;
        }
开发者ID:Syntox32,项目名称:BrettbokaExtractor,代码行数:32,代码来源:CompatiblePdfReader.cs


示例8: llenarFormulario

        //Permite cargar en un PDF información en los formularios preestablecidos.
        public void llenarFormulario(string archivoOrigen, string archivoFinal, string dato)
        {
            //Establece el archivo de entrada y de salida.
            string pdfTemplate = archivoOrigen;
            string newFile = archivoFinal;

            PdfReader pdfReader = new PdfReader(pdfTemplate);
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.OpenOrCreate));

            AcroFields pdfFormFields = pdfStamper.AcroFields;

            // Asigna los campos
            pdfFormFields.SetField("Colono", dato);

            //Muestra mensaje.
            //MessageBox.Show(sTmp, "Terminado");

            // Cambia la propiedad para que no se pueda editar el PDF
            pdfStamper.FormFlattening = true;
            pdfStamper.FreeTextFlattening = true;
            pdfStamper.Writer.CloseStream = true;
            pdfStamper.Close();

            // Cierra el PDF
            pdfStamper.Close();
            pdfReader.Close();
        }
开发者ID:hagi07,项目名称:Checador,代码行数:28,代码来源:Class1.cs


示例9: ManipulatePdf

// --------------------------------------------------------------------------- 
    /**
     * Manipulates a PDF file src
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
      PdfReader reader = new PdfReader(src);
      PdfObject obj;
      PdfDictionary action;
      for (int i = 1; i < reader.XrefSize; i++) {
      	obj = reader.GetPdfObject(i);
      	if (obj is PdfDictionary) {
      		action = ((PdfDictionary)obj).GetAsDict(PdfName.A);
      		if (action == null) continue;
      		if (PdfName.LAUNCH.Equals(action.GetAsName(PdfName.S))) {
      			action.Remove(PdfName.F);
      			action.Remove(PdfName.WIN);
      			action.Put(PdfName.S, PdfName.JAVASCRIPT);
      			action.Put(PdfName.JS, new PdfString(
      			  "app.alert('Launch Application Action removed by iText');\r"
      			));
      		}
      	}
      }        
      using (MemoryStream ms = new MemoryStream()) {
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
        }
        return ms.ToArray();
      }
    }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:30,代码来源:RemoveLaunchActions.cs


示例10: Create

        public async Task<byte[]> Create(Invoice invoice)
        {
            var formBytes = await GetInvoiceFormAsync();
            byte[] output = null;

            using (var rdr = new PdfReader(formBytes))
            {
                var outputStream = new MemoryStream();
                using (var stamper = new PdfStamper(rdr, outputStream))
                {
                    stamper.FormFlattening = true;
                    stamper.AcroFields.SetField("StartDate", invoice.StartDateTime.ToString("yyyy-MM-dd"));
                    stamper.AcroFields.SetField("EndAddress", invoice.EndAddress);
                    stamper.AcroFields.SetField("StartAddress", invoice.StartAddress);
                    stamper.AcroFields.SetField("Cost", invoice.Cost.ToString());
                    stamper.AcroFields.SetField("Distance", String.Format("{0} miles", invoice.Distance.ToString()));
                    stamper.AcroFields.SetField("Duration", String.Format("{0}''", invoice.Duration.ToString()));
                    stamper.AcroFields.SetField("EmployeeName", invoice.EmployeeName);
                    stamper.AcroFields.SetField("SignatureName", invoice.EmployeeName);
                    stamper.AcroFields.SetField("StartTime", invoice.StartDateTime.ToString("HH:mm:ss tt"));
                    stamper.AcroFields.SetField("Signature", Convert.ToBase64String(invoice.Signature));
                }
                output = (Byte[])outputStream.ToArray();
            }

            return output;
        }
开发者ID:EmiiFont,项目名称:MyShuttle_RC,代码行数:27,代码来源:InvoiceService.cs


示例11: RenameFieldsIn

 // ---------------------------------------------------------------------------    
 /**
  * Renames the fields in an interactive form.
  * @param datasheet the path to the original form
  * @param i a number that needs to be appended to the field names
  * @return a byte[] containing an altered PDF file
  */
 private static byte[] RenameFieldsIn(string datasheet, int i)
 {
     List<string> form_keys = new List<string>();
     using (var ms = new MemoryStream())
     {
         PdfReader reader = new PdfReader(datasheet);
         // Create the stamper
         using (PdfStamper stamper = new PdfStamper(reader, ms))
         {
             // Get the fields
             AcroFields form = stamper.AcroFields;
             // so we aren't hit with 'Collection was modified' exception
             foreach (string k in stamper.AcroFields.Fields.Keys)
             {
                 form_keys.Add(k);
             }
             // Loop over the fields
             foreach (string key in form_keys)
             {
                 // rename the fields
                 form.RenameField(key, string.Format("{0}_{1}", key, i));
             }
         }
         reader.Close();
         return ms.ToArray();
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:34,代码来源:ConcatenateForms2.cs


示例12: WritePDF

        public static void WritePDF(string outFilename, Dictionary<string, string> keys)
        {
            using (var existingFileStream = new FileStream(DefaultTemplatePath, FileMode.Open))
            using (var newFileStream = new FileStream(outFilename, FileMode.Create))
            {
                var pdfReader = new PdfReader(existingFileStream);
                var stamper = new PdfStamper(pdfReader, newFileStream);

                try
                {
                    var form = stamper.AcroFields;
                    var fieldKeys = form.Fields.Keys;
                    //File.WriteAllLines(@"fields.txt", fieldKeys.OfType<string>().ToArray());
                    foreach (string fieldKey in fieldKeys)
                    {
                        if (keys.ContainsKey(fieldKey))
                        {
                            form.SetField(fieldKey, keys[fieldKey]);
                        }
                    }
                    stamper.FormFlattening = true;
                }
                finally
                {
                    stamper.Close();
                    pdfReader.Close();
                }
            }
        }
开发者ID:sidfarkus,项目名称:highlands_school_reports,代码行数:29,代码来源:PDFWriter.cs


示例13: ManipulatePdf

 // ---------------------------------------------------------------------------  
 /**
  * Manipulates a PDF file src with the file dest as result
  * @param src the original PDF
  */
 public byte[] ManipulatePdf(byte[] src)
 {
     // Create a list with bookmarks
     List<Dictionary<string, object>> outlines =
         new List<Dictionary<string, object>>();
     Dictionary<string, object> map = new Dictionary<string, object>();
     outlines.Add(map);
     map.Add("Title", "Calendar");
     List<Dictionary<string, object>> kids =
         new List<Dictionary<string, object>>();
     map.Add("Kids", kids);
     int page = 1;
     IEnumerable<string> days = PojoFactory.GetDays();
     foreach (string day in days)
     {
         Dictionary<string, object> kid = new Dictionary<string, object>();
         kids.Add(kid);
         kid["Title"] = day;
         kid["Action"] = "GoTo";
         kid["Page"] = String.Format("{0} Fit", page++);
     }
     // Create a reader
     PdfReader reader = new PdfReader(src);
     using (MemoryStream ms = new MemoryStream())
     {
         // Create a stamper
         using (PdfStamper stamper = new PdfStamper(reader, ms))
         {
             stamper.Outlines = outlines;
         }
         return ms.ToArray();
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:38,代码来源:BookmarkedTimeTable.cs


示例14: ManipulatePdf

 // ---------------------------------------------------------------------------    
 /**
  * Manipulates a PDF file src with the file dest as result
  * @param src the original PDF
  */
 public byte[] ManipulatePdf(byte[] src)
 {
     // Create the reader
     PdfReader reader = new PdfReader(src);
     int n = reader.NumberOfPages;
     using (MemoryStream ms = new MemoryStream())
     {
         // Create the stamper
         using (PdfStamper stamper = new PdfStamper(reader, ms))
         {
             // Make a list with all the possible actions
             actions = new List<PdfAction>();
             PdfDestination d;
             for (int i = 0; i < n; )
             {
                 d = new PdfDestination(PdfDestination.FIT);
                 actions.Add(PdfAction.GotoLocalPage(++i, d, stamper.Writer));
             }
             // Add a navigation table to every page
             PdfContentByte canvas;
             for (int i = 0; i < n; )
             {
                 canvas = stamper.GetOverContent(++i);
                 CreateNavigationTable(i, n).WriteSelectedRows(0, -1, 696, 36, canvas);
             }
         }
         return ms.ToArray();
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:34,代码来源:TimetableDestinations.cs


示例15: FillForm

        public void FillForm(
            Dictionary<string, string> items,
            Stream formStream)
        {
            PdfStamper pdfStamper = new PdfStamper(pdfReader, formStream);
            AcroFields pdfFormFields = pdfStamper.AcroFields;
            BaseFont arialBaseFont;
            string arialFontPath;
            try
            {
                arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
                arialBaseFont = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            }
            catch (IOException)
            {
                arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");
                arialBaseFont = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            }

            pdfFormFields.AddSubstitutionFont(arialBaseFont);
            foreach (KeyValuePair<string, string> item in items)
            {
                pdfFormFields.SetFieldProperty(item.Key, "textfont", arialBaseFont, null);
                if (item.Value!=null) pdfFormFields.SetField(item.Key, item.Value);
            }
            pdfStamper.FormFlattening = false;
            pdfStamper.Close();
        }
开发者ID:PavelElis,项目名称:PGRLF.MainWeb,代码行数:28,代码来源:PDFForm.cs


示例16: GenerateCertificateDocument

 public void GenerateCertificateDocument(string targetFilename)
 {
     PdfReader reader = new PdfReader(_templateFilename);
     using (PdfStamper stamper = new PdfStamper(reader, new FileStream(targetFilename, FileMode.Create)))
     {
         AcroFields form = stamper.AcroFields;
         var fieldKeys = form.Fields.Keys;
         foreach (string fieldKey in fieldKeys)
         {
             if (fieldKey.Contains("issuedto1"))
                 form.SetField(fieldKey, Name[0]);
             if (fieldKey.Contains("issuedto2"))
                 form.SetField(fieldKey, Name[1]);
             if (fieldKey.Contains("certificatenumber"))
                 form.SetField(fieldKey, CertificateId);
             if (fieldKey.Contains("registeredtrack"))
                 form.SetField(fieldKey, RegisteredTrack);
             if (fieldKey.Contains("registrationdate"))
                 form.SetField(fieldKey, RegistrationDate);
             if (fieldKey.Contains("expirationdate"))
                 form.SetField(fieldKey, ExpirationDate);
             if (fieldKey.Contains("collaborators"))
                 form.SetField(fieldKey, Collaborators);
             if (fieldKey.Contains("agent"))
                 form.SetField(fieldKey, Agent);
         }
         stamper.FormFlattening = true;
     }
 }
开发者ID:nageshverma2003,项目名称:TrackProtectSource,代码行数:29,代码来源:CertificateDocument.cs


示例17: TestFlattening

        public virtual void TestFlattening()
        {
            const string INPUT_FOLDER = RESOURCES_FOLDER + "input/";
            const string CMP_FOLDER = RESOURCES_FOLDER + "cmp/";
            if (File.Exists(INPUT_FOLDER))
                Assert.Fail("Input folder can't be found (" + INPUT_FOLDER + ")");

            Directory.CreateDirectory(OUTPUT_FOLDER);

            String[] files = Directory.GetFiles(INPUT_FOLDER, "*.pdf");

            foreach (String file in files)
            {
                // flatten fields
                PdfReader reader = new PdfReader(file);
                PdfStamper stamper = new PdfStamper(reader, new FileStream(OUTPUT_FOLDER + Path.GetFileName(file), FileMode.Create));
                stamper.FormFlattening = true;
                stamper.Close();

                // compare
                CompareTool compareTool = new CompareTool();
                String errorMessage = compareTool.Compare(OUTPUT_FOLDER + Path.GetFileName(file), CMP_FOLDER + Path.GetFileName(file), OUTPUT_FOLDER, "diff");
                if (errorMessage != null)
                {
                    Assert.Fail(errorMessage);
                }
            }
        }
开发者ID:newlysoft,项目名称:itextsharp,代码行数:28,代码来源:FlatteningTest.cs


示例18: FillIRS941Form

        public byte[] FillIRS941Form(ReportPayrollCompanyTotal payrollData)
        {
            string iRS941FormTemplate = HttpContext.Current.Server.MapPath("~/FormTemplates/IRS2015Form941.pdf");
            byte[] formResults;

            using (PdfReader pdfReader = new PdfReader(iRS941FormTemplate))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    using (PdfStamper pdfStamper = new PdfStamper(pdfReader, ms))
                    {
                        AcroFields pdfFormFields = pdfStamper.AcroFields;
                        var s = pdfFormFields.GetSignatureNames();
                        var e = pdfFormFields.GetBlankSignatureNames();

                        pdfFormFields.SetField("f1_10_0_", "Suitland Road Baptist Church");

                        pdfStamper.FormFlattening = false;
                        pdfStamper.Close();
                    }

                    formResults = ms.GetBuffer();
                }
            }

            return formResults;
        }
开发者ID:joelmccune,项目名称:ChurchManager,代码行数:27,代码来源:PDFFormManager.cs


示例19: ManipulatePdf

 /// <summary>
 /// Fills out and flattens a form with the name, company and country.
 /// </summary>
 /// <param name="src"> the path to the original form </param>
 /// <param name="dest"> the path to the filled out form </param>
 public void ManipulatePdf(String src, String dest)
 {
     PdfReader reader = new PdfReader(src);
     PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create)); // create?
     int n = reader.NumberOfPages;
     Rectangle pagesize;
     for (int i = 1; i <= n; i++)
     {
         PdfContentByte under = stamper.GetUnderContent(i);
         pagesize = reader.GetPageSize(i);
         float x = (pagesize.Left + pagesize.Right)/2;
         float y = (pagesize.Bottom + pagesize.Top)/2;
         PdfGState gs = new PdfGState();
         gs.FillOpacity = 0.3f;
         under.SaveState();
         under.SetGState(gs);
         under.SetRGBColorFill(200, 200, 0);
         ColumnText.ShowTextAligned(under, Element.ALIGN_CENTER,
             new Phrase("Watermark", new Font(Font.FontFamily.HELVETICA, 120)),
             x, y, 45);
         under.RestoreState();
     }
     stamper.Close();
     reader.Close();
 }
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:30,代码来源:S03_CorrectedWatermark.cs


示例20: WatermarkPDF_SW

        public bool WatermarkPDF_SW(string SourcePdfPath, string OutputPdfPath, string WatermarkImageUrl, int positionX, int positionY, int WatermarkHeight, int WatermarkWidth, out string msg)
        {
            try
            {
                PdfReader reader = new PdfReader(SourcePdfPath);
                PdfStamper stamp = new PdfStamper(reader, new FileStream(OutputPdfPath, FileMode.Create));
                int n = reader.NumberOfPages;
                int i = 0;
                PdfContentByte under;
                WatermarkWidth = WatermarkWidth / n;
                //����ط�Ҫע�⣬�Ǹ���ҳ������̬����ͼƬ��ַ���м�ҳ�ͼ��ؼ�ҳ��ͼƬ
                string WatermarkPath = Server.MapPath(Request.ApplicationPath + "/HTProject/Pages/Images/��ͬ��������" + n + "/");
                string WatermarkPath2 = "";
                while (i < n)
                {
                    i++;
                    WatermarkPath2 = WatermarkPath + i + ".gif";
                    iTextSharp.text.Image im = iTextSharp.text.Image.GetInstance(WatermarkPath2);
                    im.SetAbsolutePosition(positionX, positionY);
                    im.ScaleAbsolute(WatermarkWidth, WatermarkHeight);

                    under = stamp.GetUnderContent(i);
                    under.AddImage(im, true);
                }
                stamp.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }
            msg = "��ˮӡ�ɹ���";
            return true;
        }
开发者ID:kingofhawks,项目名称:kcsj,代码行数:35,代码来源:ReadAttachFileWithZhang.aspx.cs



注:本文中的iTextSharp.text.pdf.PdfStamper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# pdf.PdfStamperImp类代码示例发布时间:2022-05-26
下一篇:
C# pdf.PdfSpotColor类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap