Create a double-layer PDF using ipv4net 3.3.6
The so-called double-layer PDF is that each page contains two layers, the upper layer is the image, and the lower layer is the text corresponding to the image. You can browse images and copy and search text. In this way, both the reading effect and ease of use are taken into account.
Google searches. Most double-layer PDF production methods are implemented using OCR technology. The premise of these methods is that the original data is only an image and there is no corresponding text version. This is not covered in this article. This article mainly discusses how to create a double-layer PDF file for a word or other file that already has a text version. Specifically, there is a typographical Word file which is made into a double-layer PDF file.
The specific production process is as follows:
1. convert a text version of a file (Word) to a PDF file stored in text format, which can be achieved by using the pdfcreator in virtual printing mode. The file name is "pdf ".
2. convert the existing file (pdf) stored in the simplified format to a PDF file stored in the image format. ".
3. A new pdf file is generated by combining the PDF file stored in text mode and the PDF file stored in image mode by page. The PDF file in image mode is on the top. This is implemented by using ipv4net 3.3.6 for secondary development. The following code is written in C # in Visual Studio 2005.
(1) Add o2s. components. ipv4net. DLL to reference the project.
(2) Add a namespace reference
Using o2s. components. ipv4net;
Using o2s. components. ipv4net. pdffile;
Using o2s. components. ipv4net. graphics;
(3) write the following code:
String starttime = system. datetime. Now. tostring ();
// File1 is a PDF file in text format
Pdffile file1 = pdffile. fromfile (@ "D: \ pdf ");
// File2 is a PDF file in the Image Format
Pdffile file2 = pdffile. fromfile (@ "D: \ pile ");
If (file1.pagescount! = File2.pagescount ){
MessageBox. Show ("Two PDF files with diffrent pages ");
Return;
}
Registrant document DOC = new registrant document ();
For (INT I = 0; I <file1.pagescount; I ++)
{
Pdfimportedcontent IC1 = file1.extractpagecontent (I );
Pdfimportedcontent ic2 = file2.extractpagecontent (I );
Pdfpage Newpage = Doc. addpage ();
Pdflayer newlayer = Newpage. Canvas. layers. Add ("page" + I. tostring ());
Newlayer. Canvas. drawimportedcontent (IC1, ic1.x, ic1.y, ic1.width, ic1.height );
Newlayer. Canvas. drawimportedcontent (ic2, ic2.x, ic2.y, ic1.width, ic1.height );
Doc. addpage (Newpage );
}
// I don't know why. The same page of the merged PDF contains two copies. Therefore, we need to remove one of them in sequence.
If (Doc. pages. Count = file1.pagescount * 2)
{
For (INT I = Doc. pages. Count-1; I> 0; I-= 2)
{
Doc. pages. removeat (I );
}
}
// Save the merged PDF file to the file
Doc. savetofile (@ "D: \ 123.20 ");
MessageBox. Show ("Start Time:" + starttime + "End Time:" + system. datetime. Now. tostring ());
PS: In the trial version of ipv4net, a red line is added to the top of each page. Ipv4net has many other functions, which are very powerful.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/togis/archive/2009/05/26/4218789.aspx