问题
Our customer has tens of thousands of correspondence letters in Word 2007 format. They need to combine all the letters into a single large PCL file, which is then sent to the print vendor for bulk printing.
From what i understand PCL content is generated by a specific printer driver. So whether interactively or programmatically with VBA from the Document.PrintOut() function, when called to print to file, it passes content to the selected/default printer driver to output the PCL format.
Now, they have an existing .NET 1.1 batch job that generates PDF out from those Word documents. They wish to use the same batch job to combine them into that large PCL file. If a printer driver is involved in the process, how can multiple Word docs be programmatically "printed" to the same file?
回答1:
Is it an option to keep the PDF output based on the existing (working!) batch job that generates PDF?
The you could use these PDFs, feed them to a Ghostscript command and let Ghostscript output the PCL.
Are your PDFs single files, one for for each Word 2007 document? In this case, you can run Ghostscript like this to output (for example) color PCLXL:
gswin32c.exe ^
-dBATCH ^
-dNOPAUSE ^
-dSAFER ^
-sDEVICE=pxlcolor^
-sOutputFile=c:/path/to/big.pcl ^
1st.pdf ^
second.pdf ^
no3.pdf ^
fourth.pdf ^
[....]
If b/w PCL is good enough, then use "-sDEVICE=pxlmono"
.
Caveats: I'm not sure what the maximum is for the number of PDFs you can line up in one commandline. If it should become an issue, I'd recommend to concatenate all the PDFs first into one single big.pdf, using pdftk.exe
(http://www.accesspdf.com/pdftk/):
pdftk.exe ^
1st.pdf ^
second.pdf ^
no3.pdf ^
fourth.pdf ^
[....] ^
cat output ^
big.pdf # Here: direct control over order of the files in the result
or, simply using wildcards:
pdftk.exe ^
*.pdf ^
cat output ^
big.pdf # Here: order of files is alphabetically
Of course, here also could come up an issue with a limitation regarding the number of files processed by one command. However, with the second method it is easier to build bigger PDFs first through several rounds of concatenating. In any case, at the end: just direct your big.pdf to Ghostscript to convert to PCL/XL.
回答2:
I agree with pipitas that a workable solution of the existing process could work well. Depending on how they are saving to Word format, you could improve that by using the 'save as' function programmability to save as PDF format.
I'd put my code inline but it's a bit of a mess, simply search Google for Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF and you should see lots of examples of this.
Another thought more in line with your request, is to setup a generic PCL printer driver (HP LaserJet 4000 or similar) and programmability open each document and print to the default printer. The trick is to write those to a file. This can be done in a couple of manners.
Use Redmon or something similar to allow for output to file without any user intervention. We have a tool that works on XP, 2003 that allows for appending to file that we have used in a very similar instance where we need to concatenate 9000 print jobs a day together (I can send a link if it interests you).
The other is to use or write a quick capture tool that captures data on port 9100 (or 515 for LPR) and writes that data to file. The application becomes the printer and away you go.
Add a comment if you want any code for the items mentioned and I can paste them in.
回答3:
Most people are in too much of a hurry to convert PCL into PDF because they are not aware that there are tools that can index, sort, merge and edit PCL print streams. They know there are for PDF files, but not for PCL.
If you print to PDF you lose the paper handling features that would have been in the PCL. If you just concatenate PCL files, you might not get them in the correct sort order and you may want to insert OMR marks/barcodes for insertion or folding equipment, etc.
PCLTool SDK - Option V, which is a license for PCLXForm.exe. PCLXForm is a Windows console program that has a powerful script programming language with command line overrides and runtime include capabilities. The Port Monitor and HotDir print capture utilities that come with the SDK can capture, redirect and accumulate multiple print streams. However, it can also look inside them and determine the correct order they need to be in, convert them to PCL. (or, PDF with bookmarks, internal/external indexes, merged with other documents, etc.). It can also sort the documents into 1-7 page, 8-15 page, etc. folders. And, the appropriate OMR/Barcodes for mailing equipment or insert logos to make the document more TransPromo-like. The demo is at www.pagetech.com
来源:https://stackoverflow.com/questions/3098862/convert-several-thousands-word-doc-into-single-pcl-file