Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

submit a PDF as a PDF to a servlet, and how to get my PDF from servlet

Avatar

Former Community Member
Hi all as the title above,



i have a button typeformat as PDF and sent to a URL( which is my servlet )

after this step how to get the PDF from my servlet.



the PDF has sent to my servlet and stop, so is there any way to get the PDF i sent ?



can someone help me?



thanks
11 Replies

Avatar

Level 10
You can use the following code:



byte[] content = getRequestBufferAsBytes(request);

...then do whatever you want



public static byte[] getRequestBufferAsBytes(HttpServletRequest request) throws IOException, ServletException

{

//

// get the RequestBuffer

//

ServletInputStream oInput = request.getInputStream();

long nContentLength = request.getContentLength();

String contentType = request.getContentType();



if (nContentLength <= 0)

return null;



byte[] cContent = new byte[(int)nContentLength];

//

// read the content in 512 bytes chunks

// a single read does not get all the characters

//

int nRead = 0;

int nToRead = (int)nContentLength;

int nBlkSize = 512;

byte[] cTemp = new byte[512];

do {

int n = 0;

int i = 0;

if (nToRead - nRead < 512)

nBlkSize = nToRead - nRead;



n = oInput.read( cTemp,0,nBlkSize);

for (i = 0; i < n; i++)

cContent[i+nRead] = cTemp[i];

nRead += i;

} while (nRead < nToRead);

//cContent[nRead] = (byte)'\0';

Long nBytesRead = new Long( nRead );





return cContent;

}



Jasmin

Avatar

Level 7
Just a note: do you realise that the free Adobe Reader can't by

default submit in PDF format, users may need to buy Acrobat?



Aandi Inston

Avatar

Former Community Member
Aandi, this is false. From WITHIN THE BROWSER Reader CAN do an HTTP post of the PDF. It's only outside the browser that you will either need Acrobat or a Reader Extended PDF to submit the PDF.

Avatar

Level 7
Is that right? I hadn't heard about that. When did it come in?



Aandi Inston

Avatar

Former Community Member
Note that the "cContent" returned in Jasmin's code above (byte[]) can be passed into a LiveCycle process variable declared as "document".



-Joel

Avatar

Former Community Member
If you are calling a LiveCycle process, there is no need for the all code shown above, you can simply use the following command...



Document document = new Document(request.getInputStream());



Where Document is a com.adobe.idp.Document object.



Gareth

Avatar

Former Community Member
Hello

I have a similar requirement and appreciate if any of you could give me a possible solution. I have a PDF form which I would like to post as a PDF document itself to a Servlet on Submit. The servlet has java mail program which would email this PDF document to a specified email address.



I tried setting the Submit As property to PDF in the button properties and the URL to my servlet. However, for testing purposes, when I have written this code request.getQueryString(); to see what the servlet is receiving, it prints null and am not sure how to get this filled out PDF document emailed on Submit.



Appreciate your response.

Avatar

Level 10
What if you try to get the length of the Document variable. Is it null?



Document document = new Document(request.getInputStream());

long size = document.length();



Jasmin

Avatar

Former Community Member
Hello Jasmin

Thanks for your response. I tried using the code in my servlet. But, I am not able to create the document object.I imported the package java.swing.text.Document but not able to instantiate the Document object. so, I changed it to



DefaultDocument document = new DefaultDocument();

DocumentType size = document.getDoctype();

System.out.println(size);



which still prints null. Note: The submit as property in the button object is set to "PDF". I changed it to URL encoded HTTP post and this still prints null. Not sure, what is going on. Appreciate any help.

Avatar

Level 10
The Document object is an Adobe data type (com.adobe.idp.Document).



It's located in the adobe-livecycle-client.jar under C:\Adobe\LiveCycle8.2\LiveCycle_ES_SDK\client-libs\common



Jasmin

Avatar

Former Community Member
For information about the com.adobe.idp.Document, read this topic -- "Passing data to LiveCycle ES services using the Java API" located at:



http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000269.html



For more information about using the LiveCycle ES Java APIs, see this URL -- "Invoking LiveCycle ES Using the Java API" at



http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000263.html