473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

How to print docx and pdf using Java in Python?

I actually can print using the txt file to printer, however, when I change to docx or pdf I get many undefined characters which cannot be understood at all. Do you guys have any ideas on how to solve this.

The code I used.

Expand|Select|Wrap|Line Numbers
  1. import system
  2. import javax.print
  3. import java.io
  4. from java.lang import Thread
  5.  
  6. filestream = java.io.BufferedInputStream(java.io.FileInputStream("C:/GEEKS.txt"))
  7.  
  8. psInformat = javax.print.DocFlavor.INPUT_STREAM.AUTOSENSE
  9.  
  10. myDoc = javax.print.SimpleDoc(filestream,psInformat,None)
  11.  
  12. aset = javax.print.attribute.HashPrintRequestAttributeSet()
  13. aset.add(javax.print.attribute.standard.Copies(2))
  14.  
  15. services = javax.print.PrintServiceLookup.lookupDefaultPrintService()
  16.  
  17. job = services.createPrintJob()
  18.  
  19. job.print(myDoc, None)
  20.  
  21. Thread.sleep(20000)
  22.  
  23. filestream.close()
Jun 26 '14 #1
1 1870
sicarie
4,677 Expert Mod 4TB
Why are you using Java inside Python? Is that a requirement? It looks like you're opening a file, getting a hash, looking up an attribute and printing it. I would imagine this is possible through Python without using the javax, but that is your decision on implementation.

Anyway, as .docx is a Microsoft proprietary format, you would need to know how it's formatted, and import a library that is able to read it and get through all the cruft that MS put in there.

From my Google search, it appears a docx is a zip'd openxml doc, so if you're doing it in Python you can import zipfile and use that. There also look to be a few custom-made libraries that will read docx's as well.
Jul 23 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tim Churches | last post by:
I am asking this on behalf of a Java enthusiast who is interested in using ZODB and other Python assets from his Java code: a) Has anyone used JPE (Java-Python Extension - see...
0
by: Natsu Mizutani | last post by:
Hello, I'm trying to wrap a c++ library using MPI inside with boost.python (or SWIG). I managed to find that calling `MPI::Init()` embeded in a c++ funtion would not work. So, I decided to use...
5
by: Maurice LING | last post by:
Hi, I've been using FB1.5 and access the database using Kinterbasdb + Python. My connection is established using kinterbasdb.connect() method and the parameters host, dns, database, user,...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
5
by: Steve | last post by:
I have added a page to the wiki, listing tools for Java-Python scripting (Java-Python interoperability). http://wiki.python.org/moin/Java_Scripting I have included information about all of...
2
by: Phoe6 | last post by:
print and softspace in python In python, whenever you use >>>print statement it will append a newline by default. If you don't want newline to be appended, you got use a comma at the end (>>>print...
1
by: harshavardhan | last post by:
Hi, here is the problem: Consider there are three frames in a HTML page. When I try to print these frames using java script, only the third document is being printed thrice. <HTML><HEAD> <script...
2
by: psbasha | last post by:
Hi, Is anybody tried using JAVA interface as front end and Python modules in the back end?. If so ,how to integrate the JAVA code with Python modules? How JAVA and Jython are...
4
by: cosmid | last post by:
Hi, I am new to Python. Just started learning it. I am just trying to follow the book and run the example given in the book. I created a module by saving 2 python statements in notepad and saved...
0
by: Tamer Higazi | last post by:
Hi people! I want to compile the Java Python Extension which I downloaded through CVS "http://jpe.cvs.sourceforge.net/jpe/" Building JPE by bootstrapping the makefile system with the cmd: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.