Generate PDF full guide: add content on existing PDF, pdf full Guide
The project is changing, the demand is changing, and what remains unchanged is the programmer who clicks the keyboard .....
After a PDF file is generated, you sometimes need to add other content on the PDF file, such as text, images ....
After several failed attempts, I finally got the correct code writing method.
Record the summary here, so that you can continue to renew it again. For the required jar files, go to: generate a
The project is changing, the demand is changing, the invariable is always the programmer tapping the keyboard ...
After the PDF is generated, it is sometimes necessary to add some other content to the PDF, such as text, pictures ....
After several failed attempts, I finally got the right way to write code.
Summary of this record to facilitate the next status quo, need the jar please go: Build PDF Full Raiders
Pdfreader reader = new Pdfreader ("E:\\a.pdf");
to create a document block for display in a PDF document that can be displayed side-by-side in the same row.3) When displaying non-English characters in a PDF document, you need to use the static method of the Basefont class CreateFont (String name,string encoding,boolean Embedded) to re-encode the text. When working with Chinese, name is the specific Chinese font name, and the encoding value is unigb-ucs2-h,embedded with the font constant not_embedded. 2. Add page numbers to the documentExampl
1, first to write a PDF tool class, and related tools 2. PDF of the required jar package Itext is a Java component that generates PDF reportsFreemarker is based on a template to generate text output 3. You need to use Adobe Acrobat Pro software to convert the template you want to create into PDF format Open Adobe Acrobat Pro, open the template, select |--Prepare the form, it automatically detects and names the form field, and then saves it in PDF formatPDF Tool Classpublic class Pdftemplet {p
Using the itextsharp to add a PDF watermark, because it is the interface dynamically generated PDF, so the use is all the form of memory flow, and the watermark is tiled is. Itextsharp version is 5.51 /// 2 ///add an oblique watermark3 /// 4 /// PDF file Stream5 /// Watermark String6 /// Page Width7 /// page Height8 PublicMemoryStream Setwatermark (MemoryStream pdfstream,stringWatermarkname,floatWidthfloatheight)9 {Ten
();X509certificateentry [] Ce = pk12.getcertificatechain (alias );This. Chain = new org. bouncycastle. x509.x509certificate [Ce. Length];For (int K = 0; k Chain [k] = Ce [K]. getcertificate ();
}
This method retrieves the certificate, traverses all its elements, and extracts the private key. If possible, it also creates a certificate chain.
Sign () method:
Public void sign (string sigreason, string sigcontact, string siglocation, bool visible){Pdfreader reader = new pdfreader (this. inpu
Package Com.test;import Com.itextpdf.text.basecolor;import Com.itextpdf.text.font;import com.itextpdf.text.Image; Import Com.itextpdf.text.pdf.*;import org.junit.test;import java.io.fileoutputstream;/** * Edit PDF */public Class pdftest {@Test public void testpdf () {generatepdf ("d:/1.pdf", "D:/2.pdf", "d:1.png"); }/** * Generate a new PDF * @param pdfpath the PDF path to edit * @param newpdfpath generate a new PDF path * @param imagePath Insert Picture Path */public void gene
problem with this program and the pictures you can export for some PDF files cannot be opened.
second, the removal of the PDF file watermark font
/** * The above class is officially given as a tool class
public static void Main (string[] args) {try {pdfreader pdfreader = new Pdfreader ("D:/1.pdf");
FileOutputStream OS = new FileOutputStream ("D:/reader.pdf");
Pdfstamper stamper = new Pdfstamper (
Recently, the project needs to investigate how to add the logo in pdf to differentiate versions. Finally, it is determined to use itext for implementation.
The Code is as follows:
Java code/*** Authory kingviker* Time: 2012-12-12*/Import java. io. FileOutputStream;Import java. io. IOException; www.2cto.comImport com. itextpdf. text. DocumentException;Import com. itextpdf. text. Font;Import com. itextpdf. text. Image;Import com.itext;.text=. BaseFont;Import com.itext;.text=. PdfArray;Import com.i
This method has also been used for a long time, because the amount of data is less.
At the beginning, Adobe livecycle designer can also be used to insert an empty chapter into a pdf. However, the fieldid of an empty chapter is long.
"Topmostsubform [0]. page1 [0]. A [0] ", cannot be located when checking the kernel. you can use the existing PDF file of the itextsharp connector Stamper!
However, it takes a long time to find the reader flow to the internal writer.
Public void addemptysignat
When we use your Stamper to merge fields. We will find
"This file is damaged, Adobe Acrobat can not repair the document
Most Adobe versions, give message "this file is damaged", but it can repair.
Unfortunately some versions can not repair ."
Memorystream stream = new memorystream ();
Pdfreader reader = new pdfreader (PATH );Pdfstamper Stamper = new pdfstamper (reader, stream );
Required Fields AF =
Recent projects need to generate a PDF file according to the information that the customer has filled out in accordance with the template.If the format is a fixed type, you can use Adobe Acrobat DC to convert the template's PDF file into a type that can be edited, and then insert the data into it based on the name of the variable that was taken when editing.First, you need to import the Itextpdf jar package.Template pathString TemplatePath = "E:/test.pdf";The new file path generatedString Newpdf
Some times we need make a series PDF from an single PDF Template
From above two article we know how to make an single PDF. And how to add page to new pdf.
From some other actile of Internet we may be get writer. copypolicform (Reader)But I find just the last PDF (copy from the single PDF) have these values.Other fields are empty
OK how to do it. memorystream stream = new memorystream ();Document Doc = new document ();Synchronized copy writer = new synchronized copy (Doc, stream );Doc. open ();S
I recently wrote a PDF resolution library and an editing Library (C ++/C), and finally found that the image was inserted into the PDF, and the image displayed in the PDF was overwritten by the original content. You can use Adobe to create a file to check whether any exceptions have been found. Therefore, if you want to use itextsharp to insert an image for testing, you can find that most of the information written on the internet is inserting an image when generating a PDF file. Search for infor
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.