本文整理匯總了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();
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
}
示例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;
}
示例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();
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}