Return-Path: X-Original-To: apmail-poi-user-archive@www.apache.org Delivered-To: apmail-poi-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4C9F49DD5 for ; Thu, 7 Jun 2012 08:48:54 +0000 (UTC) Received: (qmail 36391 invoked by uid 500); 7 Jun 2012 08:48:53 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 36361 invoked by uid 500); 7 Jun 2012 08:48:53 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Delivered-To: moderator for user@poi.apache.org Received: (qmail 26901 invoked by uid 99); 7 Jun 2012 08:44:03 -0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: 216.139.236.26 is neither permitted nor denied by domain of mrbains21@gmail.com) Date: Thu, 7 Jun 2012 01:43:37 -0700 (PDT) From: mrbains21 To: user@poi.apache.org Message-ID: <1339058617698-5710067.post@n5.nabble.com> Subject: How to change margins of a word document MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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.(HeaderBlock.java:104) at org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:138) at org.apache.poi.hwpf.HWPFDocumentCore.verifyAndBuildPOIFS(HWPFDocumentCore.java:106) at org.apache.poi.hwpf.HWPFDocument.(HWPFDocument.java:174) at setm.(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