當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfStamper.Close方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfStamper.Close方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfStamper.Close方法的具體用法?C# PdfStamper.Close怎麽用?C# PdfStamper.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfStamper的用法示例。


在下文中一共展示了PdfStamper.Close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: Post

        /// <summary>
        /// Compress a pdf
        /// </summary>
        /// <param name="base64Pdf">A small model to hold a base64 encoded pdf object { "content" : "somebase64" }</param>
        /// <returns>{ "content" : "smallerBase64" }</returns>
        public IHttpActionResult Post(Base64Pdf base64Pdf)
        {
            try
            {
                if (base64Pdf.data == null)
                    return BadRequest("Check supplied pdf model");

                byte[] data = Convert.FromBase64String(base64Pdf.data);

                //Compress
                byte[] compressedData;
                using (var memStream = new MemoryStream())
                {
                    var reader = new PdfReader(data);
                    var stamper = new PdfStamper(reader, memStream, PdfWriter.VERSION_1_4);
                    var pageNum = reader.NumberOfPages;

                    for (var i = 1; i <= pageNum; i++)
                        reader.SetPageContent(i, reader.GetPageContent(i));

                    stamper.SetFullCompression();
                    stamper.Close();
                    reader.Close();

                    compressedData = memStream.ToArray();
                }
                var compressedBase64 = Convert.ToBase64String(compressedData);

                return Json(new Base64Pdf { data = compressedBase64 });
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
開發者ID:penance316,項目名稱:CompressPdfWebApi,代碼行數:40,代碼來源:PdfController.cs

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: WritePdf

        public static void WritePdf(Character character, string pathToPdf)
        {
            using (Stream stream = typeof(Functions).Assembly.GetManifestResourceStream("CharDown.CharacterSheet.pdf"))
            {
                var pdfReader = new PdfReader(stream);
                var pdfStamper = new PdfStamper(pdfReader, new FileStream(pathToPdf, FileMode.Create));
                var fields = pdfStamper.AcroFields;

                fields.SetField("CharacterName", character.CharacterName);

                fields.SetField("STR", character.Strength);
                fields.SetField("STRmod", character.StrengthModifier);
                fields.SetField("DEX", character.Dexterity);
                fields.SetField("DEXmod ", character.DexterityModifier);
                fields.SetField("CON", character.Constitution);
                fields.SetField("CONmod", character.ConstitutionModifier);
                fields.SetField("INT", character.Intelligence);
                fields.SetField("INTmod", character.IntelligenceModifier);
                fields.SetField("WIS", character.Wisdom);
                fields.SetField("WISmod", character.WisdomModifier);
                fields.SetField("CHA", character.Charisma);
                fields.SetField("CHamod", character.CharismaModifier);

                pdfStamper.Close();
            }
        }
開發者ID:half-ogre,項目名稱:chardown,代碼行數:26,代碼來源:WritePdf.cs

示例10: 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

示例11: ImprimirComprobante

        public virtual void ImprimirComprobante(long turnoId)
        {
            var turno = SessionFactory.GetCurrentSession().Load<Turno>(turnoId);
            //Valido que sea del paciente actual
            if (turno.Paciente.Id != User.As<Paciente>().Id)
                throw new SecurityException("El usuario actual no es al que se le otorgó el turno.");

            // Read the template
            var reader = new PdfReader(Server.MapPath("~/Reports/ComprobanteTurno.pdf"));

            // Writes the modified template to http response
            this.HttpContext.Response.Clear();
            this.HttpContext.Response.ContentType = "application/pdf";
            var stamper = new PdfStamper(reader, this.HttpContext.Response.OutputStream);

            // Retrieve the PDF form fields defined in the template
            var form = stamper.AcroFields;

            // Set values for the fields
            form.SetField("Fecha", turno.FechaTurno.ToString());
            form.SetField("Profesional", turno.Profesional.Persona.NombreCompleto);
            form.SetField("Especialidad", turno.Especialidad.Nombre);
            form.SetField("Paciente", turno.Paciente.Persona.NombreCompleto);
            form.SetField("Consultorio", turno.Consultorio.Nombre);

            // Setting this to true to make the document read-only
            stamper.FormFlattening = true;

            //Close the stamper instance
            stamper.Close();
        }
開發者ID:romartinez,項目名稱:sicemed,代碼行數:31,代碼來源:ObtenerTurnoController.cs

示例12: 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

示例13: 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

示例14: SaveTest

        private string SaveTest(string pdfTemplate, string pdfXmldata, string result)
        {
            string src = @"tmpl\PIT-36_2012.pdf";
            string data = @"tmpl\PIT-36.xml";
            string res = @"tmpl\PIT-36_2012_result.pdf";

            src = pdfTemplate;
            data = pdfXmldata;
            res = result;

           
            using (FileStream existingPdf = new FileStream(src, FileMode.Open))
            using (FileStream sourceXml = new FileStream(data, FileMode.Open))
            using (FileStream newPdf = new FileStream(res, FileMode.Create))
            {
                // Open existing PDF  
                PdfReader pdfReader = new PdfReader(existingPdf);
                PdfReader.unethicalreading = true;

                // PdfStamper, which will create  
                PdfStamper stamper = new PdfStamper(pdfReader, newPdf, '0', true);
                stamper.AcroFields.Xfa.FillXfaForm(sourceXml);

                stamper.Close();
                pdfReader.Close();
            }
            return res;
        }
開發者ID:Zawulon,項目名稱:jseverywhere,代碼行數:28,代碼來源:pdflib.cs

示例15: SingleTest

 private void SingleTest(string xfdfResourceName) {
     // merging the FDF file
     PdfReader pdfreader = TestResourceUtils.GetResourceAsPdfReader(TEST_RESOURCES_PATH, "SimpleRegistrationForm.pdf");
     PdfStamper stamp = new PdfStamper(pdfreader, new MemoryStream());
     string xfdfFile = TestResourceUtils.GetResourceAsTempFile(TEST_RESOURCES_PATH, xfdfResourceName);
     XfdfReader fdfreader = new XfdfReader(xfdfFile);
     AcroFields form = stamp.AcroFields;
     form.SetFields(fdfreader);
     stamp.Close();
 }
開發者ID:Niladri24dutta,項目名稱:itextsharp,代碼行數:10,代碼來源:AcroFieldsTest.cs


注:本文中的iTextSharp.text.pdf.PdfStamper.Close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。