java


How to write String in PDF file using Java


I had written below code to write a String in PDF file. But I am getting the corrupted PDF error. Attached the image. Please help me to understand where I did wrong. I don't want to use any jar files.
import java.util.Base64;
import java.io.UnsupportedEncodingException;
import java.io.*;
public class testPdf{
public static void main(String args[]){
try {
String value="creating PDF";
String base64encodedString = Base64.getEncoder().encodeToString(value.getBytes("utf-8"));
StringBuffer strBuilder = new StringBuffer();
strBuilder.append(base64encodedString);
byte[] byteArray = base64encodedString.getBytes();
FileOutputStream out = new FileOutputStream("temp.pdf");
out.write(byteArray);
out.flush();
out.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Related Links

Override Cordova Log
Opengl es 2.0 draw bitmap overlay on video
Trying to get songlist in a fragment gives nullpointerexception
Swagger 2.0 Implementation in spring MVC rest api with spring boot
What is the conflict that causes lang.ClassCastException on WebLogic?
Terminology: What do you call a function that does not change object state?
Circular reference in Hibernate
How to call specific method on every 10 second
Downloading and installing an APK using volley
Java reflection: getting list of declared variables within same class? [duplicate]
Formatting XMLGregorianCalendar
Set.equals doesn't work : only check the first hashSet
Hibernate: Exception when 10 or more users insert a record concurrently
Gradle seems to ignore project dependencies
spring.cloud.inetutils.ignoredInterfaces ignored in profiles
Grails not resolving spring security Ui

Categories

HOME
ionic-framework
vbscript
listview
amazon-ec2
omnet++
spagobi
sql-server-2016
flyway4
azure-storage-tables
synchronization
amazon-cloudformation
iggrid
izpack
row
mapserver
google-cloud-ml
jplayer
alignment
dtrace
try-catch
after-effects
oracle-coherence
flux
scichart
web-sql
mustache.php
restful-authentication
numerical-methods
semantic-analysis
traffic
replaceall
windows-dev-center
xmlreader
nssegmentedcontrol
plsql-psp
dosbox
android-browser
service-discovery
mapzen
fedex
estimote
eclipse-gef
thin
flickr-api
pubmed
return-value
aurelia-validation
diagnostics
knockout-components
kbuild
memory-alignment
crosswalk-runtime
yt-project
abcpdf9
color-picker
instant
removechild
home-directory
url-masking
angstrom-linux
revolution-r
xna-4.0
splash
nsight
kineticjs
system.reflection
c3
terminfo
elliptic-curve
fluentautomation
reactfx
mysql-error-1062
undefined-reference
ril
eclipse-memory-analyzer
dataadapter
qt-faststart
eventual-consistency
ocunit
browser-detection
ocx
dotnethighcharts
boost-filesystem
pydot
f#-powerpack
table-footer
mozilla-prism
fixed-width
meego
avatar
multiple-languages
commodore
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App