Re: [api-dev] How can I insert a header only in the first page
Fernand Vanrie wrote: aloizio schreef: Andrew, I am using this two methods to put header in my document, the problem is that the header appear in all pages. It must appear only in the first page. I using XStyle but doesn't modify anything. You must have 2 Pagestyles: Page1_style: with a Header and a next_style who is ponting to a Page2_Style Page2_Style with no Header and a nest_style who is now also Page2_Style You can define the Styles with te API or simply inclose themin a template or the Doc you are using Fernand public void setHeader(String p_jlsHF, String p_jlsImagePath,XTextDocument m_xTextDocument) { try { XTextCursor m_xTextCursor = m_xTextDocument.getText().createTextCursor(); final String f_jlsPrefix = p_jlsHF.equals(H) ? Header : Footer; //m_xTextCursor é classe membro que especifica o XTextCursor do XTextDocument atual XPropertySet xPageProps = (XPropertySet)UnoRuntime. queryInterface(XPropertySet.class, m_xTextCursor); String jlsPageStyleName = (String)xPageProps. getPropertyValue(PageStyleName); XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime. queryInterface(XStyleFamiliesSupplier.class, m_xTextDocument); //Usa a interface StyleFamiliesSupplier para obter a interface XNameAccess // da familia de estilos atual XNameAccess xFamilies = (XNameAccess)UnoRuntime. queryInterface(XNameAccess.class, xSupplier.getStyleFamilies()); //acessa a familia 'PageStyles' XNameContainer xFamily = (XNameContainer)UnoRuntime. queryInterface(XNameContainer.class, xFamilies.getByName(PageStyles)); //obter o estilo para a familia PageStyles XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, xFamily.getByName(jlsPageStyleName)); /*XStyle xStyle = (XStyle) UnoRuntime.queryInterface( XStyle.class, xFamily.getByName(First Page)); XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStyle); xStyleProps.setPropertyValue(FollowStyle, Right Page);*/ //obter a propriedade do TextCursor Sabe XPropertySet xStyleProps = (XPropertySet)UnoRuntime. queryInterface(XPropertySet.class, xStyle); //O cabeçalho/rodapé deve existir xStyleProps.setPropertyValue(f_jlsPrefix + IsOn, new Boolean(true)); //obter cabeçalho/rodapé XText xText = (XText)UnoRuntime.queryInterface(XText.class, xStyleProps. getPropertyValue(f_jlsPrefix + Text)); XTextCursor xTextCursor = xText.createTextCursor(); getFachadaOpenOffice().inserirCabecalho(m_xTextDocument, xText.getStart()); xTextCursor.gotoEnd(false); //p_jlsText é o parâmetro a ser inserido no cabeçalho/rodapé //xText.insertString(xTextCursor, p_jlsText, false); } catch (UnknownPropertyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WrappedTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } public void inserirCabecalho(XComponent document, XTextRange bookmark) { try { String imageUrl= ; String imageName = getDiretorioBase() + imagens// + getCabecalhoDocumento(); Image image = null; File imageFile = new File(imageName); try { imageUrl = (file:/// + imageFile.getCanonicalPath()).replace('\\', '/'); image = ImageIO.read(imageFile); } catch (java.io.IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } short hOrientation = HoriOrientation.LEFT; // Escolher HoriOrientation short vOrientation = VertOrientation.TOP; // Escolher VertOrientation int imageWidth; int imageHeight; int enlargement = 18; // depende do tamanho da imagem if (image != null) { imageWidth = (image.getWidth(null) * enlargement); imageHeight = (image.getHeight(null) * enlargement ); image.flush(); } else { imageWidth = 100; imageHeight = 100; System.out.println(Something is wrong with the image.); } TextContentAnchorType oTCAT = null; // Choose among TextContentAnchorType elements WrapTextMode oWTM = null; // Choose among WrapTextMode elements // Create
Re: [api-dev] How can I insert a header only in the first page
Andrew, I am using this two methods to put header in my document, the problem is that the header appear in all pages. It must appear only in the first page. I using XStyle but doesn't modify anything. public void setHeader(String p_jlsHF, String p_jlsImagePath,XTextDocument m_xTextDocument) { try { XTextCursor m_xTextCursor = m_xTextDocument.getText().createTextCursor(); final String f_jlsPrefix = p_jlsHF.equals(H) ? Header : Footer; //m_xTextCursor é classe membro que especifica o XTextCursor do XTextDocument atual XPropertySet xPageProps = (XPropertySet)UnoRuntime. queryInterface(XPropertySet.class, m_xTextCursor); String jlsPageStyleName = (String)xPageProps. getPropertyValue(PageStyleName); XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime. queryInterface(XStyleFamiliesSupplier.class, m_xTextDocument); //Usa a interface StyleFamiliesSupplier para obter a interface XNameAccess // da familia de estilos atual XNameAccess xFamilies = (XNameAccess)UnoRuntime. queryInterface(XNameAccess.class, xSupplier.getStyleFamilies()); //acessa a familia 'PageStyles' XNameContainer xFamily = (XNameContainer)UnoRuntime. queryInterface(XNameContainer.class, xFamilies.getByName(PageStyles)); //obter o estilo para a familia PageStyles XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, xFamily.getByName(jlsPageStyleName)); /*XStyle xStyle = (XStyle) UnoRuntime.queryInterface( XStyle.class, xFamily.getByName(First Page)); XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStyle); xStyleProps.setPropertyValue(FollowStyle, Right Page);*/ //obter a propriedade do TextCursor Sabe XPropertySet xStyleProps = (XPropertySet)UnoRuntime. queryInterface(XPropertySet.class, xStyle); //O cabeçalho/rodapé deve existir xStyleProps.setPropertyValue(f_jlsPrefix + IsOn, new Boolean(true)); //obter cabeçalho/rodapé XText xText = (XText)UnoRuntime.queryInterface(XText.class, xStyleProps. getPropertyValue(f_jlsPrefix + Text)); XTextCursor xTextCursor = xText.createTextCursor(); getFachadaOpenOffice().inserirCabecalho(m_xTextDocument, xText.getStart()); xTextCursor.gotoEnd(false); //p_jlsText é o parâmetro a ser inserido no cabeçalho/rodapé //xText.insertString(xTextCursor, p_jlsText, false); } catch (UnknownPropertyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WrappedTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } public void inserirCabecalho(XComponent document, XTextRange bookmark) { try { String imageUrl= ; String imageName = getDiretorioBase() + imagens// + getCabecalhoDocumento(); Image image = null; File imageFile = new File(imageName); try { imageUrl = (file:/// + imageFile.getCanonicalPath()).replace('\\', '/'); image = ImageIO.read(imageFile); } catch (java.io.IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } short hOrientation = HoriOrientation.LEFT; // Escolher HoriOrientation short vOrientation = VertOrientation.TOP; // Escolher VertOrientation int imageWidth; int imageHeight; int enlargement = 18; // depende do tamanho da imagem if (image != null) { imageWidth = (image.getWidth(null) * enlargement); imageHeight = (image.getHeight(null) * enlargement ); image.flush(); } else { imageWidth = 100; imageHeight = 100; System.out.println(Something is wrong with the image.); } TextContentAnchorType oTCAT = null; // Choose among TextContentAnchorType elements WrapTextMode oWTM = null; // Choose among WrapTextMode elements // Create graphic object XMultiServiceFactory xWriterFactory = (XMultiServiceFactory) UnoRuntime. queryInterface(XMultiServiceFactory.class, document); Object graphicObject = xWriterFactory.createInstance(com.sun.star.text.GraphicObject); // set propriedades XPropertySet xPropSet = (XPropertySet) UnoRuntime. queryInterface(XPropertySet.class, graphicObject); xPropSet.setPropertyValue(GraphicURL, imageUrl);
Re: [api-dev] How can I insert a header only in the first page
Hi aloizio, aloizio wrote: Andrew, I am using this two methods to put header in my document, the problem is that the header appear in all pages. It must appear only in the first page. I using XStyle but doesn't modify anything. [...] You must make sure that the first page has a different style then the pages theraafter. As Andrew suggested: make sure that you know how (page-) styles work in OOo. In a page style you can set a property: next page style. Also you can isert a hard break. That leads to properties in the first paragraph of a new page, in which a page style cen be defined. Kindest regards, Cor First, you need to know how to do this using the GUI. In other words, you must understand how styles work. After you understand styles and how to use them, then, and only then, should you attempt to code it using the API. If you do not understand how styles work, then understanding how to manipulate them from the API will not help. I recommend that you start with the documentation project and/or the user's guide to first learn how to use styles. -- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.odt My Book: http://www.hentzenwerke.com/catalog/oome.htm Info: http://www.pitonyak.org/oo.php See Also: http://documentation.openoffice.org/HOW_TO/index.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Cor Nouws Arnhem - Netherlands nl.OpenOffice.org - marketing contact - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [api-dev] How can I insert a header only in the first page
aloizio schreef: Andrew, I am using this two methods to put header in my document, the problem is that the header appear in all pages. It must appear only in the first page. I using XStyle but doesn't modify anything. You must have 2 Pagestyles: Page1_style: with a Header and a next_style who is ponting to a Page2_Style Page2_Style with no Header and a nest_style who is now also Page2_Style You can define the Styles with te API or simply inclose themin a template or the Doc you are using Fernand public void setHeader(String p_jlsHF, String p_jlsImagePath,XTextDocument m_xTextDocument) { try { XTextCursor m_xTextCursor = m_xTextDocument.getText().createTextCursor(); final String f_jlsPrefix = p_jlsHF.equals(H) ? Header : Footer; //m_xTextCursor é classe membro que especifica o XTextCursor do XTextDocument atual XPropertySet xPageProps = (XPropertySet)UnoRuntime. queryInterface(XPropertySet.class, m_xTextCursor); String jlsPageStyleName = (String)xPageProps. getPropertyValue(PageStyleName); XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)UnoRuntime. queryInterface(XStyleFamiliesSupplier.class, m_xTextDocument); //Usa a interface StyleFamiliesSupplier para obter a interface XNameAccess // da familia de estilos atual XNameAccess xFamilies = (XNameAccess)UnoRuntime. queryInterface(XNameAccess.class, xSupplier.getStyleFamilies()); //acessa a familia 'PageStyles' XNameContainer xFamily = (XNameContainer)UnoRuntime. queryInterface(XNameContainer.class, xFamilies.getByName(PageStyles)); //obter o estilo para a familia PageStyles XStyle xStyle = (XStyle)UnoRuntime.queryInterface(XStyle.class, xFamily.getByName(jlsPageStyleName)); /*XStyle xStyle = (XStyle) UnoRuntime.queryInterface( XStyle.class, xFamily.getByName(First Page)); XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStyle); xStyleProps.setPropertyValue(FollowStyle, Right Page);*/ //obter a propriedade do TextCursor Sabe XPropertySet xStyleProps = (XPropertySet)UnoRuntime. queryInterface(XPropertySet.class, xStyle); //O cabeçalho/rodapé deve existir xStyleProps.setPropertyValue(f_jlsPrefix + IsOn, new Boolean(true)); //obter cabeçalho/rodapé XText xText = (XText)UnoRuntime.queryInterface(XText.class, xStyleProps. getPropertyValue(f_jlsPrefix + Text)); XTextCursor xTextCursor = xText.createTextCursor(); getFachadaOpenOffice().inserirCabecalho(m_xTextDocument, xText.getStart()); xTextCursor.gotoEnd(false); //p_jlsText é o parâmetro a ser inserido no cabeçalho/rodapé //xText.insertString(xTextCursor, p_jlsText, false); } catch (UnknownPropertyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PropertyVetoException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WrappedTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } public void inserirCabecalho(XComponent document, XTextRange bookmark) { try { String imageUrl= ; String imageName = getDiretorioBase() + imagens// + getCabecalhoDocumento(); Image image = null; File imageFile = new File(imageName); try { imageUrl = (file:/// + imageFile.getCanonicalPath()).replace('\\', '/'); image = ImageIO.read(imageFile); } catch (java.io.IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } short hOrientation = HoriOrientation.LEFT; // Escolher HoriOrientation short vOrientation = VertOrientation.TOP; // Escolher VertOrientation int imageWidth; int imageHeight; int enlargement = 18; // depende do tamanho da imagem if (image != null) { imageWidth = (image.getWidth(null) * enlargement); imageHeight = (image.getHeight(null) * enlargement ); image.flush(); } else { imageWidth = 100; imageHeight = 100; System.out.println(Something is wrong with the image.); } TextContentAnchorType oTCAT = null; // Choose among TextContentAnchorType elements WrapTextMode oWTM = null; // Choose among WrapTextMode elements // Create graphic object XMultiServiceFactory xWriterFactory = (XMultiServiceFactory) UnoRuntime. queryInterface(XMultiServiceFactory.class, document);
Re: [api-dev] How can I insert a header only in the first page
Andrew Pitonyak, I don't understand styles well enough yet. Have you some example code? I have been working with OpenOffice API for three months. Andrew Douglas Pitonyak wrote: aloizio wrote: How can I insert a header that appear only in the first page of the document? I am using OpenOffice API, Java. You need to use a different page style for the first page and a different page style for the rest. You then enable the special header only in the first page page style. Do you understand styles well enough to implement this in styles to perform manually? After you do, then it is pretty easy to implement using the API by setting the page style on the first page. (but the first page style should set the next style to your standard page style.) -- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.odt My Book: http://www.hentzenwerke.com/catalog/oome.htm Info: http://www.pitonyak.org/oo.php See Also: http://documentation.openoffice.org/HOW_TO/index.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/How-can-I-insert-a-header-only-in-the-first-page-tf2570760.html#a7197645 Sent from the openoffice - api dev mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [api-dev] How can I insert a header only in the first page
aloizio wrote: I don't understand styles well enough yet. Have you some example code? I have been working with OpenOffice API for three months. First, you need to know how to do this using the GUI. In other words, you must understand how styles work. After you understand styles and how to use them, then, and only then, should you attempt to code it using the API. If you do not understand how styles work, then understanding how to manipulate them from the API will not help. I recommend that you start with the documentation project and/or the user's guide to first learn how to use styles. -- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.odt My Book: http://www.hentzenwerke.com/catalog/oome.htm Info: http://www.pitonyak.org/oo.php See Also: http://documentation.openoffice.org/HOW_TO/index.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[api-dev] How can I insert a header only in the first page
How can I insert a header that appear only in the first page of the document? I am using OpenOffice API, Java. -- View this message in context: http://www.nabble.com/How-can-I-insert-a-header-only-in-the-first-page-tf2570760.html#a7166317 Sent from the openoffice - api dev mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [api-dev] How can I insert a header only in the first page
aloizio wrote: How can I insert a header that appear only in the first page of the document? I am using OpenOffice API, Java. You need to use a different page style for the first page and a different page style for the rest. You then enable the special header only in the first page page style. Do you understand styles well enough to implement this in styles to perform manually? After you do, then it is pretty easy to implement using the API by setting the page style on the first page. (but the first page style should set the next style to your standard page style.) -- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.odt My Book: http://www.hentzenwerke.com/catalog/oome.htm Info: http://www.pitonyak.org/oo.php See Also: http://documentation.openoffice.org/HOW_TO/index.html - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]