I would like to print a PDF document created with A4 format on a printer that is using US letter paper.
First, my method to print the doc on a printer with A4 format.
public static void printWithPdfBox(String strFilename) throws IOException, PrinterException
{
PrinterJob job = PrinterJob.getPrinterJob();
System.out.println("Printer name : "+ job.getPrintService().getName());
PDDocument doc = new PDDocument();
doc = PDDocument.load(strFilename);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
attributes.add(Sides.ONE_SIDED);
job.setPageable(new PDPageable(doc, job));
job.print(attributes);
}
I tried to add this attribute but it is not working :
attributes.add(MediaSizeName.NA_LETTER);
In the help of print method, it is mentionned :
Note that some attributes may be set directly on the PrinterJob by equivalent method calls, (for example), copies: setcopies(int), job name: setJobName(String) and specifying media size and orientation though the PageFormat object.
If someone has a solution, I'll apreciate his help ;o)
Related
I want to print Notes-documents directly to an pdf-printer. The documents are selected in a view. I do not want to open the printer dialog form.
Using the "NotesUIView.Print"- method works in principle, however, the generated pdf-documents sometimes look not exactly like the Notes-documents (especially regarding tables).
Therefore I tried to use the "NotesUIDocument.Print" - method:
Option Public
Option Explicit
Const pdfAppName = "PDF-XChange Standard"
Dim dc As NotesDocumentCollection
Dim curDoc As NotesDocument
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
...
Set dc = curDB.UnprocessedDocuments
...
Set curdoc = dc.GetFirstDocument
Call workspace.EditDocument(False,curDoc)
Set uidoc = workspace.Currentdocument
Call uidoc.Print(1,0,0,False,pdfAppName)
...
Dispite the first parameter in "uidoc.print" is set to "1" the printer dialog form opens. In the printer dialog form the printer "PDF-XChange Standard" is selected correctly. Selecting the "OK"-Button prints the document correctly.
Many thanks in advance for hints.
enter image description herei want to print all the Double variables in a java label. but when i execute the program only Qty1 print in the label.so that i used escape sequences but the also dont work. Could anyone tell me how to fix this.What i really expect to do is something like in the attachment.
Code
JButton receipt = new JButton("Receipt");
receipt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Double Qty1= Double.parseDouble(textField.getText());
Double Qty2=Double.parseDouble(textField_2.getText());
Double Qty3=Double.parseDouble(textField_3.getText());
lblRecipt.setText("\t\nHotel \n\nManagement System"+Qty1);
// lblRecipt.setText("Hotel Management System"+Qty1);
You can use swing's html formatting feature as explained in https://docs.oracle.com/javase/tutorial/uiswing/components/html.html.
To specify that a component's text has HTML formatting, just put the tag at the beginning of the text, then use any valid HTML in the remainder.
This is what swing example offers:
Your code might look like:
lblRecipt.setText("<html>\t<br>Hotel<br><br>Management System"+Qty1+"</html>");
I have realize that the SaveImage() command uses the last the last type of format that has been selected during normal DM operation. I assume that this option is selected somewhere in the GobalInfo tags. Please, could someone tell me which tag I have to modify to select dm4 format when I use SaveImage()?
'SaveImage()' is just a convenience wrapper. It is generally not the
Image which is saved to file, but an ImageDocument which can contain one ore more images. The latest DigitalMicograph help
documentation is more detailed about loading/saving than previous
ones, so I'm just copy-pasting the according passages below:
For example to store the front-most displayed image(document) as DM images, you may use:
string name = "C:\\TempImg"
string handler = "Gatan 3 Format"
ImageDocument doc = GetFrontImageDocument()
doc.ImageDocumentSaveToFile( handler, name )
And you can always get the ImageDocument from any image, using:
string handler = "Gatan 3 Format"
image img := RealImage("Test - not yet shown", 4, 100, 100 )
string name = "C:\\" + img.GetName()
ImageDocument doc = img.ImageGetOrCreateImageDocument()
doc.ImageDocumentSaveToFile( handler, name )
I want to print to a network printer from active reports but it always prints to default printer without throwing error.
Once I try to print with the .net printdocument library it print to specified printer.
I don't know why it is printing to default printer when using activereports.
Set the PrinterName property of the Printer object. Something like the following:
viewer.Document.Printer.PrinterName = "TheNetworkPrinterName";
viewer.Print();
The value of the PrinterName property should be the exact name from windows. To get a list of the valid printer names on a given system you can enumerate the list of printers using PrinterSettings.InstalledPrinters. An example of enumerating the available printers is in the MSDN documentation here.
If you try something and find it doesn't work give us more detailed information and we'll try to help you.
Change printer in end user designer.
Grapecityteam answer:
For a SectionReport, you could inject a Script to change the default printer when the report is loaded, in the LayoutChanged event of the Designer as given below:
private void OnLayoutChanged(object sender, LayoutChangedArgs e)
{
if (e.Type == LayoutChangeType.ReportLoad || e.Type == LayoutChangeType.ReportClear)
{
reportToolbox.Reorder(reportDesigner);
reportToolbox.EnsureCategories();
reportToolbox.Refresh();
RefreshExportEnabled();
CreateReportExplorer();
splitContainerMiddle.Panel2Collapsed = reportDesigner.ReportType == DesignerReportType.Section;
if (reportDesigner.ReportType == DesignerReportType.Section)
{
string script = string.Empty;
script += "public void ActiveReport_ReportStart()";
script += "{";
script += "rpt.Document.Printer.PrinterSettings.PrinterName = System.Drawing.Printing.PrinterSettings.InstalledPrinters[3];";
script += "}";
(reportDesigner.Report as SectionReport).ScriptLanguage = "C#";
(reportDesigner.Report as SectionReport).Script = script;
}
}
thanks to Grapecity Sales and Support
I have an XML as input to a Java function that parses it and produces an output. Somewhere in the XML there is the word "stratégie". The output is "stratgie". How should I parse the XML as to get the "é" character as well?
The XML is not produced by myself, I get it as a response from a web service and I am positive that "stratégie" is included in it as "stratégie".
In the parser, I have:
public List<Item> GetItems(InputStream stream) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(stream);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("item");
List<Item> items = new ArrayList<Item>();
Item currentItem = new Item();
Node node = nodeLst.item(0);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element item = (Element) node;
if(node.getChildNodes().getLength()==0){
return null;
}
NodeList title = item.getElementsByTagName("title");
Element titleElmnt = (Element) title.item(0);
if (null != titleElmnt)
currentItem.setTitle(titleElmnt.getChildNodes().item(0).getNodeValue());
....
Using the debugger, I can see that titleElmnt.getChildNodes().item(0).getNodeValue() is "stratgie" (without the é).
Thank you for your help.
I strongly suspect that either you're parsing it incorrectly or (rather more likely) it's just not being displayed properly. You haven't really told us anything about the code or how you're using the result, which makes it hard to give very concrete advice.
As ever with encoding issues, the first thing to do is work out exactly where data is getting lost. Lots of logging tends to be the way forward: create a small test case that demonstrates the problem (as small as you can get away with) and log everything about the data. Don't just try to log it as raw text: log the Unicode value of each character. That way your log will have all the information even if there are problems with the font or encoding you use to view the log.
The answer was here: http://www.yagudaev.com/programming/java/7-jsp-escaping-html
You can either use utf-8 and have the 'é' char in your document instead of é, or you need to have a parser that understand this entity which exists in HTML and XHTML and maybe other XML dialects but not in pure XML : in pure XML there's "only" ", <, > and maybe ' I don't remember.
Maybe you can need to specify those special-char entities in your DTD or XML Schema (I don't know which one you use) and tell your parser about it.