Почему я не могу отправить pdf с майкой в ​​клиент браузера? - PullRequest
0 голосов
/ 09 июня 2019

У меня проблема: я хочу отредактировать pdf в веб-сервисе и отправить отредактированный pdf клиенту через джерси.Проблема в том, что если я вызываю URL в браузере, он говорит, что произошла ошибка при загрузке PDF.

Я уже пытался установить тип ответа на что-то другое, чем PDF, и я также попробовал другойpdf из интернета.

@Path("/certificate")
public class CertificateService{
    @GET
    @Path("{language}/{name}")
    @Produces("application/pdf")
    public Response createPDF(@PathParam("language") String language,@PathParam("name") String name) throws IOException {


        PDDocument document = null;
        try {
            // Load the document and get the AcroForm

            DateFormat formatter;
            URL url = new URL("http://app-learning.com/simplestock/assets/Zertifikat-de.pdf");
                    BufferedInputStream file = new BufferedInputStream(url.openStream());
                    document = document.load(file);

                formatter = new SimpleDateFormat("MM/dd/yyyy");


            PDDocumentCatalog docCatalog = document.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();


            // Fill the text field
            PDTextField field1 = (PDTextField) acroForm.getField("Text1");
            field1.setValue(name);
            // Optional: don't allow this field to be edited
            field1.setReadOnly(true);

            Date c = Calendar.getInstance().getTime();


            String today = formatter.format(c);

            PDTextField field2 = (PDTextField) acroForm.getField("Text2");
            field2.setValue(today);
            // Optional: don't allow this field to be edited
            field2.setReadOnly(true);






        } catch (IOException e) {

        }



      final File file = File.createTempFile("certi", ".pdf");
      document.save(file);
      document.close();



        return Response.ok(file).header("Content-Disposition",  "filename=restfile.pdf").type("application/pdf").build();


    }
...