![]() ![]() put the alignment and coordinates hereĬb.ShowTextAligned(1, text, 520, 640, 0) Ĭb. String text = "Some random blablablabla." PdfWriter writer = PdfWriter.GetInstance(document, fs) īaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED) Rectangle size = reader.GetPageSizeWithRotation(1) įileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write) PdfReader reader = new PdfReader(oldFile) String newFile = "C:\Hola.pdf" // open the reader PdfWriter writer = PdfWriter.GetInstance(doc, ms) Ĭopier.AddPage(copier.GetImportedPage(rd, pageCounter)) PageStamp ps = pdfCopy.CreatePageStamp(page) īaseFont baseFont = BaseFont.CreateFont(string.Format("\\Fonts\\arialuni.ttf", Environment.GetEnvironmentVariable("windir"), BaseFont.CP1252, BaseFont.NOT_EMBEDDED) Ĭb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, printLangString, 100f, 40f, 0f) ĭocument doc = new Document(PageSize.A4) ![]() PdfImportedPage page = copier.GetImportedPage(reader, pageCounter) PdfCopy copier = new PdfCopy(doc, new FileStream("2.pdf", FileMode.Create)) įor (int pageCounter = 1 pageCounter < reader.NumberOfPages 1 pageCounter ) I've added an example how to add a footer too: PdfReader reader = new PdfReader("1.pdf") ĭocument document = new Document(reader.GetPageSize(1)) You will need to create a new pdf and add it If you need to do that (PdfCopy is the best for merging pdf). Under.ShowTextAligned(PdfContentByte.ALIGN_CENTER, userComments, xPosition, yPosition, angle) Under.SetFontAndSize(baseFont, fontSize) Under.SetColorFill(BaseColor.LIGHT_GRAY) PdfContentByte under = writer.DirectContentUnder īaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED) ![]() String outputFileName = Path.GetTempFileName() ".pdf" įloat xPosition = 4.Width / 2 įloat yPosition = (4.Height - 140f) / 2 private string AddWaterMarkPageToFile(string fileName, string userComments) Try This code: It adds a new page with existing pdf and add watermark text to that last page. Int rotation = reader.GetPageRotation(pageNumber) Ĭb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(pageNumber).Height) Ĭb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0) įont titleFont = new Font(.HELVETICAĬhunk titleChunk = new Chunk("Comments", titleFont) įont textFont = new Font(.HELVETICAĬhunk textChunk = new Chunk(userComments, textFont) PdfImportedPage page = writer.GetImportedPage(reader, pageNumber) Insert to Destination on the first page PdfReader reader = new PdfReader(filename) įor (int pageNumber = 1 pageNumber < reader.NumberOfPages 1 pageNumber )ĭocument.SetPageSize(reader.GetPageSizeWithRotation(1)) PdfContentByte cb = writer.DirectContent PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outputFileName, FileMode.Create)) Step 2: we create a writer that listens to the document String outputFileName = Path.GetTempFileName() Import static string AddCommentsToFile(string fileName, string userComments) Using iTextSharp To start, you’ll need to add a couple of using statements to your code: using iTextSharp.text using Then create a Document object: Document pdfDocument new Document ( ) Next, create an instance of the PdfWriter and point it to where you want to save this document. A negative value to the yPosition create an underline while a positive value will produce a strike through. You can use the Chunk‘s setUnderline(float thickness, float yPosition) method to add underline or strike through to a chunk. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |