Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Oct 21, 2024 8:39 am

I have implemented an API that is in a webservice deployed on a tomcat server. Here is sample of convert. the webservice is also managing signature:

Code: Select all
    @Override
    public PdfDto convert(PdfDto pdfDto) throws IOException {
        DataDto dataDto;
        try (ByteArrayOutputStream pdfConvertedStream = convertStream(pdfDto)) {
            String pdf64Converted = new Base64().encodeAsString(pdfConvertedStream.toByteArray());
            dataDto = DataDto.builder()
                    .fileName(pdfDto.getData().getMultipart().getOriginalFilename())
                    .pdf(pdf64Converted)
                    .converted(Boolean.TRUE)
                    .build();
        } catch (UnsupportedFormatException | IOException e) {
           // exception thrown
        }
        return PdfDto.builder()
                .headerData(modelMapper.map(logDto, HeaderDataDto.class))
                .data(dataDto)
                .build();
    }


My convert stream is the following:


Code: Select all
 private ByteArrayOutputStream convertStream(PdfDto pdfDto) throws IOException {
        ByteArrayOutputStream pdfConvertedStream = new ByteArrayOutputStream();
        PdfStandardsConverter converter = new PdfStandardsConverter(
                pdfDto.getData().getMultipart().getInputStream());
        DataDto dataDto = pdfDto.getData();
        PdfFormatEnum pdfFormatEnum = Arrays.stream(PdfFormatEnum.values())
                .filter(pdfFormat -> pdfFormat.name().equalsIgnoreCase(dataDto.getFormat()))
                .findAny()
                .orElse(PdfFormatEnum.PDFA3A);
        String pdfFormat = pdfFormatEnum.getFormat().toLowerCase();
        switch (pdfFormat) {
            case "pdfa1a" -> converter.toPdfA1A(pdfConvertedStream);
            case "pdfa1b" -> converter.toPdfA1B(pdfConvertedStream);
            case "pdfa2a" -> converter.toPdfA2A(pdfConvertedStream);
            case "pdfa2b" -> converter.toPdfA2B(pdfConvertedStream);
            case "pdfa3a" -> converter.toPdfA3A(pdfConvertedStream);
            // case "pdfa3b" -> converter.toPdfA3B(pdfConvertedStream);
            default -> converter.toPdfA3B(pdfConvertedStream);
        }
        return pdfConvertedStream;
    }


for signature:


Code: Select all
private ByteArrayOutputStream signedStream(PdfDto pdfDto)
            throws IOException {
        if ((pdfDto.getData().getSignatureName() == null) || pdfDto.getData().getSignatureName().isEmpty()) {
            pdfDto.getData().setSignatureName("Signature");
        }


        return signedStream(pdfDto, pdfDto.getData().getMultipart().getInputStream());
    }

    private ByteArrayOutputStream signedStream(
            PdfDto pdfDto,
            InputStream signatureStream) throws IOException {

        PdfDocument doc = new PdfDocument(signatureStream);
         PdfCertificate cert = new PdfCertificate(IOUtils.toByteArray(FileUtils.base64DecodeFromString(
                pdfDto.getData().getCertificate())), pdfDto.getData().getPassword());
        PdfSignature pdfSign = new PdfSignature(
                doc,
                doc.getPages().get(doc.getPages().getCount() - 1),
                cert,
                pdfDto.getData().getSignatureName());
        pdfSign.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
        pdfSign.setDocumentPermissions(PdfCertificationFlags.Allow_Form_Fill);
        pdfSign.setLocationInfo(pdfDto.getData().getLocation());
        pdfSign.setReason(pdfDto.getData().getReason());
        ByteArrayOutputStream signedPdf = new ByteArrayOutputStream();
        doc.saveToStream(signedPdf);
        doc.close();
        return signedPdf;
    }



My issue is that once deployed, client is calling webservice and signature, conversion of both operations are working fine.
We simply noticed that we have files stored in a temp folder and that they're not removed after operation. In the end, we can have 5000 files around 3 Mo and we have limitations on space disk?

dreamweaver
 
Posts: 4
Joined: Tue Feb 22, 2022 5:04 pm

Mon Oct 21, 2024 10:01 am

Hello,

Thanks for your inquiry. I created a springboot project locally for testing and simulated the operations of converting formats and setting signatures based on your code. I also simulated accessing the corresponding interface 3000 times, but the situation you reported did not occur. To help us investigate your issue in more detail, please provide us with a demo that can reproduce your problem and tell us your system operating environment(E.g. Win10, 64 bit). You can upload here or send it to us via email( Amin.gan@e-iceblue.com ). Thank you in advance.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF