PDF to PCL conversion - java

In my Java application, I have PDF files that I eventually need to convert to PCL and send to a RightFax server. I'll also need to embed codes in the PCL files that RightFax will read to know where to send the fax.
What's the best approach towards doing this?
Searching online, it seems like I could use Java's StreamPrintService to print the PDF files to PCL. Is this correct? Does this also mean that I must have installed on my OS a printer that can interpret PCL?
Once the PCL file is generated, I need to add the embedded codes in the file. Do I add the codes to the end of the file (by opening it in Java and writing out to it)?

The simplies solution, IMHO, is to drop the PDF into a folder on the RightFax server. Then create a small text file with all the instructions for who to send the document to etc. using Embedded Codes or FCL (Fax Command Language). We do this all of the time and it works great. Note: Fax Command Languate is only available if you have the Integration Module. Both Embedded Codes and FCL each have a command to attach a file(s). Once RightFax receives this text file it will process the commands and attach the PDF and fax and/or email the document. Here are two examples (one Embedded and one FCL).
Embedded Code File:
<TOFAXNUM:999999999>
<TONAME:Douglas Anderson>
<BILLINFO1:12345>
<NOCOVER>
<WHO:DOUG>
<ADDDOC2: C:\pdfFiles\12345.pcl>
FCL Code File:
{{begin}}
{{fax 999999999}}
{{contact Douglas Anderson}}
{{billinfo1 12346}}
{{nocover}}
{{attach C:\pdfFiles\12345.pcl delete}}
{{imagetype pdf}}
{{end}}
Sending this simple text file to RightFax will prompt it to process and insert the document you specify. There are vaious ADDDOC commands and switchinges for ATTACH that tell RightFax to delete the file once it has been sent etc.
The Embedded Code File can be sent in via the HPFAX queue and the FCL can be sent in via the Production Inbox (c:\program files\rightfax\production\inbox).
This gives a lot of control and allows for easier troubleshooting as you still have a PDF that is viewable (due to the fact that you didn't stick text at the start of it), and you can easily output the Embedded Code or FCL files to an alternate folder for viewing and even modifying with simple tools like Notepad.
Edit: OpenSource is correct that you can concatenate files together, I haven't done this with Embedded Codes for a long time (see example at end) but have done something similar with FCL (if you have the Ingetration Module you can do this).
FCL with PDF or Postscript embedded in data (RightFax treats PS and PDF):
{{begin}}
{{fax 999999999}}
{{contact Douglas Anderson}}
{{billinfo1 12346}}
{{nocover}}
{{beginpostscript}}
%PDF-1.3...
...your pdf...
{{endpostscript}}
{{end}}
The PCL variant looks like this:
{{begin}}
{{fax 999999999}}
{{contact Douglas Anderson}}
{{billinfo1 12346}}
{{nocover}}
{{beginpcl}}
...your pcl data...
{{endpcl}}
{{end}}
False first page with Embedded Codes (as per my notes from something we did a long time ago):
<TOFAXNUM:999999999>
<TONAME:Douglas Anderson>
<BILLINFO1:12345>
<NOCOVER>
<WHO:DOUG>
<DELETEFIRSTPAGE>
*PCL formfeed character*
...your pcl data...
Whatever you send will appear on the 'first page' but this will be deleted. The other option is to send this data after the Formfeed a the end of the document and use the <DELETELASTPAGE> option. This data can also appear inline with the PCL file itself and as such you may be able to send it at the start of the job without the <DELETEFIRSTPAGE> command and the formfeed splitter.

We have a very similar process. What we do is we have a pcl file and a control file (a text file with the rightfax instructions in it). We concatenate these two files using java NIO and send it across to the rightfax print queue. We basically create a new file and write the above two into the new file using the transferFrom() method in the channel which is got by stream.getChannel(). We put control instructions at the top not at the bottom as you have mentioned? may be you misstated it - I think Rightfax needs it at the top. I have to admit I have not tried to send it at the bottom. May be it will work just dont know.

JPS lets you print to file so you just need to print to file on a PCL printer.

print-to-file seems to be the right approach here.

Related

Outpuf PDF as a stream for calling process

I'm using jasperstarter (a java program, open source) to generate reports that I define in iReports. This runs in windows and I need the output PDF generated to be directly read by the calling process which is a C# program.
Jasperstarter has lots of options like viewing the PDF generated directly, or generating the PDF as a file, sending it to printer, but no option to stream the result PDF to the calling process.
Is this possible at all, even if I have to change jasperstarter's open source code? How?
Is this possible in some other way that doesn't imply changing the jasperstarter's code? How?
Actually the answer was quite easy. I've downloaded jasperstarter and was able to use JasperExportManager.exportReportToPdfStream method which already existed on jasper's library to export the pdf to "System.out" stream. Together with adding a new option to run this process, this makes jasperstarter to be able to allow for redirection of the PDF's result (pipe '|' and redirect can be used directly on the program).
I tried contact with jasperstarter's project owner to see if I can get this change commited on the master branch.

Uploading the contents of a directory in JSP

I'm developing a JSP application, and I want to be able to upload the contents of a directory to the server. So the user will select the directory he wants to upload, and somehow all its contents will be uploaded.
Can't be done with regular HTML/Javascript, you have to use either Java or Flash.
There is no support for this in HTML (only uploading of a single file) so there is nothing you can do in your JSP. If you want to do this in java you will have to have something client side, like a signed Applet or a jar that the user downloads and runs.
Looks like it's time for a Framework! Struts2 can handle this type of jobs well and is easy to start with. Here you can take a look at a File Upload sample.
As said, there is no way to do this in JavaScript/HTML.
If you do not want to use a Java Applet (they are clunky and your users may not have Java installed), you can let people upload a zip file and extract it on the server (there is support for this in the Java standard API). Both Windows and Mac OS allow the clients to zip a folder by right-clicking.

How to split wmv file with java

How can I split *.wmv file (using java)?
I tryed simple algorythm like read bytes from wmv file and store first half in one file and other half in another file. But the second becomes non-playable.
As I can see i must add to the second file correct header to allow media-players interpret data correct.
Is it true? How can i do splitting if it is not and where can i find wmv header specification if my assumption is correct?
You won't be helping yourself with any format definitions, since WMV files are handled properly only through the Windows Media Format SDK.
Here is some (very little) info on how to call COM from java: http://www.eggheadcafe.com/software/aspnet/29766681/windows-media-encoder-sdk-java.aspx
Then, go to http://sourceforge.net/projects/windowsmedianet/files/WindowsMediaNetSamples/Dec%202008/
and download the samples, look into WMVSPLIT (I guess that's the name of the sample you should read).
Also, you should know that you will be able to split the files ONLY at CLEAN_POINTs (that's WMV lingo for KEYFRAME).
EDIT:
In fact, I would go, in your shoes, for some windows machine and simple .exe or some other kind of extra-process utility that you will execute from java. My strong belief is that it would be simpler.
And if you don't have a windows machine, you'll have to go through the VLC code to find ASF format parser.

Convert DGN to PDF

How can I convert MicroStation (DGN) files to PDF via command line?
The OpenDesign Alliance has libraries for dgn and dwg with pdf capabilities.
You could could use them to create the command line utility.
Decision Graphics http://www.dgnlink.com/ has a number of products that convert DGN to DWG, all of which can be run from a command line.
Once you have the DWG files, you can use one of the command line DWG to PDF converters (I can't recommend a specific one but a quick Google will find loads), or if you have a copy of AutoCAD or AutoCAD LT, you could write a script for that to convert the DWGs by using the DWG To PDF plotter.
From command line parameters, you can not do it. But you can create a Visual Basic or VB.NET application that will lunch microstation to do it for you.
I have been struggling with this one for a long time. All of the existing tools out there require expensive per-user licenses, which was a no-go for my implementation.
I solved the issue with a combination of three things:
Downloaded Bentley Viewer. This is their 100% free viewing/printing application.
Set up a virtual Windows postscript printer using GhostScript and RedMon. There are various guides online for this, and it can be a bit tricky to track down all of the prerequisites, but it is quite stable once set up correctly. Here is one guide: GhostScript/RedMon Guide
Use a "Key-In" script to pass print commands to Bentley View. This involves simply creating a text file with the required commands (List of Commands) and passing it AND the file you want to convert on the command line as such:
BentleyView.exe -M [Filename.dgn] -S[KeyIn FileName]
Please note that you need a space between the -M and the DGN filename but NOT between the -S and the Key-In script filename.
The script I used to simply print the document and then quit the GUI was:
PRINT PRINTERNAME PDFWriter
PRINT EXECUTE
QUIT
This is not a perfect solution at all, especially since it requires the installation of Bentley View and it also opens a UI when called (although it does close it immediately after printing).

In java web application how to print server file from client side

In the java web application need to select the file from server and print to the local printer. how it can be done
Thanks in advance
That's going to be tricky whenever you require a minimum of user interaction (i.e. just click the link and then do the print magic) and it also depends on the type of the file in question. If it is for example a .doc file, then you would basically need to download it to the client environment and open it in the default associated application (MS Word in this case) and then let the application execute the print command. You can't do this from the server side on.
Your best bet is to create an Applet which in turn displays the file tree, downloads the file to the local disk file system on client interaction and makes use of Desktop#print() to print it. E.g.
File file = new File("/temp/file.doc");
// Read file from server using URLConnection, write it to this file and then do:
Desktop.print(file);
But if it are for example plain text files such as text/html, text/xml, etcetera, then you can make use Javascript to load the file into some <div> or <iframe> element and then execute the window.print() method on it, if necessary along with a CSS media rule.
You will need an applet, flash, silverlight, javafx - i.e. an embedded app. There:
download the file from the server by creating a GET request (in an applet - using URL.openConnection()), obtaining the returned bytes and forming an in-memory document
sending that to a printer. If you chose applet - this might help
(I'm not aware whether the same flow can't be achieved with javascript as well)

Categories

Resources