itext7

iText 7 - Add and Remove Watermark on a PDF

佐手、 提交于 2019-12-05 19:48:51
I would like to add and remove a watermark to a PDF using iText 7. I was able to add the watermark, but unable to remove it again. I could only find relevant code/examples related to iText 5. Any pointers appreciated, thanks. This is how I added the Watermark (using Layers): pdfDoc = new PdfDocument(new PdfReader(sourceFile), new PdfWriter(destinationPath)); var numberOfPages = pdfDoc.GetNumberOfPages(); PageSize ps = pdfDoc.GetDefaultPageSize(); for (var i = 1; i <= numberOfPages; i++) { PdfPage page = pdfDoc.GetPage(i); PdfLayer layer = new PdfLayer("watermark", pdfDoc); var canvas = new

How to get the text position from the pdf page in iText 7

≡放荡痞女 提交于 2019-12-04 16:29:32
I am trying to find the text position in PDF page? What I have tried is to get the text in the PDF page by PDF Text Extractor using simple text extraction strategy. I am looping each word to check if my word exists. split the words using: var Words = pdftextextractor.Split(new char[] { ' ', '\n' }); What I wasn't able to do is to find the text position. The problem is I wasn't able to find the location of the text. All I need to find is the y co-ordinates of the word in the PDF file. First, SimpleTextExtractionStrategy is not exactly the 'smartest' strategy (as the name would suggest. Second,

iText 7: How to build a paragraph mixing different fonts?

非 Y 不嫁゛ 提交于 2019-12-04 13:04:15
I've been using iText 7 for a few days to build pdf files, unfortunately, iText 7 is very different from iText 5 and the documentation is still very incomplete. I'm trying to build a paragraph that mixes two fonts or two fonts style (example: have a bold text in the middle of a paragraph) Using iText 5 this would be done using Chunks: Font regular = new Font(FontFamily.HELVETICA, 12); Font bold = Font font = new Font(FontFamily.HELVETICA, 12, Font.BOLD); Phrase p = new Phrase("NAME: ", bold); p.add(new Chunk(cc_cust_dob, regular)); PdfPCell cell = new PdfPCell(p); Using iText 7, I still haven

How to create template and generate pdf using template and database data iText C#

随声附和 提交于 2019-12-04 06:53:41
问题 I want to do below task using iText7. create template using HTML or ..(some fields can be able to hide according to user input) Fill the template with the database data generate accessible pdf How can I do this? 回答1: As far as I understand, you want to have an HTML template where you will fill in data based on user input as well as data coming from your database. This is possible in iText in general, however you would need to do a lot of work, especially if you want to have a template for the

Manipulate paths, color etc. in iText

与世无争的帅哥 提交于 2019-12-04 06:41:52
问题 I need to analyze path data of PDF files and manipulate content with iText 7. Manipulations include deletion/replacemant and coloring. I can analyze the graphics alright with something like the following code: public class ContentParsing { public static void main(String[] args) throws IOException { new ContentParsing().inspectPdf("testdata/test.pdf"); } public void inspectPdf(String path) throws IOException { File file = new File(path); PdfDocument pdf = new PdfDocument(new PdfReader(file

How during work itext find out coordinates text?

 ̄綄美尐妖づ 提交于 2019-12-04 06:35:52
问题 I want to know the coordinates of the text that is added to the page. And apply some canvas to this text. (for example custom underline or strikethrough or text inside the triangle) I only need certain words List<String> listString = new ArraList(); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST)); Document doc = new Document(pdfDoc, PageSize.A4); for(String s:listString) //**underlineWord** hidden it will be removed if( s.contains("**underlineWord**")){ s.replace("**underlineWord**"

Stretching internal content inside the cell iText 7 PDF

戏子无情 提交于 2019-12-04 05:40:22
问题 I still fight with iText, and it looks like he's running over me. I already asked the question here, but most likely the question was so abstract that I could not get answers. So, I have a table with two cells - notesCell and priceCell: public void GenerateTable(SimpleProductVM product) { // Create the table var productTable = new Table(new float[] { 1, 1 }) .SetWidth(UnitValue.CreatePercentValue(100)) .SetKeepTogether(true); // Create a cell of the notes var notesCell = CreateNotesCell

iText 7: Paragraph height as it would be rendered

心已入冬 提交于 2019-12-03 16:25:40
I can set the width of a new paragraph as follows, which results in a certain height: Paragraph p = new Paragraph("some longer text some longer text some longer text"); p.setWidth(100); System.out.println("height " + p.getHeight()); document.add(p); Of course p.getHeight() is null , since the rendered height is calculated during rendering the PDF file. But I need the height before the final rendering. How can I get it most efficiently? To get the effective width of the paragraph as if it was drawn on a page already, you need to create renderer tree from model element tree, and then layout the

Font size for Name and Description PDF Digital signature

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 22:29:31
问题 If I use font size appearance.setLayer2FontSize(6.0f); it sets font size for both Name and Description. PdfReader reader = null; PdfSigner signer = null; try { reader = new PdfReader(inStream); signer = new PdfSigner(reader, pdfos, false); } catch (IOException e) { LOGGER.error("Error while loading PDF"); throw new DigitalSignException("Error while loading PDF", e); } int noOfPages = signer.getDocument().getNumberOfPages(); PdfSignatureAppearance appearance = signer.getSignatureAppearance()

iText7 Convert PDF to Image

梦想的初衷 提交于 2019-12-02 16:36:35
问题 Please let me know what method can be used to convert pdf to image in iText7. In Itexsharp, there was an option to convert pdf file to images. Following is the link. PDF to Image Using iTextSharp http://www.c-sharpcorner.com/UploadFile/a0927b/create-pdf-document-and-convert-to-image-programmatically/ Below is the sample code created using the following refernce link. itext7 pdf to image this is not working as expected. It is not converting the pdf to image. It is creating a 1kb blank image.