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

Google App Engine class on client side
How can I remove a sticky broadcast from memory?
How to access a property value of an object that is a Hashset when iterating in Struts2
Correct database design for JPA entity inheritance
Need help on java interfaces exercise [closed]
Interpreting Bytebuffer that contains different data types
playframework - package javax.persistence does not exist
Which Exception to be thrown?
onItemLongClick is undefined?
adding a double to a JTextArea?
Spring HttpMessageNotReadableException
How to parse a generic type through several levels of extends?
“. . . 30 more” in Eclipse LogCat. How to show those 30 more?
Cannot test my web service on Browser,
How to parse raw mime content in java?
Java generics inconsistent behavior?

Categories

HOME
multithreading
image
listview
reflection
relay
q
packages
dxl
retrofit
primary-key
maude-system
ef-migrations
pugjs
visual-composer
object-detection
intentfilter
facebook-instant-articles
sylius
dcevm
tibco-mdm
underflow
ejabberd-module
nat
preg-match-all
semantic-versioning
create-table
mozilla
language-concepts
fusionpbx
jmonkeyengine
leading-zero
sas-visual-analytics
firebase-admin
http-redirect
netcdf4
convertapi
executenonquery
network-flow
hibernate-tools
strptime
integrity
yii2-extension
directory-structure
boost-preprocessor
word-vba-mac
plottable.js
contact-list
markojs
python-stackless
ios4
system.management
pervasive-sql
reactive-banana
jms2
intellij-14
tmuxinator
sframe
android-listview
cakephp-3.1
php-ci
method-parameters
sankey-diagram
clicktag
jsonpickle
android-nested-fragment
websocket4net
elliptic-curve
quartz-graphics
ril
kyotocabinet
referrer
dmoz
enter
spring-portlet-mvc
mod-auth
coercion
django-tagging
yetanotherforum
disclosure
gamma
asp.net-profiles
zend-tool
brewmp
3gp

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