Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XmpHelper.java #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,62 @@ final class XmpHelper {
" <stEvt:when>" + TAG_DATE + "</stEvt:when>\n" + //$NON-NLS-1$ //$NON-NLS-2$
"</rdf:li>"; //$NON-NLS-1$

private static String getOriginalCreationDateAsW3C(final byte[] inPdf) {
final String pdfStr = new String(inPdf);

int pos = pdfStr.indexOf("/CreationDate"); //$NON-NLS-1$
if (pos == -1) {
return null;
}
pos += "/CreationDate".length(); //$NON-NLS-1$

pos = pdfStr.indexOf("(", pos); //$NON-NLS-1$
if (pos == -1) {
return null;
}
pos += "(".length(); //$NON-NLS-1$
final int pos2 = pdfStr.indexOf(")", pos); //$NON-NLS-1$
if (pos2 == -1) {
return null;
}
final String pdfDateStr = pdfStr.substring(pos, pos2).trim();
return PdfDate.getW3CDate(
pdfDateStr
);
}

/**
* B&uacute;squeda de subcadenas en arrays de bytes. Similar al m&eacute;todo de Google Guava en la clase Bytes.
*
* @param inPdf
* @return
*/
public static int indexOf(byte[] array, byte[] target, int start) {
if (target.length == 0) {
return 0;
}

outer:
for (int i = start; i < array.length - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}

/**
* Obtener la fecha de creaci&oactue;n del PDF.
*
* @param inPdf
* @return
*/
public static String getOriginalCreationDateAsW3C(final byte[] inPdf) {
byte[] aCreation = "/CreationDate".getBytes();
byte[] aOpen = "(".getBytes();
byte[] aClose = ")".getBytes();

int pos = indexOf(inPdf, aCreation, 0);
if (pos == -1) {
return null;
}
pos += aCreation.length;

pos = indexOf(inPdf, aOpen, pos);
if (pos == -1) {
return null;
}
pos += aOpen.length;

final int pos2 = indexOf(inPdf, aClose, pos);
if (pos2 == -1) {
return null;
}

System.out.println(pos + ", " + pos2);
final String pdfDateStr = new String(Arrays.copyOfRange(inPdf, pos, pos2)).trim();
return PdfDate.getW3CDate(pdfDateStr);
}

/** A&ntilde;ade una entrada de firma al hist&oacute;rico XMP de un PDF.
* Un ejemplo de hist&oacute;rico XML con entrada de firma podr&iacute;a ser:
* <pre>
Expand Down