• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Printing PDF - Technical Solution Needed

 
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need some technical help in this problem that I am stuck in. I need to silent print(print without opening file) PDF file using java code. I have this code and it works fine except that it blows up font a little and the footer cuts off.



I don't know, how can I share .pdf files on this forum. Moderators could you please help me out?

Thanks in Advance
 
Shaan Shar
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just found from JAVA API docs following:



Now in my current code I am passing 3rd parameter(attributes) as null, as I don't know, how can I get attribute from my file. Could anyone help me out to get the attribute set for pdf file I have provided in FileInputStream() variable.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to silent print (print without opening file)


By "silent" I assume you mean "without showing a dialog to the user". The printer driver obviously will have to open the file.

Whether it's possible to print a PDF depends a good deal on the printer/printer driver you're using. Some printers can print PDFs, but many can't. For a general solution, I'd look into the https://pdf-renderer.dev.java.net/ library; it can print PDFs.
 
Shaan Shar
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:

By "silent" I assume you mean "without showing a dialog to the user". The printer driver obviously will have to open the file.

Whether it's possible to print a PDF depends a good deal on the printer/printer driver you're using. Some printers can print PDFs, but many can't. For a general solution, I'd look into the https://pdf-renderer.dev.java.net/ library; it can print PDFs.



Thanks for your reply ULF, but my printer is printing pdf file with this code, but the problem is, it blows up font a little and the footer cuts off.

I apologize if I haven't explained it correctly.
 
Shaan Shar
Ranch Hand
Posts: 1249
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,
Could you help me to upload a sample pdf file, so that I can show it to you?
 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ankur Sharma:
Now in my current code I am passing 3rd parameter(attributes) as null, as I don't know, how can I get attribute from my file. Could anyone help me out to get the attribute set for pdf file I have provided in FileInputStream() variable.


What you can try is to show a print dialog in a test setup, then read the DocAttributeSet it generates. Then create your own DocAttributeSet with the same contents in your real code.
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ankur Sharma:
Ulf,
Could you help me to upload a sample pdf file, so that I can show it to you?



I'm a new Bartender here so don't take this as 100% gospel but I'm pretty sure that Javaranch doesn't support uploads at this stage. Are you able to type out the surrounding lines?
 
Marshal
Posts: 66198
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the easiest ways to create a pdf is to use an office suite which supports pdf creation, write out a document with drawing objects in, and "export" it as a pdf. OpenOffice will do that easily.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the printing different than from printing the .pdf diractly from
a .pdf viewer ?
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!