Friday, 9 August 2013

insert a null space coding between two characters in a PDF document generated by PDFBox

insert a null space coding between two characters in a PDF document
generated by PDFBox

I have tired to insert an null space coding (an invisible ascii between
two characters) in a PDF document generated by PDFBox. My code serves to
create a PDF document with PDFBox containing the following string "La
Stéganographie dans PDF". i tried firstly to convert the string to hex:
String hex= "4C61205374E967616E6F677261706869652064616E7320504446f";
Then insert one from four invisible ascii codes between St. Notice: that i
want is to insert an invisible Ascii, and more particularity, a null space
coding such as 1C, 1D, 1E and 1F between St in order to obtain :
String hex_modified=
"4C6120531C74E967616E6F677261706869652064616E7320504446f";
Notice the 1C added after 53 and before 74
When i opened the file structure of the document, i got:
(La SFStéganographie dans PDF)Tj
Notice that FS = File Separator.
When i search the position of each character, i got:
String[31.680002,15.0 fs=12.0 xscale=12.0 height=9.0720005 space=3.3360004
width=8.004]S
String[39.684002,15.0 fs=12.0 xscale=12.0 height=9.096001 space=3.3360004
width=0.0]
String[39.684002,15.0 fs=12.0 xscale=12.0 height=9.0720005 space=3.3360004
width=3.3360023]t
So we can notice that the inserted null space coding "1C" between the two
characters "St" has a width=0.0.
My Problem: when i open the PDF Document, i get a space between the two
characters S and t. How to resolve this problem?
Let as consider the following code:
public class Test1 extends PDFTextStripper{
private static String v;
public Test1() throws IOException {
super.setSortByPosition(true);
}
private static Test1 tes;
private static final String src="...";
private static PDPageContentStream content;
private static PDType1Font font;
public static void CreatePdf(String src) throws IOException,
COSVisitorException{
PDRectangle rec= new PDRectangle(400,400);
PDDocument document= null;
document = new PDDocument();
PDPage page = new PDPage(rec);
document.addPage(page);
PDDocumentInformation info=document.getDocumentInformation();
PDStream stream= new PDStream(document);
stream.addCompression();
info.setAuthor("PdfBox");
info.setCreator("Pdf");
info.setSubject("Stéganographie");
info.setTitle("Stéganographie dans les documents PDF");
info.setKeywords("Stéganographie, pdf");
content= new PDPageContentStream(document, page, true, false );
font= PDType1Font.HELVETICA;
String hex = "4C6120531C74E967616E6F677261706869652064616E7320504446";
System.out.println(hex.length());
StringBuilder sb = new StringBuilder();
for (int count = 0; count < hex.length() - 1; count += 2)
{
String output = hex.substring(count, (count + 2));
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
}
String tt=sb.toString();
System.out.println("la valeur tt est: "+tt);
content.beginText();
content.setFont(font, 12);
// content.moveTextPositionByAmount(15, 385);
// content.appendRawCommands("3 Tr");
content.appendRawCommands("15 385 Td\n");
//content.drawString("La Stéganographie dans PDF");
content.appendRawCommands("("+tt+")"+"Tj\n");
content.endText();
content.close();
document.save("doc.pdf");
docum
ent.close();
}
Please i need your help,
Best regards,

No comments:

Post a Comment