Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lab4
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ali Shakoori
lab4
Commits
285ac83b
Commit
285ac83b
authored
6 years ago
by
Ali Shakoori
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
second commit of lab 4 (pdf sout and pdf modified)
parent
ff92a1a6
master
No related merge requests found
Pipeline
#312
failed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
2 deletions
+69
-2
Main.java
src/Main.java
+17
-2
outputpdf.java
src/outputpdf.java
+52
-0
No files found.
src/Main.java
View file @
285ac83b
import
com.itextpdf.text.pdf.PdfReader
;
import
com.itextpdf.text.Document
;
import
com.itextpdf.text.DocumentException
;
import
com.itextpdf.text.PageSize
;
import
com.itextpdf.text.Paragraph
;
import
com.itextpdf.text.pdf.*
;
import
com.itextpdf.text.pdf.parser.PdfTextExtractor
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
try
{
PdfReader
pdfReader
=
new
PdfReader
(
"test.pdf"
);
System
.
out
.
println
(
pdfReader
.
getNumberOfPages
());
}
catch
(
Exception
e
){
for
(
int
i
=
1
;
i
<=
pdfReader
.
getNumberOfPages
();
i
++){
String
pageContent
=
PdfTextExtractor
.
getTextFromPage
(
pdfReader
,
i
);
System
.
out
.
println
(
pageContent
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
}
This diff is collapsed.
Click to expand it.
src/outputpdf.java
0 → 100644
View file @
285ac83b
import
com.itextpdf.text.pdf.BaseFont
;
import
com.itextpdf.text.pdf.PdfContentByte
;
import
com.itextpdf.text.pdf.PdfReader
;
import
com.itextpdf.text.pdf.PdfStamper
;
import
java.io.FileOutputStream
;
public
class
outputpdf
{
public
static
void
main
(
String
args
[]){
try
{
//Create PdfReader instance.
PdfReader
pdfReader
=
new
PdfReader
(
"test.pdf"
);
//Create PdfStamper instance.
PdfStamper
pdfStamper
=
new
PdfStamper
(
pdfReader
,
new
FileOutputStream
(
"D:\\ModifiedTestFile.pdf"
));
//Create BaseFont instance.
BaseFont
baseFont
=
BaseFont
.
createFont
(
BaseFont
.
TIMES_ROMAN
,
BaseFont
.
CP1252
,
BaseFont
.
NOT_EMBEDDED
);
//Get the number of pages in pdf.
int
pages
=
pdfReader
.
getNumberOfPages
();
//Iterate the pdf through pages.
for
(
int
i
=
1
;
i
<=
pages
;
i
++)
{
//Contain the pdf data.
PdfContentByte
pageContentByte
=
pdfStamper
.
getOverContent
(
i
);
pageContentByte
.
beginText
();
//Set text font and size.
pageContentByte
.
setFontAndSize
(
baseFont
,
14
);
pageContentByte
.
setTextMatrix
(
50
,
740
);
//Write text
pageContentByte
.
showText
(
"javawithease.com"
);
pageContentByte
.
endText
();
}
//Close the pdfStamper.
pdfStamper
.
close
();
System
.
out
.
println
(
"PDF modified successfully."
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment