View Full Version : Challenge PDF files and webMethods
Wayne S Olsen
04-05-2003, 22:17
Hi.
I have been hearing from our Enterprise Architects and they would like to know if it is possible to pass PDF files around in the webMethods platform. Apparently an application will be generating a PDF file and other applications may want to use this PDF file (to display on a web page). So assuming the PDF is in a file, or stored in a db table, how would we use webMethods to retrieve it and return it (in a message) to a client ?
Can we return pdf's in documents or xml ? Do we need to use file transfer ? Do we set a specific mime type ? (eg. application/pdf) ???
Any thought ?
Regards
Wayne
Kevin Liang
04-10-2003, 10:36
We've done a similar project although we use Intergration Server, not Enterprise Server. We store the pdf file in file system. And pass it to multiple destinations through ftp or http depending on the requirement of the destinations. For http, you probably have to specify the content type as "application/pdf".
IS provides numerous build service such as getFiles, ftp and http to assist those jobs. If you store pdf in the database, there are build in db services to get the file. So you have many ways to handle it.
Invoke pug.file:getFile loading as Bytes, So pdf files can be processed in webMethods .
wleishman
04-10-2003, 22:01
Thanks for the feedback.
I understand the idea with IS. Grab the pdf as bytes, and in the response set the content type to "application/pdf".
Question: What if I want to publish the pdf (or Word doc) so that multiple subscribers can use it ? What field type should I use ? byte array ? ( byte [] )
Regards,
Wayne
byte[] is the right type to use.
Another approach would be to place the file of interest in an accessible location and publish a notification doc that says "there's a new doc available for download named xyz" then subscribers could use facilities more suitable for large files.
Wayne S Olsen
04-10-2003, 23:00
Thanks much Rob.
Wayne
Hey Guys,
I have the similar scenario. I have PDF file stored in oracle database and it is stoed as Blob SQL data type in the table. I used utility services and JDBC adapter to select the data from the table. How to handle this byte[] data and write to a file again ?
i used services like bytesToString and writeStringToFile.
but it writes some junk data in the file. I am not sure how to handle this scenario. if any suggestions ?? help ??
regards,
nilesh
Hello,
You should not change the byte[] to a string. You should write the byte array directly to the file. So:
IDataCursor idc = pipeline.getCursor();
idc.first("pdfbytes");
byte[] pdfbytes = (byte[]) idc.getValue();
try{
java.io.File file = new java.io.File("file.pdf");
java.io.FileOutputStream filestream = new java.io.FileOutputStream(file);
filestream.write(pdfbytes);
}catch(Exception e){}
idc.destroy();
You should customize this to your needs.
Good day.
Yemi Bedu
Hello:
We generated a pdf document but is not possible to open directly, we just can open a copy of this document.
Itīs a simple document generated with the services:
1.-pdf.generate:beginPDF
2.-pdf.generate:addParagraph
3.-pdf.generate:addDocumentElement
4.-pdf.generate:endPDF
5.-pdf.file:convertToFile
if any suggestions ?? help ??
thanks,
ten
If you're dynamically generating the PDF when a service is invoked by a user or other process, you don't necessarily need to write the file to the IS local disk first. If the PDF will be small enough to fit completely into memory, you can set the http response so that you can return the bytes and the right content-type so the browser will open Reader properly.
To do this you'll need to create a Java service (pub.flow:setResponse accepts a string and for this we need to pass a byte array). The service could look like this:
setResponseBytes(IData pipeline)
IDataCursor idc = pipeline.getCursor();
byte[] bytes = (byte [])IDataUtil.get(idc, "bytes");
String encoding = IDataUtil.getString(idc, "encoding");
String contentType = IDataUtil.getString(idc, "contentType");
String remoteFilename = IDataUtil.getString(idc, "remoteFilename");
idc.destroy();
com.wm.net.HttpHeader httpheader = Service.getHttpResponseHeader();
if(httpheader != null)
{
if(contentType!=null && !contentType.equals(""))
httpheader.addField("content-type", contentType);
if(encoding!=null && !encoding.equals(""))
httpheader.addField("encoding",encoding);
if(remoteFilename!=null && !remoteFilename.equals(""))
httpheader.addField("content-disposition", "inline;filename= \""+ remoteFilename+ "\"");
}
Service.setResponse(bytes);
Call pdf.util:toByteArray instead of convertToFile. Pass the resulting bytes to the setResponseBytes and presto--your PDF will be returned to the caller without writing it to disk first.
HTH
Oops. Forgot to mention that the content-type should be application/pdf. (Wayne L. had mentioned that earlier but thought I'd reiterate just in case.)
Hi,
I need to create a textbox in the Pdf.In this textbox i have to display a default value.i have created the pdf file using the Pdf.Generate sevices.
Please give some idea to generate a textbox in the PDF.
Thanks in advance.
Hi
I see some posts in this thread about pdf services. For instance: pdf.util:toByteArray
What does this refer to? Are these wM services?
Thanks
It's a package posted in the shareware section.
http://www.wmusers.com/software/uploads/2314PDFCreator.zip
vivekrim
10-13-2008, 03:28
Hi All,
I tried the above code to write pdf file
IDataCursor idc = pipeline.getCursor();
idc.first("pdfbytes");
byte[] pdfbytes = (byte[]) idc.getValue();
try{
java.io.File file = new java.io.File("file.pdf");
java.io.FileOutputStream filestream = new java.io.FileOutputStream(file);
filestream.write(pdfbytes);
}catch(Exception e){}
idc.destroy();
But when I am opening this pdf, its coming as blank,where as size of file is correct.