开发者

JMS TextMessage itext PDF header signature not found

I have a listener that receives a JMS TextMessage that has pdf content in there.

I am doing getBytes("Cp037") since it is coming from mainframe

when i run the line "PdfReader reader = new PdfReader(bais)";

it crashes with PDF header signature not found.

It should be a valid pdf since another app is able to get the pdf.

What could be the problem? Thanks

import javax.jms.开发者_运维知识库Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

            TextMessage txtMessage = (TextMessage)message;
                ByteArrayInputStream bais = new ByteArrayInputStream(txtMessage.getText().getBytes("Cp037"));

                PdfReader reader = new PdfReader(bais);


I had the same error and I just changed my PdfReader from reading InputStreams to read Strings. So, it works perfectly with:

public static void doMerge(List<String> list, OutputStream outputStream)
        throws DocumentException, IOException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, outputStream);
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    for (String in : list) {
        PdfReader reader = new PdfReader(in);
        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            document.newPage();
            // import the page from source pdf
            PdfImportedPage page = writer.getImportedPage(reader, i);
            // add the page to the destination pdf
            cb.addTemplate(page, 0, 0);
        }
    }

    outputStream.flush();
    document.close();
    outputStream.close();
}

*Originally I took this code from http://www.mindfiresolutions.com/Java-Merging-multiple-PDFs-into-a-single-PDF-using-iText-671.php


Why is it a TextMessage instead of a BytesMessage?

As Mark wrote, a PDF contains binary data. So it looks like the sender side of the JMS communication has to be changed too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜