I wanna know if it's possible to recognize printer in Java/C# as a pdf printer and block them.
The main reason behind this is, that i have a printing software with pictures which include copyrights. Within the web its easy for me to safe these copyrights with watermarks etc, but also the user is able to print out of the application.
If an user print the image to a pdf printer, he could cut the image out of the pdf f.e. .
Because in the printing result, the customer dont want a watermark
I dont think that this is possible by only checking a property. What you can do is first to get all the printers by
PrinterSettings.InstalledPrinters
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++){
pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
}
after that you can write out the printer settings with PrintSystemObject.PropertiesCollection or directly the processor name with the PrintProcessorProperty Class.
Then you need to look at the property if you can specify the PDF Printers with any of these properties.
You could check the print processor of the printer and see if it's a known PDF print processor.
https://msdn.microsoft.com/en-us/library/system.printing.printsystemobject.propertiescollection%28v=vs.110%29.aspx
Related
When I say print im talking about a physical printer so I want the users image chosen with jfilechooser to show up on the paper that comes out of the printer I can make it print out text but it also needs to show the image so far I have tried using buffered image and geticon neither of those worked so I really need help here.
I'm trying to generate an xsl to be printed in a pre-printed sheet which works fine.
Now i want to give the user a better previsualization (in the pdf screen version) adding a background image which emulates the "pre-printed" stuf on the sheet to give the user a "context" of what is he printing.
The question is: Is there any way I can set a background image in xsl (using apache fop) visible only in pdf but not in the printed version of it?
Thank you all for reading or givin any advice.
Although as the comments state, you can't have content in the PDF that does not come out in a physical printed copy, here is one possible work around for you. Depending on how your users are ultimately going to be using FOP for PDF rendering and how your a driving the work flow, it's possible to pass a parameter into an xslt file before the transofrmation phase is run, so potentially, you could do a dual rendering of the same PDF, one that is presented to the user where the background image is enabled, and one that gets printed, you could just set a variable similar to how they do in this Example, and call it something like $isPreview, and just use a simple if or choose statement to check for 'Y' or 'N'.
Since you are sending to a printer, you may even want to take advantage of FOP's ability to generate to Postscript rather than PDF, I've used this feature quite extensively for print documents using FOP while also producing a PDF copy for electronic delivery via email or hosted services, and I've yet to find any discrepancy between the PDF rendering and what is printed after sending a rendered postscript file, so it should work well for you as well.
As I said, this is not truly a solution to your problem as you've presented it, but as a work around, it could get you the desired results if your clever about how you implement it.
I don;t think the statement that it is not possible is true, I am just not sure how to create such a PDF with FOP. Certainly you can add an image field. One would use a button field and place the image in the button. Then you would set the properties of that button to not print (printable false).
PDF support images in fields: https://answers.acrobatusers.com/adding-image-field-form-q41825.aspx
RenderX supports PDF Form fields but I do not see where they support an image inside the button, only text: http://www.renderx.com/reference.html#PDF%20Forms. But they do support setting a field to "printable".
Is there a way to micro-adjust exactly where a PDF prints on a page within IText?
Here's my problem: It appears that naturally through variations in printer manufactures or age of printer, etc., minor variations occur when printing a PDF document. These variations are typically very small, however for 2 sample printers (both laser and the same model and manufacturer) the variation in text placement is upwards of 1-2 millimeters between printers. This would be fine for most normal printing however, for this task, this is outside of acceptable tolerances.
My gut reaction to this is to provide some ability to make micro adjustments to exactly where the print happens and thus be able to account for any variation within the printers themselves. Printing does appear to be consistent for all jobs sent to a single printer however.
Presently I have a PDF created in Adobe Acrobat Pro X that has form fields, that are then filled out by a java application and sent to the printer.
Thank you for any and all suggestions
My first attempt to solve this issue would be to try changing the default settings of the printer driver... somehow. But I can't give any useful pointers about that.
If you want to adjust the PDFs, you should probably change the page boundaries to shift the content. For example, this code shifts the content of the first page 50 units down, for a simple PDF that has only a MediaBox.
PdfReader reader = new PdfReader("in.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("out.pdf"));
PdfDictionary pagedict = reader.getPageN(1);
PdfArray mediabox = pagedict.getAsArray(PdfName.MEDIABOX);
mediabox.set(1, new PdfNumber(mediabox.getAsNumber(1).intValue()+50));
mediabox.set(3, new PdfNumber(mediabox.getAsNumber(3).intValue()+50));
stamper.close();
You'll have to adjust any other boxes (CropBox, BleedBox, etc) accordingly. Take a look at the PDF spec for information on the different page boundaries.
Using JSP and Jasper Reports, I made an application for printing A4 label pages.
I have to configure my application (set alignment on the PDF page to be generated) according to different pages (2×5, 2×7, 3×10 and 3×11 grids), different printers (Kyocera, OKI and HP) and different PDF viewers (Adobe, Foxit and Nitro).
Example: I set in Jasper Reports an A4 page with a grid of 2×5 and an user who has Foxit Reader will print it on a Kyocera. If another user has Kyocera too but is using Adobe Reader, the space between the columns gets smaller. But if the user has Foxit Reader but will print on an OKI, the whole document goes left and even gets cut.
To configure each individual label page is unavoidable, but can it be possible for me not have to set the page alignment for specific PDF viewer or printer (at least one of those)? It can be a way to skip the PDF generation or some conventional configuration that all printers would interpret - to get my page printed exactly the same, regardless of PDF viewer or printer.
Are you sure this is not a setting in Foxit Reader and/or Adobe reader that is causing the issue?
I know in Adobe reader there is a setting in the print dialog under Page Sizing & Handling. They should use Actual Size so as to not do any scaling or manipulation of the image.
In Foxit Reader it is under Print Handling. You need to set Scaling Type to None. The default seems to be Fit to Printer Margins.
You should not have to do anything different for each PDF reader and/or each version and combination of printer. That is a maintenance nightmare you should not try to take this on. You would have to make changes every time they bought a new printer, and potentially when an upgrade to their reader comes out.
Best bet is to figure out why they are producing different results, and tackle that issue, instead of brute forcing the problem. I am pretty sure this is more a training issue with your users, and telling them about these settings should clear up the problem.
UPDATE: After some more digging it seems to be possible to set the value of the Print Scaling while exporting. After you create your JRPdfExporter you need to set JRPdfExporterParameter.PRINT_SCALING to JRPdfExporterParameter.PRINT_SCALING_NONE:
exporter.setParameter(JRPdfExporterParameter.PRINT_SCALING, JRPdfExporterParameter.PRINT_SCALING_NONE);
I do not know if this will work for Foxit Reader also, but I would assume it would.
I examined the possibilities of previewing and printing generic text in Java. The requirements which I depend on are:
I should be able to specify font family and size of the font for both the preview component and for printed text.
The print preview must look exactly the same as the printed text.
Printing must be independend of printer device (no printer specific commands to define fonts etc.).
Printing of approx. 20 pages of generic text must start immediately (without any significant delay caused by data processing)
To meet the aformentioned requirements I first tried the Java Print Service API. I created the JTextPane which contained the text to preview and print. By using JTextPane I was able to specify the font so the result looked fancy. To print data from JTextPane I used the standard procedure, which is independend from printer device
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(myTextPane);
pj.print();
Everything would be fine if printing 20 pages of plain text wouldn't start in 15 seconds after the print() method was executed.
However printing starts immedialety when I print the same text as raw byte array ('application/octet-stream') with few PCL specific commands to set a proper font. But this approach is printer specific and there is also a problem with previewing the text so that the priview look exactly the same as printed text.
The problem with JTextPane is most likely caused by the fact that the data sent to printer are too large (pixel-by-pixel) while the second solution is a matter of few bytes. Unfortunately none of these solutions are sufficion for me because they don't meet all of the requirements.
Probably the solution would be if there is some 'facade' over printer control languages (PCL, ESC/P, ...) which would allow me to set the text font independently from the printer device. The problem with print preview would not be solved, but at least the printing would start immediately.
Any advice how to print the plain text not breaking the aforemention 4 criteria?
The problems above seems to be linked to Linux print driver and Cups.
I tried to print some text on Windows and everything works fine. Printing even starts immediately.