473,386 Members | 1,819 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,386 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 1877
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.