This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Palak Agarwal

Greenhorn
+ Follow
since Nov 02, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Palak Agarwal

hi all,

I am trying to merge two pdfs using java code. the following code merges the required pdf but the second pdf gets zoomed.I am using iText java library for this code.
Does anybody have idea, for this behaviour of code.
Kindly help me with this issue.

public static void concatPDFs(List<InputStream> streamOfPDFFiles,

OutputStream outputStream, boolean paginate) {

Document document = new Document(PageSize.A2);

try {
List<InputStream> pdfs = streamOfPDFFiles;
List<PdfReader> readers = new ArrayList<PdfReader>();
int totalPages = 0;
Iterator<InputStream> iteratorPDFs = pdfs.iterator();

// Create Readers for the pdfs.
while (iteratorPDFs.hasNext()) {
InputStream pdf = iteratorPDFs.next();
PdfReader pdfReader = new PdfReader(pdf);
readers.add(pdfReader);
totalPages += pdfReader.getNumberOfPages();
}
// Create a writer for the outputstream
PdfWriter writer = PdfWriter.getInstance(document, outputStream);

document.open();
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
PdfContentByte cb = writer.getDirectContent(); // Holds the PDF
// data

PdfImportedPage page;
int currentPageNumber = 0;
int pageOfCurrentReaderPDF = 0;
Iterator<PdfReader> iteratorPDFReader = readers.iterator();

// Loop through the PDF files and add to the output.
while (iteratorPDFReader.hasNext()) {
PdfReader pdfReader = iteratorPDFReader.next();

// Create a new page in the target for each source page.
while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) {
//document.setPageSize(pdfReader.getPageSizeWithRotation(pageOfCurrentReaderPDF));
document.newPage();
pageOfCurrentReaderPDF++;
currentPageNumber++;
page = writer.getImportedPage(pdfReader,
pageOfCurrentReaderPDF);

cb.addTemplate(page, 0, 0);

// Code for pagination.
if (paginate) {
//cb.rectangle (document.left (), document.bottom (), document.right ()-document.left (),
//document.top ()-document.bottom ());
cb.beginText();
cb.setFontAndSize(bf, 10);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, ""
+ currentPageNumber + " of " + totalPages, 520,
5, 0);
cb.endText();
}
}
pageOfCurrentReaderPDF = 0;
}
outputStream.flush();
document.close();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (document.isOpen())
document.close();
try {
if (outputStream != null)
outputStream.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}


with regards
palak
10 years ago
hi all,

I have written the following code in java:




When i run this code couple of times i got two color codes which are entirely different from each other but their color are exactly same. Following are the two produced codes :
#A11C10 and #aa020a

Please if any one has idea how to produce codes where color as well as code both are unique, then reply.
I have to generate around 300 unique codes . Please help.

Thanks
Palak
10 years ago
But i want to apply this logic in java.
My requirement is to generate the dark color codes randomly and i am not able to get the exact logic, so please help.
10 years ago
hi,

i got this piece of code to generate random color codes



10 years ago
hi ,

no i don't please help me with this.

Thanks
Palak
10 years ago
Hi all,

What i want, is to write a code that will be capable of generating random html color codes, is there a way to do so?

Thanks
Palak
10 years ago
hi karthik,

Thanks a lot for your help and guidance.
With the help of servlet we are able to convert word files from salesforce
to pdf now.

Thanks
Palak
10 years ago
hi all,

I am trying to call salesforce platform through java servlet using SOAP connection. To do so i have imported WSC-20 jar etc. and set the class path as follows:


set classpath=.;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-cli-1.2.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\commons-io-1.4.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jodconverter-2.2.2.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jodconverter-cli-2.2.2.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\juh-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\jurt-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\ridl-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\slf4j-api-1.5.6.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\slf4j-jdk14-1.5.6.jar;C:\program Files\Apache Software Foundation\Tomcat 7.0\lib\unoil-3.0.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\xstream-1.3.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\enterprise.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\xstream-1.3.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\xstream-1.3.1.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\wsc-20.jar;C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\itext-2.1.7.jar;

But the servlet is throwing an exception

java.lang.NoClassDefFoundError: com/sforce/ws/ConnectionException java.lang.Class.getDeclaredConstructors0(Native Method) java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) java.lang.Class.getConstructor0(Class.java:2699) java.lang.Class.newInstance0(Class.java:326) java.lang.Class.newInstance(Class.java:308) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:197) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1824) java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)


Does anyone have idea why I am facing this kind of exception? Please reply

Thanks
Palak
10 years ago
hi all,
I am facing the similar kind of issue. Below are the two different packages which I am trying to import. Both of them contains the class with same name.
it does not allow the code to get compiled and says "already defined in single-type import".

import com.lowagie.text.Document;
import com.sforce.soap.enterprise.sobject.Document;

How to resolve this issue ?

Thanks
Palak
10 years ago
hi karthik,

"Deploy the conversion code as a servlet in Tomcat"

Please can you give the steps to deploy conversion code as servlet and how will I publish the converted file in some directory
of Tomcat.

Thanks a lot you have been really helpful to me.
With Regards,
Palak
10 years ago
Hi karthik,

Actually, I am salesforce(cloud computing) developer and salesforce does not allow conversion of word to pdf. For this reason I have to use EC2. My aim is to send word file to EC2 from salesforce which will be converted into a pdf and send it back to salesforce.

Thanks,
Palak
10 years ago
hi karthik ,

Thanks for your reply.
This java code needs to be invoked on EC2 from some other platform so do we need to have EC2 credentials to do so or please tell me
if there is any other alternative to run this java code hosted on EC2 from other platform.

thanks
Palak
10 years ago
karthik while i am uploading the files, the system runs terribly slow . I am using RDC. so is it due to the internet speed or for any other reason?
thanks a lot for your help....
10 years ago