First public commit
This commit is contained in:
7
tests/samples/descriptions.txt
Normal file
7
tests/samples/descriptions.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
== Zip files ==
|
||||
|
||||
test1.zip: deux fichiers et commentaire global.
|
||||
|
||||
== Pdf files ==
|
||||
|
||||
test1.pdf: fichier des impots.
|
||||
BIN
tests/samples/test1.pdf
Normal file
BIN
tests/samples/test1.pdf
Normal file
Binary file not shown.
BIN
tests/samples/test1.zip
Normal file
BIN
tests/samples/test1.zip
Normal file
Binary file not shown.
BIN
tests/samples/test1_normalized.pdf
Normal file
BIN
tests/samples/test1_normalized.pdf
Normal file
Binary file not shown.
21
tests/test_pdf_add_data.py
Executable file
21
tests/test_pdf_add_data.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
|
||||
import logging
|
||||
from PdfFileTransformer import Pdf
|
||||
|
||||
|
||||
input_file = "./samples/test1.pdf"
|
||||
output_file = "./samples/test1_out.pdf"
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
p = Pdf(input_file)
|
||||
p.insert_new_obj_stream_at_start(b'A' * 140)
|
||||
p.insert_new_obj_stream_at_end(b'B' * 120)
|
||||
f = open(output_file, 'wb')
|
||||
f.write(p.get_build_buffer())
|
||||
f.close()
|
||||
26
tests/test_pdf_normalisation.py
Executable file
26
tests/test_pdf_normalisation.py
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
import logging
|
||||
from PdfFileTransformer.PyPDF2 import PdfFileReader, PdfFileWriter
|
||||
|
||||
|
||||
input_file = "./samples/test1.pdf"
|
||||
output_file = "./samples/test1_out.pdf"
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
f_input = open(input_file, "rb")
|
||||
reader = PdfFileReader(f_input)
|
||||
|
||||
f_output = open(output_file, "wb")
|
||||
writer = PdfFileWriter()
|
||||
|
||||
writer.appendPagesFromReader(reader)
|
||||
writer.setHeader(b"%PDF-1.5")
|
||||
writer.write(f_output)
|
||||
|
||||
f_input.close()
|
||||
f_output.close()
|
||||
19
tests/test_pdf_rebuild.py
Executable file
19
tests/test_pdf_rebuild.py
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
|
||||
from PdfFileTransformer import Pdf
|
||||
import logging
|
||||
|
||||
input_file = "./samples/test1.pdf"
|
||||
output_file = "./samples/test1_out.pdf"
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
p = Pdf(input_file)
|
||||
f = open(output_file, 'wb')
|
||||
f.write(p.get_build_buffer())
|
||||
f.close()
|
||||
23
tests/test_polyglot_pdfzip.py
Executable file
23
tests/test_polyglot_pdfzip.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
|
||||
from PdfFileTransformer import Pdf
|
||||
from ZipFileTransformer import Zip
|
||||
from PolyglotFile import PolyglotPdfZip
|
||||
import logging
|
||||
|
||||
input_file_pdf = "./samples/test1.pdf"
|
||||
input_file_zip = "./samples/test1.zip"
|
||||
output_file = "./samples/test1_out.pdf"
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
p = Pdf(input_file_pdf)
|
||||
z = Zip(input_file_zip)
|
||||
a = PolyglotPdfZip(p, z)
|
||||
a.generate()
|
||||
a.write(output_file)
|
||||
20
tests/test_rebuild_zip.py
Executable file
20
tests/test_rebuild_zip.py
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
|
||||
import tempfile
|
||||
|
||||
from ZipFileTransformer import Zip, ZipFile
|
||||
|
||||
input_file = "./samples/test1.zip"
|
||||
output_file = "./samples/test1_out.zip"
|
||||
|
||||
zi = ZipFile(input_file,"r")
|
||||
zo = ZipFile(output_file,"w")
|
||||
zo.writestr(' ',b'AAAAAAAAAAAAAAAAAAAAAA',0)
|
||||
for zipinfo in zi.infolist():
|
||||
zo.writestr(zipinfo, zi.read(zipinfo))
|
||||
zi.close()
|
||||
zo.close()
|
||||
21
tests/test_zip.py
Executable file
21
tests/test_zip.py
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append("../")
|
||||
|
||||
import tempfile
|
||||
|
||||
from ZipFileTransformer import Zip
|
||||
|
||||
input_file = "./samples/test1.zip"
|
||||
output_file = tempfile.mktemp()
|
||||
print("Output: " + output_file)
|
||||
|
||||
z = Zip(input_file)
|
||||
a = bytearray(b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
|
||||
b = bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
|
||||
z.add_data_to_file(a, b, False)
|
||||
g = open(output_file, "wb")
|
||||
g.write(a + z.get_local_file_data() + b + z.get_data_after_central_directory())
|
||||
g.close()
|
||||
Reference in New Issue
Block a user