473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Landscape Orientation margin problems

Hello,

The code which I have attached below properly has the margins working
in Portrait mode. The margin is contained in an object called
settings. The behavior is that the top and bottom margins work
correctly in both Landscape and Portrait. The left margin ends up
being large, around 2.5 inches, in Landscape mode, while in Portrait
it correctly is at .25 inches.

I was careful to set the orientation first, then the rest of the
paperformat and paper settings. So I am confused as to why it is not
working. Any help would be great! Thanks for all the help in
advance.

---------------snip---------------
public class Printer
{
public void toPrinter(String buffer, boolean confirm)
{
Book book;
PrinterPage printerPage;
String formattedBuffer;
PrinterJob printJob;
StringTokenizer pageTokenizer;
String pageStr;
PageFormat pageFormat;

formattedBuffer = formatBuffer(buffer);

printJob = PrinterJob.getPrinterJob();

if (confirm == true)
{
printJob.printDialog();
}

book = new Book();

pageTokenizer = new StringTokenizer(formattedBuffer, "\f");
while (pageTokenizer.hasMoreTokens())
{
pageStr = pageTokenizer.nextToken();
pageFormat = getPageFormat(printJob);
printerPage = new PrinterPage(settings, pageStr);
book.append(printerPage, pageFormat);
}

printJob.setPageable(book);

try
{
printJob.print();
}
catch (Exception PrintException)
{
PrintException.printStackTrace();
}
}
}
public class Printerpage extends Printable
{

public int print(Graphics g, PageFormat pageFormat, int pageIndex)
{
double height;
String newLineChars;
int newLineCharCount;
String line;
StringTokenizer lineTokenizer;

height = pageFormat.getImageableHeight();

//--- Create a graphic2D object a set the default parameters
g2d = (Graphics2D) g;

g2d.setColor(settings.getFontColor());

font = settings.getFont();
g2d.setFont(font);

//--- Translate the origen to be (0,0)
g2d.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());

//--- Print the output buffer
newLineChars = System.getProperty("line.separator");
newLineCharCount = 0;

horizontal = vertical = (int) settings.getMargin();
largestFontOnLine = settings.getFontPoints();

lineTokenizer = new StringTokenizer(pageBuffer, newLineChars,
true);

while (vertical < height && lineTokenizer.hasMoreTokens())
{
line = lineTokenizer.nextToken();

// check for an empty line
if (newLineChars.indexOf(line.charAt(0)) != -1)
{
// all characters comprising a new line must appear to
define a new line
// Unix systems are only \r while Windows are \n\r.
This is written to be
// OS independant.
++newLineCharCount;
if (newLineCharCount == newLineChars.length())
{
newLineCharCount = 0;
horizontal = (int) settings.getMargin();
vertical += largestFontOnLine;
}
continue;
}

// safety - checking if rendering occuring out of bounds
if (vertical > pageFormat.getImageableHeight())
{
break;
}

g2d.drawString(line, horizontal, vertical);
horizontal += (settings.getFontPoints() * token.length());
}

return PAGE_EXISTS;
}
}
----------------snip--------------------
Jul 17 '05 #1
1 3737
Sorry, I had forgotten to include this method from class Printer

----------snip----------
public PageFormat getPageFormat(PrinterJob printJob)
{
PageFormat pageFormat;
Paper paper;
int orientation;

pageFormat = printJob.defaultPage();

orientation =
PrinterCommands.orientationToJavaOrientation(DynaP roperties.getProperty(DynaProperties.PROP_PRINT_OR IENTATION));
pageFormat.setOrientation(orientation);
paper = pageFormat.getPaper();

paper.setImageableArea(settings.getMargin(),
settings.getMargin(), paper.getWidth()-(2*settings.getMargin()),
paper.getImageableHeight()-(2*settings.getMargin()));

pageFormat.setPaper(paper);

return pageFormat;
}
------------snip------------

happy trails
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ned | last post by:
I am having trouble with a layout that I am trying to convert from table based layout to css based layout. I have included source code for a stripped down version. The problem is that when the...
0
by: Linda Antonsson | last post by:
Hi, I am trying to put together a CSS-based layout consisting of a header, a sidebar and a main content area. Page: http://www.westeros.org/ASoWS/ CSS:...
2
by: lbbs | last post by:
every time I open my table and want to print I have to go to printer setup to chance it to landscape and to change the margin size. Can you save those settings?
5
by: Robert Schuldenfrei | last post by:
Hi Again, Forgive me for posting this again, but old items seem to get little review. I thought I could adjust the viewer properties without any further aid from the NG, but I was wrong. When...
12
by: Connor T | last post by:
Hi, I have a crystal report embedded in a viewer. How / Where can I set a property to make it default to landscape orientation? Rgds, Dan
1
by: Rich | last post by:
Hello, I found some code for printing a report (.rdlc) file without using the ReportViewer control. This code prints in the Portrait orientation which I presume is the default orientation. I...
5
by: ramesh1210 | last post by:
Hi all, Actually my requirement is that i need to print a page in landscape orientation , but i am unable to find solution for this through google. So I tried to print the page by...
2
by: J360 | last post by:
I'm using VB in Access 2003 to generate a dynamic report. I first open the report in design view to set all the grouping levels etc. I then use with rpt .printer.orientation =...
4
by: J360 | last post by:
Access 2003. I've set the report orientation to landscape using VB. The report that pops up is in Portrait view, but page orientation is correctly set to Landscape and it prints in landscape...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.