"edit pdf itextsharip" Code Answer's

You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "edit pdf itextsharip" answered properly. Developers are finding an appropriate answer about edit pdf itextsharip related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like edit pdf itextsharip. Enter your desired code related query in the search bar and get every piece of information about C# code related question on edit pdf itextsharip. 

edit pdf itextsharip

By Ugly UnicornUgly Unicorn on Dec 22, 2020
string oldFile = "oldFile.pdf";
string newFile = "newFile.pdf";

// open the reader
PdfReader reader = new PdfReader(oldFile);
Rectangle size = reader.GetPageSizeWithRotation(1);
Document document = new Document(size);

// open the writer
FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();

// the pdf content
PdfContentByte cb = writer.DirectContent;

// select the font properties
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.DARK_GRAY);
cb.SetFontAndSize(bf, 8);

// write the text in the pdf content
cb.BeginText();
string text = "Some random blablablabla...";
// put the alignment and coordinates here
cb.ShowTextAligned(1, text, 520, 640, 0);
cb.EndText();
cb.BeginText();
text = "Other random blabla...";
// put the alignment and coordinates here
cb.ShowTextAligned(2, text, 100, 200, 0);
cb.EndText();

// create the new page and add it to the pdf
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);

// close the streams and voilá the file should be changed :)
document.Close();
fs.Close();
writer.Close();
reader.Close();

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the C# based application and are stuck on edit pdf itextsharip can get a collection of related answers to their query. Programmers need to enter their query on edit pdf itextsharip related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about edit pdf itextsharip for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of edit pdf itextsharip while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "edit pdf itextsharip". Visit this developer's friendly online web community, CodeProZone, and get your queries like edit pdf itextsharip resolved professionally and stay updated to the latest C# updates. 

C# answers related to "edit pdf itextsharip"

View All C# queries

C# queries related to "edit pdf itextsharip"

Browse Other Code Languages

CodeProZone