def _toPDF(fis) : b = ByteArrayOutputStream() # create a new document document = Document(); # get Instance of the PDFWriter pdfWriter = PdfWriter.getInstance(document, b) # document header attributes document.addAuthor("betterThanZero") document.addCreationDate() document.addProducer() document.addCreator("MySampleCode.com") document.addTitle("Demo for iText XMLWorker") document.setPageSize(PageSize.LETTER); # open document document.open(); # To convert a HTML file from the filesystem # String File_To_Convert = "docs/SamplePDF.html"; # //FileInputStream fis = new FileInputStream(File_To_Convert); # URL for HTML page # get the XMLWorkerHelper Instance worker = XMLWorkerHelper.getInstance(); # convert to PDF worker.parseXHtml(pdfWriter, document, fis); # close the document document.close(); # close the writer pdfWriter.close(); return b.toByteArray()
def createPDF(fis,map={},paragraph=None) : b = ByteArrayOutputStream() # create a new document document = Document(); # get Instance of the PDFWriter pdfWriter = PdfWriter.getInstance(document, b) # document header attributes if map : if map.has_key(AUTHOR) : document.addAuthor(map[AUTHOR]) if map.has_key(PRODUCER) : document.addProducer() if map.has_key(CREATOR) : document.addCreator(map[CREATOR]) if map.has_key(TITLE) : document.addTitle(map[TITLE]) document.addCreationDate() document.setPageSize(PageSize.LETTER); # open document document.open(); if paragraph : for pa in paragraph : document.add(Paragraph(pa)) # get the XMLWorkerHelper Instance worker = XMLWorkerHelper.getInstance(); # convert to PDF worker.parseXHtml(pdfWriter, document, fis); # close the document document.close(); # close the writer pdfWriter.close(); return b.toByteArray()