Embed font into PDF file by using iText

If you are doing more work with iText, you may want to invest into the iText book – it has examples for all the features of iText. There is a parameter that you specify when you create your font that defines font embedding: BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); Font font = new Font(helvetica, 12, … Read more

How to extract images from a PDF with iText in the correct order?

I found an answer elsewhere, namely the iText mailing list. The following code works for me – please note that I switched to PdfBox: PDDocument document = null; document = PDDocument.load(inFile); List pages = document.getDocumentCatalog().getAllPages(); Iterator iter = pages.iterator(); while (iter.hasNext()) { PDPage page = (PDPage) iter.next(); PDResources resources = page.getResources(); Map pageImages = resources.getImages(); … Read more

What does “Not LTV-enabled” mean?

LTV (Long Term Validation) and PDF signatures The term LTV-enabled 4 Profile for PAdES-LTV 4.1 Overview Validation of an electronic signature requires data to validate the signature such as CA certificates, Certificate Revocation List (CRLs) or Certificate status information (OCSP) commonly provided by an online service (referred to in the present document as validation data). … Read more

ItextSharp Error on trying to parse html for pdf conversion

`HTMLWorker’ has been deprecated in favor of XMLWorker. Here is a working example tested with a snippet of HTML like you used above: StringReader html = new StringReader(@” <div style=”font-size: 18pt; font-weight: bold;”> Mouser Electronics <br />Authorized Distributor</div><br /> <br /> <div style=”font-size: 14pt;”>Click to View Pricing, Inventory, Delivery & Lifecycle Information: </div> <br /> … Read more

Extract Image from PDF using Java

You can use Pdfbox List pages = document.getDocumentCatalog().getAllPages(); Iterator iter = pages.iterator(); while( iter.hasNext() ) { PDPage page = (PDPage)iter.next(); PDResources resources = page.getResources(); Map images = resources.getImages(); if( images != null ) { Iterator imageIter = images.keySet().iterator(); while( imageIter.hasNext() ) { String key = (String)imageIter.next(); PDXObjectImage image = (PDXObjectImage)images.get( key ); String name = … Read more

iTextSharp Password Protected PDF

Yes, there are two passwords that you can pass to PdfEncryptor.Encrypt(), userPassword and ownerPassword. Just pass null to the userPassword and people will be able to open it without specify a password. string WorkingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string InputFile = Path.Combine(WorkingFolder, “Test.pdf”); string OutputFile = Path.Combine(WorkingFolder, “Test_enc.pdf”); using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) … Read more

itext positioning text absolutely

In the end I wrote my own method to do it. private void PlaceChunck(String text, int x, int y) { PdfContentByte cb = writer.DirectContent; BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.SaveState(); cb.BeginText(); cb.MoveText(x, y); cb.SetFontAndSize(bf, 12); cb.ShowText(text); cb.EndText(); cb.RestoreState(); }

How to add total page number on every page with iText?

Process the output from a PdfWriter to a bytestream first with a dummy page count. Create a PdfReader from that bytestream, calling PdfReader.getNumberOfPages to get the actual page count. Recreate the PDF output, knowing what the page count will be, changing the footer accordingly. It’s messy, but there’s no easy way to know the page … Read more