Set margins when printing

I have problems to set the margins for printing..
I set margins in this way:
when I start the printing process I do:
        PrinterJob job = PrinterJob.getPrinterJob();
        final Stamp canvas = new Stamp();
        job.setPrintable(canvas);
        MediaPrintableArea area = new MediaPrintableArea(10, 10, 170, 255, MediaPrintableArea.MM);
        HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(area);
        if (job.printDialog()) { // chiede conferma definitiva
            try {
                job.print(aset);
            } catch (PrinterException ex) {
                Logger.getLogger(Stampa_Try_For_PreciseLocation.class.getName()).log(Level.SEVERE, null, ex);
        }in the canvas class I try to read the margins :
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
        if (pageIndex >= 1) {
            return Printable.NO_SUCH_PAGE;
        Graphics2D g2 = (Graphics2D) g;
        g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        AffineTransform at = new AffineTransform();
        at.scale(pageFormat.getImageableWidth(), pageFormat.getImageableHeight());
        g2.transform(at);
        double pageWidth = pageFormat.getWidth();
        double pageHeight = pageFormat.getHeight();
        double pageSpUsedX = pageFormat.getImageableX();
        double pageSpUsedY = pageFormat.getImageableY();
        double pageSpUsedWidth = pageFormat.getImageableWidth();
        double pageSpUsedHeight = pageFormat.getImageableHeight();
        System.out.print("larghezza pg = " + pageWidth);
        System.out.println(" ; altezza pg = " + pageHeight);
        System.out.print ("area usabile X = " + pageSpUsedX);
        System.out.println(" ; area usabile Y = " + pageSpUsedY);
        System.out.print("area usabile larghezza  = " + pageSpUsedWidth);
        System.out.println("  ; area usabile altezza = " + pageSpUsedHeight);
        g2.drawString("x as", (float)pageSpUsedX                         , (float)pageSpUsedY);
        g2.drawString("x ad", (float)pageSpUsedX + (float)pageSpUsedWidth, (float)pageSpUsedY);
        g2.drawString("x bs", (float)pageSpUsedX                         , (float)pageSpUsedY + (float)pageSpUsedHeight);
        g2.drawString("x bd", (float)pageSpUsedX+ (float)pageSpUsedWidth , (float)pageSpUsedY + (float)pageSpUsedHeight);
                return Printable.PAGE_EXISTS;
    }But the result is not what I expected to be....
I am working at a program that have to print 'something' on paper's labels
placed in a normal sheet format A4.
and for this purpose it is very important to have the contrlo where the letters are wrote..
I don't know what it is wrong and I need some help..
thank you in advance..
regards
tomyMrsangelo

hi Andre,
thank you to answering me,
I tried with your code but still I have not the control that I would have printing.
Perhaps I misunderstand the role and the means of the parameters used for set the printable
area.......
For example.. when I set the margins in this way:
MediaPrintableArea area = new MediaPrintableArea(10, 10, 170, 255, MediaPrintableArea.MM);
I expect to have one area printable with the shape of a rectangle that, on a sheet of
paper A4 format, begin in the corner up to left in the point (5, 10) and have a horizontal size
of 180 millimeters and a vertical size of 265 millimeters.
But this is not happen..., I measured the horizontal side in 150 millimeters (instead 170) and
the vertical size in 248 millimeters (instead 255)....
Measuring the coords of the corner on top to left, I got (5, 13) and not (10, 10).
.....I tried with other values of parameters and never I got the exact values that I expected to have.
Having to print labels glued on a paper sheet - A4 format,
*I need to be sure that when the statement
g2.drawString("x", 0, 0);
is executed
The character x is wrote, on the paper, at the point 10, 10. *
Perhaps
g2.drawString("+", 0, 0);
is not the right operation to get this target..... ????
Regards
tonyMrsangelo

Similar Messages

  • Cannot change the print margins when printing out my spreadsheet.  Tried clicking on format and then Document but when I enter a number I always get " invalid number".

         I cannot change the margins when printing out my spreadsheet.  I clicked on the format then on document and got a entry box.  But everytime I try entering a number to change the left margin ( tried .5 ) I get an " invalid number " response.  I can print out the spreadsheet but always get a message telling me the margins may be too small and data may be clipped.  Data doesn't get clipped but left part of the spreadsheet is right at the left side of the paper.  Want to change the margin so I don't get that message.

    Naming the spreadsheet app would do wonders for getting an answer.

  • A way to reduce margins when printing multiple pages per sheet?

    I really like the new leopard print dialog box. Is there a way of reducing the large margins when printing 2, 4, or more pages per sheet (in Layout)?

    You could use custom page sizes (in the Page Setup dialog) or you could see if the settings in the Paper Handling panel help at all.

  • How do I remove top and bottom margins when printing using Adobe Acrobat XI Standard.

    How do I remove top and bottom margins when printing using Adobe Acrobat XI Standard. (I selected 'Fit to scale' and there's a huge gap on the top and bottom).

    Those margins are usually reported from the printer settings to Acrobat. Meansif you have, for example, an inkjet printer and that printer can not print seamlessly, then there will be a minimum margin.
    Check your printer's page settings.

  • How to change margins when printing in landscape

    Hi all,
    I have a network printer installed on Solaris 6. To get it to print in "landscape" i added a filter - like this:
    Input types: any
    Output types: landscape
    Printer types: any
    Printers: any
    Filter type: slow
    Command: /etc/lp/landscape.sh
    The script: landscape.sh:
    echo "^[&l1O"
    cat -
    echo "^[&l0O"
    When i print like this: lp -dprinter -olandscape filename it print�s in landscape. Problem is i can�t set up any margins.
    Printer is configurated like this:
    Banner: on:Always
    Content types: landscape
    Device: /dev/null
    Interface: /etc/lp/test
    Printer type: unknown
    Modules:
    Options:
    I tried to modify it�s interface file, but that had no effect. Here are the line i tried to modify
    # PC-850, 12 cpi, 12 pkt, normal Courier, 6 col. Left Marg., 2 lin. TopMarg.
    echo '\033(0N\033(s0p12.00h12.00v0s0b3T\033&a6L\033&2E\c'
    How can i change the margins ?
    Thank u all
    Thomas

    It sounds like either the font is corrupted or your AddressBook prefs are whacked.
    You can check the font in FontBook > File> Validate Fonts, or in /Users/yourname/Library/Preferences/com.apple.AddressBook.plist move it to the desktop and restart.
    -mj

  • Extra margins when printing double sided

    I'm using Word 2007 and have created recipe cards using a basic recipe templete in Word. I have the top margin set to .25 and I'm printing on a regular 8x11 piece of card stock (I want to simply cut the sides and bottom down to make a 4x6 index card).
    However, the margin is printing at almost .75 when I print double sided. Any help would greatly appreciated! I've been working on this problem for two days and I bought the printer to print both sides.
    Thanks!

    Did you ever figure this out? Because my C309g changes my margins when I print double sided, and I can't find any info on it anywhere...!

  • Margins when printing handouts.

    When printing a handout from slides is there a way to increase the margins? Keynote prints the slides (and rules if you use them) almost right out to the edge of the page. I couldn't find anything on this in the help file.
    Thanks.
    John
    G5   Mac OS X (10.4.7)  

    To set a custom margin, you need to create a custom paper size. To do this, go into Page Setup, and under Paper Size choose Manage Custom Sizes. In the new dialog, click the plus sign at the bottom left to create a new size. Set the paper size to whatever you want (it should be 8.5X11" for letter, of course), and then set the margins to the size you need. Once you click the OK button, this paper size will now be available to choose in the Page Setup dialog.

  • HT3771 How do I adjust print margins when printing from Safari?

    When I try to print email from Safari, my messages go all the way to the edge of the paper and get cut off. I can't find any page set up adjustments for margins when in Safari, like I can in other software (Word, Excel, etc.).  All I can find are page size, orientation, etc.

    Welcome to Apple Support Communities. We're all users here.
    Let me hazard a wild guess that you're using Outlook, formerly Hotmail, for email in your web browser.
    When the forced 'downgrade' from Hotmail to Outlook occurred, they decided to hide some frequently used commands and made simple message printing from a browser print command nearly impossible, at least for Mac users.
    The trick is to use the Print command now hidden within the Outlook menu bar.
    It's in the "..." section of the Outlook top menu bar following Categories along with "Mark Read, Mark Unread, Flag, Unflag, and View Message Source".
    Select Print from there, it will open a new Outlook Print Message window. You should once again be able to print emails in their entirety.

  • HP Officejet Pro 8620 Shifted Margins when printing

    The only problem I find when printing paper is that the margins are always shifted. The margins of the paper on my PC display Is different to when Officejet Pro 8620 prints the paper. I tried printing with borderless on, but the margins are either to close to the top of the paper; I also tried printing with borderless off, but the margins shifts way below compared to the paper on the computer display. My older printer HP Officejet 4500 wireless has a "minimize margins" option, and the printer always prints exactly as it is on the display; however, it is no so with my newer Pro printer. I tried going to advanced options and clicking on preserve layout, which is available only when doing 2-sided printing, and the margins were still shifted; there are pictures on the bottom that can show you. I looked around preference options of the printer, paper setup, printer properties, tried readjusting settings, but the problem is persisting. I do not want to go any further, or else I might screw everything up. Additionally, the problem is not with the copy settings of the printer, I looked there too and the margin shift is turned off. Please help me find a solution. I use this printer to print books, and I need to finish it ASAP, thank you for your support  Printed Paper Page 1: Printed paper margins are shifted slightly higher, compared to PC display paper   Printed Paper Page 2: Printed paper margins are shifted down, compared to PC display paper   Paper Displayed on Computer: Observe the top margin distance from the top of the screen   

    Hi , Exon737 wrote:
    For the first question: Yes, when I print multiple page copies in 1-sided or 2-sided format it makes margin shifts. 1-sided printing margin is shifted down for all pages. 2-sided printing margin shifts up for odd pages and shifts down for even pages.This would mean it's something in the hardware that is causing the shifting.  HP regularly releases firmware updates that may help. You can click on this link to Get Printer Updates for HP Officejet Pro. I would also check for crumpled paper inside the printer. All of the steps can be found here, but I copied the main step for you. Check the carriage path for obstructions with a flashlight;Place your fingers into the slot on the left side of the printer, and then pull to open the cartridge access door. The carriage moves into the access area. Wait until the carriage is idle and silent before you continue.Disconnect the power cord from the rear of the printer, and then unplug the power cord from the power source or electrical outlet.Use a flashlight to check for torn pieces of paper that might remain inside the printer. 
      I would then clean the paper feed rollers, steps copied from this document.Follow these steps to clean the paper pick rollers.Place your fingers in the slot on the front of Tray 1.
    Figure : The slot on the front of Tray 1
    Pull the tray toward you to remove it.
    Figure : Pull out the input tray
    If you use Tray 2, lift the printer off Tray 2, and then set the printer aside.
    Figure : Lift the printer off Tray 2
    Turn the printer so you see its underside, and then locate the pick roller.
    Figure : Locate the pick roller
    Roll the pick roller to the right so that the rubber part faces you. This might require some force.
     NOTE:The pick roller should only rotate to the right.
    Figure : The pick roller in its normal position
    Figure : The rubber part of the pick roller
    The rubber part of the pick rollerRotate the rubber part of the pick roller so that it faces youLightly dampen a clean, lint-free cloth with bottled or distilled water, and then squeeze any excess liquid from the cloth.Press the cloth against the rubber part of the roller, and then rotate the roller to the right with your fingers. Apply a moderate amount of pressure to remove any dust or dirt buildup.Rotate the roller back to its original position.
    Figure : The pick roller in its original position
    Turn the printer back around so that the printer control panel faces you.Place the printer its normal position.Reinstall Tray 1. Then I would try aligning the printhead.On the printer control panel, swipe the display to scroll to Setup () and touch itSwipe the display to scroll then touch Tools.Touch Align Printhead.  Please let me know if any of these steps resolved your issue, or if there is anything else I can do to help.  I look forward to hearing from you!  Thanks, 

  • Howto change left/right margin when print

    In a report we defined a left margin of 2 cm and a right margin of 1 cm.
    When printing the report simplex everything is ok.
    But when printing the report duplex we want to change the margins. Odd pages should print "normal" - but the page on the back, i.e. even pages, should then be "moved" to the left. That means the left margin has to be 1 cm and the right margin 2 cm.
    How can we achieve this behavior?

    Hi Rainer
    For information on settings for Duplex printing please refer to the below link:
    [link|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40e40899-721e-2b10-b084-c7ed76af46f1]
    Hope this helps!!
    Regards
    Sourashree

  • Top margin when printing with Generic text driver

    I created a report in Character Mode and tryed to print it using the Generic Text windows printer driver, but the Reports is adding a non-specified top margin. I already removed all the margins of this report in the Layout Editor but the problem continues. What can I do to solve this problem ?

    Is it shifting only down, or to the right as well?
    What are the bleed an slug settings, and are you including slug and bleed in the print?
    Is the dialog set to print in upper left corner, and if so does it change when you print centered?
    Peter

  • Preview not putting in margins when printing

    I have an HP6500 e709 (Duplex) printer that is capable of no margin printing that will accept any margin arrangement from zero up to half the paper size being used. I have a document that was set up in Pages with landscape margins set for: Left - .25", right - .25", top - .75" (no header), bottom - .75", footer - .75" (10 pt type) then exported to PDF in sections because each section has its own paging. The sections were then combined into one document using "Combine PDF", a free application. When I printed this document from Preview I noticed that both right and left margins on the printed page were .5" or or more which cut off both right and left parts of most lines and in one section skipping an entire left hand column. The individual sections print properly from Pages.
    Is this a problem with Preview?

    I have discovered that this may be a printer driver problem though there are different symptoms on different applications but is more related to the duplex printer capability.
    Sparkgapper

  • Set MARGIN  of Printer with REPORT6

    I have some reports and to print some of them, the margin of prinetr must set to .5 and user must set it before any print. how can i set it in report builder with code or is there any way to solve this problem.
    and users dont do this.

    Hi,
    On Windows the printer margin is controlled by the printer driver. This is called the printer or hardware margin. To this, you add the margin defined inside the report definition. The sum total is the margin that you will see on the report's printed output. For example, if the default printer margin is 2 cm, and you have defined 3 cm inside the report defintion, you should see a total 5 cm margin on the printed output. This should be consistent across prints. So you can reduce / increase the report definition margin, to get the exact output that you want in the printed output.
    However, if you find that even by making the report definition margin zero you cannot get the margin that you want, then you can upgrade to version 6i patchset 15. From this patch onwards, the printer default margin is ignored, and only the report definition margin is counted.
    Also, you can find useful notes if you serach for "margin" on Metalink.
    Navneet.

  • Deskjet 3050 leaves a margin when printing A4

    When I try to print a photo on A4 the printing output has at every or sometimes two sides a blank margin.
    In the height about 4 mm and in the smaller side about 8 mm. I need it printed out precise in the A4 dimensions (210x297 mm).
    How can I arrange that.  I have tried several software but it did not work out.
    How can I manage this problem?
    Thanks

    Hello h-wijnen,
    What you are referring to is named borderless printing. I am sorry to say that the model you own does not support borderless printing on a4 size papers or any others paper sizes for that matter. HP models that support borderless printing almost always have Photosmart in the name.
    Say "Thanks" by clicking the Kudos Star in the post that helped you.
    Although I work for HP my posts and replies are my own
    Please mark the post that solves your problem as "Accepted Solution"

  • Unwanted margins when printing images

    All,
    I have an application that loads images from a chosen directory and loads them into tabs. I then have print options. All is fine printing however there is a 1" border around the image. This seems to squish the image smaller which results in more difficulty reading.
    I have aquired a PrintImage class for GIF's somewhere from the Sun site and modified it to also accept JPG and PNG. Can anyone give an idea on how set the margin attributes from this code?
    public class PrintImage {
        public void PrintImage(String path, String type) {
            /* Use the pre-defined flavor for a GIF from an InputStream */
            DocFlavor flavor = null;
            if (type.equals("gif")) {
                flavor = DocFlavor.INPUT_STREAM.GIF;
            } else if (type.equals("jpg") || type.equals("jpeg")) {
                flavor = DocFlavor.INPUT_STREAM.JPEG;
            } else if (type.equals("png")) {
                flavor = DocFlavor.INPUT_STREAM.PNG;
            /* Create a set which specifies how the job is to be printed */
            PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
            aset.add(MediaSizeName.NA_LETTER);
            aset.add(new Copies(1));
            /* Locate print services which can print a GIF in the manner specified */
            PrintService[] pservices =
                    PrintServiceLookup.lookupPrintServices(flavor, aset);
            if (pservices.length > 0) {
                /* Create a Print Job */
                DocPrintJob printJob = pservices[0].createPrintJob();
                /* Create a Doc implementation to pass the print data */
                Doc doc = new InputStreamDoc(path, flavor);
                /* Print the doc as specified */
                try {
                    printJob.print(doc, aset);
                } catch (PrintException e) {
                    System.err.println(e);
            } else {
                Component frame = null;
                JOptionPane.showMessageDialog(frame,
                "No suitable printers.",
                "Print error",
                JOptionPane.ERROR_MESSAGE);
        public static void main(String args[]) {
    class InputStreamDoc implements Doc {
        private String filename;
        private DocFlavor docFlavor;
        private InputStream stream;
        public InputStreamDoc(String name, DocFlavor flavor) {
            filename = name;
            docFlavor = flavor;
        public DocFlavor getDocFlavor() {
            return docFlavor;
        /* No attributes attached to this Doc - mainly useful for MultiDoc */
        public DocAttributeSet getAttributes() {
            return null;
            /* Since the data is to be supplied as an InputStream delegate to
             * getStreamForBytes().
        public Object getPrintData() throws IOException {
            return getStreamForBytes();
        /* Not possible to return a GIF as text */
        public Reader getReaderForText()
        throws UnsupportedEncodingException, IOException {
            return null;
            /* Return the print data as an InputStream.
             * Always return the same instance.
        public InputStream getStreamForBytes() throws IOException {
            synchronized(this) {
                if (stream == null) {
                    stream = new FileInputStream(filename);
                return stream;
    }

    To set a custom margin, you need to create a custom paper size. To do this, go into Page Setup, and under Paper Size choose Manage Custom Sizes. In the new dialog, click the plus sign at the bottom left to create a new size. Set the paper size to whatever you want (it should be 8.5X11" for letter, of course), and then set the margins to the size you need. Once you click the OK button, this paper size will now be available to choose in the Page Setup dialog.

Maybe you are looking for

  • Cannot download iTunes 7 and trouble with existing iTunes file

    I downloaded iTunes onto my hard drive on my computer but also onto an external hard drive as well. Everything worked fine until I went to open iTunes on my desktop one day and an error window popped up. "Windows - No Disk Exception Processing Messag

  • Getting complete file path in Adobe Interactive Form

    Hi All, I have a requirement where I have a field ZPATH1 on Adobe Interactive Form. I am putting a BROWSE button and writing following JavaScript on CLICK event on this button for populating the chosen file path into field ZPATH1. *Start of JavaScrip

  • Help with MyBT and Billing

    Hi, I recently set-up a MyBT.com account, placed an order for Broadband and TV etc and then subsequently cancelled it because I screwed up the order. Unfortunately I now have a MyBT account that I will not use. The problem is that I keep getting emai

  • N8 camera blurs

    After i have updated my n8 and c7 from s^3 to anna.....................i found that the camera quality of n8 as well as the c7 deteriorates................now the camera gives blur images.................whereas i have updated my n8 camera from nokia

  • How do you send an email to everyone in your address book

    hi guys. do you know how i send an email to everyone in my address book