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.
Thu May 06, 2021 4:11 pm
Hi!
I´m building a function to recive base64 PDF, process and return base64 again:
This part of code is wirking
- Code: Select all
//Decode base64
byte[] decoded = java.util.Base64.getDecoder().decode(base64_in);
//Load on PdfDocument
pdf.loadFromBytes(decoded);
//Remove embedded javascript
pdf.removeDocumentJavaScript();
//Save to file to test, but I don't want to save on filesystem
pdf.saveToFile("output.pdf", FileFormat.PDF);
//Here I need to save on memory and encode to base64 again
How can I do this?
Regards.
-
riturra84
-
- Posts: 4
- Joined: Fri Apr 09, 2021 10:02 pm
Fri May 07, 2021 2:33 am
Hello,
Thanks for your inquiry.
Please refer to the modified code below.
- Code: Select all
//Decode base64
byte[] decoded = java.util.Base64.getDecoder().decode(base64_in);
//Load on PdfDocument
pdf.loadFromBytes(s);
//Remove embedded javascript
pdf.removeDocumentJavaScript();
//Save to file to test, but I don't want to save on filesystem
pdf.saveToFile("output.pdf", FileFormat.PDF);
//Here I need to save on memory and encode to base64 again
//Write the pdf to stream
ByteArrayOutputStream stream=new ByteArrayOutputStream();
pdf.saveToStream(stream);
//Convert the stream to byte array and encode
byte[] encoded=java.util.Base64.getEncoder().encode(stream.toByteArray());
//Close the stream
stream.close();
If you have any other questions, please feel free to contact us.
Sincerely,
Andy
E-iceblue support team
-
Andy.Zhou
-
- Posts: 483
- Joined: Mon Mar 29, 2021 3:03 am
Mon May 17, 2021 3:36 am
Hello,
Greetings from E-iceblue!
Has the issue been solved now? Could you please give us some feedback at your convenience?
Thank you in advance.
Sincerely,
Andy
E-iceblue support team
-
Andy.Zhou
-
- Posts: 483
- Joined: Mon Mar 29, 2021 3:03 am