Itext modify pdf
I am using the below code , but where can i implement in my code. According to your post, my understanding is that you want to edit PDF document and save the content using iTextSharp. AcroFields; form. SetField test. Key, test. Value ; form. SetFieldProperty test. Key, "setfflags", PdfFormField. Close ; reader.
Close ; stamper. Dev Center. Explore Why Office? Android ASP. Ask a question. The code to add the text is similar to what we did in chapter 2. Whether you're creating a document from scratch, or adding content to an existing document, has no impact on the instructions we use. The same goes for adding fields to a PdfAcroForm instance:. In the FillAndModifyForm example, we return to the FillForm example from chapter 4, but instead of merely filling out the form, we also change the properties of the fields:.
We convert this List to a PdfArray line 16 and we use this array to update the options of the "shift" field line We see that the "shift" field now has more options, but we don't see the background color of the "name" field. It's also not clear if the font of the "info" field has changed. What's wrong? Nothing is wrong, the fields are currently highlighted and the blue highlighting covers the background color.
Let's click "Highlight Existing Fields" and see what happens. Now Figure 5. We wouldn't have had this problem if we had added form. We'll make some more forms examples in the next chapter, but for now, let's see what we can do with existing documents that don't contain a form.
Do you remember the report of the UFO sightings in the 20th century we created in chapter 3? We'll use a similar report for the next couple of examples: ufo. As you can see, it's not so fancy as the report we made in chapter 3. What if we'd like to add a header, a watermark and a footer saying "page X of Y" to this existing report? Figure 5. In Figure 5.
In chapter 3, we didn't know the total number of pages at the moment we were adding the footer, hence we only added the current page number. Now that we have an existing document, we can add "1 of 4", "2 of 4", and so on. When creating a document from scratch, it's possible to create a placeholder for the total number of pages. Once all the pages are created, we can then add the total number of pages to that placeholder, but that's outside the scope of this introductory tutorial.
The AddContent example shows how we can add content to every page in an existing document. We use the pdfDoc object to create a Document instance. We'll use that document object to add some content.
We also use the pdfDoc object to find the number of pages in the original PDF. We loop over all the pages, and we get the PdfPage object of each page. A header line : we use low-level text functionality to add "I want to believe" at the top of the page. A footer line line : we use low-level graphics functionality to draw a line at the bottom of the page.
A footer with the page number : we use low-level text functionality to add the page number, followed by " of " , followed by the total number of pages at the bottom of the page. A watermark lin : we create a Paragraph with the text we want to add as a watermark. Then we change the opacity of the canvas. Finally we add the Paragraph to the document, centered in the middle of the page and with an angle of 45 degrees, using the showTextAligned method.
We're doing something special when we add the watermark. We're changing the graphics state of the canvas object obtained from the page. Then we add text to the corresponding page in the document.
Internally, iText will detect that we're already using the PdfCanvas instance of that page and the showTextAligned method will write to that same canvas. This way, we can use a mix of low-level and convenience methods. In the final example of this chapter, we'll change the page size and orientation of the pages of our UFO sightings report.
If we take a look at Figure 5. The ChangePage example shows how this was done. CreateFont fontPath, BaseFont. ShowTextAligned canvas, Element. GetTop iTextSharp. Improve this question. Mark 7, 14 14 gold badges 45 45 silver badges 78 78 bronze badges. Mina N Mina N 2 2 gold badges 7 7 silver badges 17 17 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.
The Overflow Blog.
0コメント