Skip to content

Commit

Permalink
correcting 4 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Jun 11, 2024
1 parent 175871d commit ab079c9
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,20 @@ public ZUGFeRDImporter(InputStream pdfStream) {
*/
private void extractLowLevel(InputStream inStream) throws IOException {
BufferedInputStream pdfStream = new BufferedInputStream(inStream);
byte[] pad = new byte[4];
pdfStream.mark(0);
pdfStream.read(pad);
pdfStream.reset();
byte[] theBytes = IOUtils.toByteArray(inStream);

byte[] pdfSignature = {'%', 'P', 'D', 'F'};
if (Arrays.equals(pad, pdfSignature)) { // we have a pdf

byte[] copiedArray = new byte[4];

System.arraycopy(theBytes, 0, copiedArray, 0, 4);
if (Arrays.equals(copiedArray, pdfSignature)) { // we have a pdf


try (PDDocument doc = Loader.loadPDF(IOUtils.toByteArray(inStream))) {
// PDDocumentInformation info = doc.getDocumentInformation();
final PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
//start
try (PDDocument doc = Loader.loadPDF(theBytes)) {
// PDDocumentInformation info = doc.getDocumentInformation();
final PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
//start

if (doc.getDocumentCatalog() == null || doc.getDocumentCatalog().getMetadata() == null) {
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.INFO, "no-xmlpart");
Expand Down

0 comments on commit ab079c9

Please sign in to comment.