poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrbains21 <mrbain...@gmail.com>
Subject How to change margins of a word document
Date Thu, 07 Jun 2012 08:43:37 GMT
Hi i am new to java and poi interface. I had this project in which i want to
change the margins and page size of an existing word document. So far i've
not reached anywhere need your help guys. Ill paste the code i wrote so far
but it gives the error:

java.io.IOException: Unable to read entire header; 57 bytes read; expected
512 bytes
	at
org.apache.poi.poifs.storage.HeaderBlock.alertShortRead(HeaderBlock.java:226)
	at
org.apache.poi.poifs.storage.HeaderBlock.readFirst512(HeaderBlock.java:207)
	at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
	at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
	at
org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:106)
	at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)
	at setm.<init>(marg.java:37)
	at marg.main(marg.java:22)

Here is my code and i am using eclipse IDE: 


import java.util.*;
import java.io.*;

import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import java.util.Iterator;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hwpf.*;
import org.apache.poi.hwpf.extractor.*;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.BottomMarginRecord.*;

import java.io.*;

public class marg {
	public static void main(String[] args) {

		setm ob = new setm();

	}
}

class setm {
	static final double LeftMargin = 1.25;
	static final double RightMargin = 1.25;
	static final short TopMargin = 1;
	static final short BottomMargin = 1;

	public setm() {
		try {
			FileInputStream fis = new FileInputStream("sample.doc");
			// POIFSFileSystem fs = new POIFSFileSystem(fis);
			HWPFDocument doc = new HWPFDocument(fis);
			RecordInputStream r = new RecordInputStream(fis);

			BottomMarginRecord bm = new BottomMarginRecord(r);
			TopMarginRecord tm = new TopMarginRecord(r);
			RightMarginRecord rm = new RightMarginRecord(r);
			LeftMarginRecord lm = new LeftMarginRecord(r);

			bm.setMargin(BottomMargin);
			tm.setMargin(TopMargin);
			lm.setMargin(LeftMargin);
			rm.setMargin(RightMargin);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

I need some help urgently.
Thnx in advance.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/How-to-change-margins-of-a-word-document-tp5710067.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message