Should i delete pdfwriter3/10/2023 Int pageHeight = Convert.ToInt32(pageSize.Height) pageSize = reader.GetPageSizeWithRotation(1) Designate the Temporary source to be used x and y are used to position the text and allow multiple different templates to use the same method public static void AddText(string pdfName, string filePath, string textToStamp, float? x = null, float? y = null) This allows stamping information on the page no matter what the layout is and gives it a small amount of customization. Using the information posted by Bruno, I came up with this solution. Gets the first page and sends the text to the upper left cornerĭocument.Add(new Paragraph("Hello World", MyFont)) Īny comments or suggests that you would like to add, feel free! Thank Var MyFont = FontFactory.GetFont("Times New Roman", 12, FontColour) ![]() Var FontColour = new BaseColor(255, 255, 255) PdfImportedPage page = writer.GetImportedPage(reader, p) PdfContentByte cb = writer.DirectContent create the ContentByte to give the text a position on the first page Using (PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filePath, FileMode.Create))) Using (Document document = new Document()) PdfReader reader = new PdfReader(tempPath) Make a new reader using the copied source file Make a Temporary copy of the original to manipulate ![]() Public static void stamp(string pdfName, string filePath, string textToStamp) Adds white invisible text to the pdf document that is highlightable The end goal of the text on the pdf that is highlightable. ![]() Im fairly new to programming in C#, pdf manipulation, and iTextSharp. I've looked at other answers involving the PdfStamper, but am having troubles manipulating existing code to work with what I am doing. This rotation causes the information to end up being cut off on the right hand side since the original layout was landscape. I cant find documentation on why the default layout is changed to portrait after text has been input on the pdf. However, when the source pdf's layout is landscape, the writer rotates the layout to portrait after inputting the text onto the first page of the pdf. Currently this has been working as intended for each pdf that that I had to input text on. I have a program that takes a pdf and prints text onto the first page using Itextsharp and PdfWriter.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |