public HttpResponseMessage UpdatePdfDoc(UpdatePDF updatePDF)
{
HttpResponseMessage response = null;
try
{
string ExistingVariableinPDF = updatePDF.ExistingVariableinPDF;
string ReplacingVariable = updatePDF.ReplacingVariable;
string ReplacingDateVariable = updatePDF.ReplacingDateVariable;
string sourceFile = @updatePDF.sourceFile;
Guid guid = Guid.NewGuid();
FileInfo fileInfo = new FileInfo(sourceFile);
string tempfilename = Path.Combine(fileInfo.Directory.FullName, guid.ToString() + fileInfo.Extension);
string destFile = @tempfilename;
PdfReader pReader = new PdfReader(sourceFile);
int numberOfPages = pReader.NumberOfPages;
FileStream fileStream = new System.IO.FileStream(destFile, System.IO.FileMode.Create);
stamper = new iTextSharp.text.pdf.PdfStamper(pReader, fileStream);
PDFTextGetter(ExistingVariableinPDF, ReplacingVariable, StringComparison.CurrentCultureIgnoreCase, sourceFile, destFile);
if (!String.IsNullOrEmpty(ReplacingDateVariable))
{
PDFTextGetter(ReplacingDateVariable, DateTime.Now.DisplayWithSuffix(), StringComparison.CurrentCultureIgnoreCase, sourceFile, destFile);
}
stamper.Close();
stamper.Dispose();
pReader.Close();
pReader.Dispose();
fileStream.Close();
fileInfo.Refresh();
File.Delete(sourceFile);
response = Request.CreateResponse(System.Net.HttpStatusCode.OK, guid.ToString());
}
catch (Exception ex)
{
response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
Logger.WriteLog("Exception while UpdatePdfDoc " + ex.Message + Environment.NewLine + ex.StackTrace);
}
// File.Move(tempfilename, sourceFile);
return(response);
}