Question

1
Replies
1682
Views
chars1 Member since 2015 46 posts
PEGA
Posted: 4 years ago
Last activity: 4 years 8 months ago
Closed

Can we display inline bytes from pdf/images in Section

Hi all,

  1. How do I display attachment on the Section e.g. via Content-Disposition inline.

   The code below is a simple test to read PDF bytes (the bytes could be read from URL etc).  How can we do this in Pega?

package sc.test;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.net.MalformedURLException;

import java.net.URL;

import javax.servlet.ServletException;

import javax.servlet.ServletOutputStream;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* Servlet implementation class MyServlet2_1

*/

@WebServlet("/MyServlet2_1")

public class MyServlet2_1 extends HttpServlet {

  private static final long serialVersionUID = 1L;

  /**

  * @see HttpServlet#HttpServlet()

  */

  public MyServlet2_1() {

  super();

  // TODO Auto-generated constructor stub

  }

  /**

  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse

  *      response)

  */

  protected void doGet(HttpServletRequest req,

  HttpServletResponse res) throws ServletException, IOException {

  // TODO Auto-generated method stub

  doPost(req,res);

  }

  /**

  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse

  *      response)

  */

  protected void doPost(HttpServletRequest req,

  HttpServletResponse res) throws ServletException, IOException {

  ServletOutputStream out = res.getOutputStream();

  res.setContentType("application/pdf"); // MIME type for pdf doc

  res.setHeader("Content-disposition", "inline; filename="

  + "Example.pdf");

  BufferedOutputStream bos = null;

  try {

  bos = new BufferedOutputStream(out);

  byte[] buff = getByte();

  int bytesRead;

  bos.write(buff, 0, buff.length);

  } catch (final MalformedURLException e) {

  System.out.println("MalformedURLException.");

  throw e;

  } catch (final IOException e) {

  System.out.println("IOException.");

  throw e;

  } finally {

  if (bos != null)

  bos.close();

  }

  }

  public byte[] getByte() {

  FileInputStream fileInputStream = null;

  File file = new File("C:\\temp2\\a.pdf");

  byte[] bFile = new byte[(int) file.length()];

  try {

  // convert file into array of bytes

  fileInputStream = new FileInputStream(file);

  fileInputStream.read(bFile);

  fileInputStream.close();

  System.out.println("Done");

  } catch (Exception e) {

  e.printStackTrace();

  }

  return bFile;

  }

Inline contents displayed on Browser.png

2. How do I use PM4ML to create a PDF and so I can get the bytes used for the above question.

3. Is ITEXT PDF generation supported, can we use itext in Java activity or rules?

Regards

Seri

Low-Code App Development System Administration
Moderation Team has archived post
Share this page LinkedIn