Difference between revisions of "PDF"
Line 197: | Line 197: | ||
Add reference to the iTextSharp library | Add reference to the iTextSharp library | ||
− | + | 1. Download iTextSharp | |
− | + | ||
− | + | Download the iTextSharp library at http://sourceforge.net/projects/itextsharp/ | |
− | + | ||
− | + | 2. Extract the iTextSharp library | |
+ | |||
+ | Extract the library to a new folder that you can find again. I extracted mine to my Visual Studio directory. For example, "\Visual Studio 2010\external libraries\iText lib" | ||
+ | |||
+ | 3. Create a new C# Windows Forms project | ||
Start Visual Studio 2010. Select "New Project". Next, under C#, select "Windows Forms Application". Name the solution something like "FormFillerPDF" and select "OK" | Start Visual Studio 2010. Select "New Project". Next, under C#, select "Windows Forms Application". Name the solution something like "FormFillerPDF" and select "OK" | ||
− | + | ||
− | + | 4. Add a reference to the iTextSharp library | |
+ | |||
In your Solution Explorer, right click on "Reference". Left-click on "Add Reference..." (Figure 4.1) | In your Solution Explorer, right click on "Reference". Left-click on "Add Reference..." (Figure 4.1) | ||
(Alternatively, you can also select "Project" then "Add Reference..." from the menu.) Now you'll need to find the folder where you extracted the iTextSharp library in step 2. In that location, find "itextsharp.dll" and select "OK". (Figure 4.2) | (Alternatively, you can also select "Project" then "Add Reference..." from the menu.) Now you'll need to find the folder where you extracted the iTextSharp library in step 2. In that location, find "itextsharp.dll" and select "OK". (Figure 4.2) | ||
− | + | ||
− | + | 5. Създаване на текстово поле | |
− | + | ||
− | + | 6. Добавяне бутон запис на pdf | |
− | + | ||
+ | 6.1. Създване на събитие при натискане на бутон | ||
+ | Create a System.IO.FileStream object: | ||
FileStream fs = new FileStream("Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None); | FileStream fs = new FileStream("Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None); | ||
− | + | ||
− | + | 6.2. Create a iTextSharp.text.Document object: | |
Document doc = new Document(); | Document doc = new Document(); | ||
− | + | ||
− | + | 6.3. Create a iTextSharp.text.pdf.PdfWriter object. It helps to write the Document to the Specified FileStream: | |
PdfWriter writer = PdfWriter.GetInstance(doc, fs); | PdfWriter writer = PdfWriter.GetInstance(doc, fs); | ||
− | + | ||
− | + | 6.4. Openning the Document: | |
doc.Open(); | doc.Open(); | ||
− | + | ||
− | + | 6.5. Adding a Paragraph by creating a iTextSharp.text.Paragraph object: | |
doc.Add(new Paragraph(richTextBox.Text1)); | doc.Add(new Paragraph(richTextBox.Text1)); | ||
− | + | ||
− | + | 6.6. Closing the Document: | |
doc.Close(); | doc.Close(); | ||
Revision as of 21:18, 7 April 2014
Contents
Подготовка
sudo apt-get update sudo apt-get install vim sudo apt-get install pdftk sudo apt-get install php5
Създаване на pdf
Зад.1.
vim zad1.pdf
Натискате "i" за влизате в текстов режим и копирате кода Листинг1. Натискате "Esc", ":", "w","q","Enter".
%PDF-1.0 File header
1 0 obj
<<
/Type /Pages
/Count 1
/Kids [2 0 R]
>>
endobj
2 0 obj
<<
/Type /Page
/MediaBox [0 0 612 792]
/Resources 3 0 R
/Parent 1 0 R
/Contents [4 0 R]
>>
endobj
3 0 obj
<<
/Font
<<
/F0
<<
/Type /Font
/BaseFont /Times-Italic
/Subtype /Type1
>>
>>
>>
endobj
4 0 obj
<< >>
stream
1. 0. 0. 1. 50. 700. cm
BT /F0 36. Tf (Hello, World!) Tj ET
endstream
endobj
5 0 obj
<<
/Type /Catalog
/Pages 1 0 R
>>
endobj
xref
0 6
trailer
<<
/Size 6
/Root 5 0 R
>>
startxref
0
%%EOF
Коригиране на pdf с pdftk
Изпълнете следната команди, за да се добави липсващата информация към pdf-a.
pdftk zad1.pdf output zad.pdf
Разгледайте резултата и вижте коментарите листинг 2.
vi zad.pdf evince zad.pdf
След коригиране на pdf-a.
%PDF-1.0 начало и версия
%âãÏÓ non printable caracters, за да
1 0 obj Обект 1, Съдържа Структурата на страниците
<<
/Kids [2 0 R]
/Count 1
/Type /Pages
>>
endobj
2 0 obj описание на страницата
<<
/Parent 1 0 R
/Resources 3 0 R допълнителни данни за възпроизвеждане на страницата
/MediaBox [0 0 612 792] Размер на страницата
/Contents [4 0 R] съдържание на страницата
/Type /Page
>>
endobj
3 0 obj Информация за шрифта
<<
/Font
<<
/F0 Име на шрифта
<<
/BaseFont /Times-Italic
/Subtype /Type1
/Type /Font
>>
>>
>>
endobj
endobj
4 0 obj Съдържание на страницата
<<
/Length 64 Размер на данните в stream
>>
stream
1. 0. 0. 1. 50. 700. cm
BT /F0 36. Tf (Hello, World!) Tj ET
endstream
endobj
5 0 obj Роот обект
<<
/Pages 1 0 R
/Type /Catalog
>>
endobj xref Местоположение на всечки обекти
0 6
0000000000 65535 f
0000000015 00000 n
0000000074 00000 n
0000000182 00000 n
0000000281 00000 n
0000000398 00000 n
trailer
<<
/Root 5 0 R
/Size 6
>>
startxref
448 Местоположение на препратките
%EOF
Обединяване на два pdf файла
Да се изтегли примерния файл zad2r.pdf. Да се запише в същата директория на получения в задача 1 zad.pdf. Да се изпълни командата:
pdftk zad.pdf zad2r.pdf cat output zad2c.pdf
Разгледайте получения файл и начертайте схема с връзките между блоковете.
vi zad2c.pdf evince zad2c.pdf
Генериране на PDF c PHP
Да се създаде директория php
mkdir /home/lab/php
Да се свали php скрипт с подръжка на UTF-8 за генериране на pdf. Файлът съдържа и набор от TrueType шрифтове.
Файлът да се разархивира в директория /home/lab/php
cd ~/php unzip tfpdf.zip
Да се изпълни примерният скрипт и да се разгледа резулатата.
cd ~/php php ex.php > myphp.pdf vi myphp.pdf evince muphp.pdf
Да се разкомпресира pdf файлът и да се разгледа резулатата.
pdftk myphp.pdf output de.pdf uncompress vi de.pdf evince de.pdf
Да се разгледа и модифицира кода на ex.php:
vi ex.php
Генериране на PDF с C#
http://techvalleyprojects.blogspot.com/2011/08/fill-pdf-forms-in-c-with-itextsharp.html
http://sourceforge.net/projects/itextsharp/
http://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in
Download the iTextSharp library Extract the iTextSharp library Start new C# Windows Forms project Add reference to the iTextSharp library
1. Download iTextSharp
Download the iTextSharp library at http://sourceforge.net/projects/itextsharp/
2. Extract the iTextSharp library
Extract the library to a new folder that you can find again. I extracted mine to my Visual Studio directory. For example, "\Visual Studio 2010\external libraries\iText lib"
3. Create a new C# Windows Forms project Start Visual Studio 2010. Select "New Project". Next, under C#, select "Windows Forms Application". Name the solution something like "FormFillerPDF" and select "OK"
4. Add a reference to the iTextSharp library
In your Solution Explorer, right click on "Reference". Left-click on "Add Reference..." (Figure 4.1) (Alternatively, you can also select "Project" then "Add Reference..." from the menu.) Now you'll need to find the folder where you extracted the iTextSharp library in step 2. In that location, find "itextsharp.dll" and select "OK". (Figure 4.2)
5. Създаване на текстово поле
6. Добавяне бутон запис на pdf
6.1. Създване на събитие при натискане на бутон Create a System.IO.FileStream object:
FileStream fs = new FileStream("Chapter1_Example1.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
6.2. Create a iTextSharp.text.Document object:
Document doc = new Document();
6.3. Create a iTextSharp.text.pdf.PdfWriter object. It helps to write the Document to the Specified FileStream:
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
6.4. Openning the Document:
doc.Open();
6.5. Adding a Paragraph by creating a iTextSharp.text.Paragraph object:
doc.Add(new Paragraph(richTextBox.Text1));
6.6. Closing the Document:
doc.Close();
Литература
- John Whitington, PDF Explained - The ISO Standard for Document Exchange, O'Reilly Media, December 2011
- Sid Steward, PDF Hacks, O'Reilly Media,August 2004; http://www.pdfhacks.com, http://etutorials.org/Linux+systems/pdf+hacks/PDF+Hacks/
- Document Management – Portable Document Format – Part 1: PDF 1.7, First Edition,Adobe 2008
- FPDF - удобен за генериране на pdf (v1.3) с PHP
- http://www.pdflib.com/ - подържат - C, C++,Java,Perl,PHP,Python,Tcl,Ruby