Header misaligned when saving file as a .doc file

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
sandyks
Posts: 11
Joined: Wed Jan 23, 2013 8:06 am

Header misaligned when saving file as a .doc file

Post by sandyks »

Hello,

I have a scenario which was working in OOO 2.*, but doens't seem to be working in OOO 3.*. :crazy:

I have a code snippet which prepares data, uses a templates(*.doc) and replaces the data with the necessary contents. Once done the file is saved as *.doc.

Earlier(in OOO 2.*) the file was saving as expected and the header was aligned as displayed in the attachment ACTUAL_INTENDED.jpg.
Actual file format the generated file was supposed to have
Actual file format the generated file was supposed to have
ACTUAL_INTENDED.jpg (6.81 KiB) Viewed 6985 times
Now( in OOO 3.*) the header is getting misaliged as displayed in the image Erroneous.jpg.
Erroneous.jpg
Erroneous.jpg (6.98 KiB) Viewed 6985 times
I can resolve the issue by saving the file as .odt and then convert into *.doc as opposed to directly saving as *.doc, but the file cannot be opened using Microsoft 2007. I get the following error "Word cannot start the converter mswrd632.wpc". Though that can also be resolved by deleting a registry entry, I do not wanna do that as many other windows based apps run on the machine and the after effects could be anything.

The file is being generated using a java code and have pasted the snippet below.

Code: Select all

XComponent document= doc.createDoc("***", templateDir+"/"+templateLocName,***,****,AsOfDate);
XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document); 

PropertyValue[] properties = new PropertyValue[2]; 
PropertyValue p = new PropertyValue(); 
p.Name = "FilterName"; 
p.Value = format.getFormatCode();  
properties[0] = p; 
        	
String loadURL = "file:///"+System.getProperty("*******")+"/"+fileName;
storable.storeToURL(loadURL, properties);	

I need to find an alternative wherein the *.doc file gets saved without the header misalignment and also it should open using Windows 2007.

Can anyone who have faced the issue please help me out here..
OpenOffice 3.3, Windows 7, Linux.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Header misaligned when saving file as a .doc file

Post by John_Ha »

Some observations ...

AOO 3 is very back level - does it work OK in AOO 4.1?

The .doc format is always likely to be tricky because AOO had to reverse engineer it. Is there a way you can do everything in .odt (or .ott if you need to use a template), and just do the final save in .doc if you must use .doc.
I can resolve the issue by saving the file as .odt and then convert into *.doc as opposed to directly saving as *.doc, but the file cannot be opened using Microsoft 2007
It looks like you are using something in Writer which is not available in .doc files. Unzip the .doc file (and the .odt file) and see if you can spot the error.

Is a workaround merely to add the extra few mm to the location in the Java code so as to correct the wrong position?

You might be better searching through, then asking your question in the Macros and UNI API forum at Macros and UNO API
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
sandyks
Posts: 11
Joined: Wed Jan 23, 2013 8:06 am

Re: Header misaligned when saving file as a .doc file

Post by sandyks »

I actually implemented your suggestion, i.e, saving the file as .odt and then converting it to .doc. Unfortunately MS 2007 has some problems opening the file.

I cannot move to AOO 4.1 since it needs to be installed on a windows machine owned by a different group and we have a stringent way of getting software's approved. As of now the approved version is 3.3, so am stuck with it. I also cannot go back to AOO 2.*

Hence I need to know what can be done.
Also I would like to know what could be wrong with the filter that I am using or if anything extra needs to be used to resolve the same.
OpenOffice 3.3, Windows 7, Linux.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Header misaligned when saving file as a .doc file

Post by John_Ha »

sandyks wrote:I actually implemented your suggestion, i.e, saving the file as .odt and then converting it to .doc. Unfortunately MS 2007 has some problems opening the file.
That is probably because you are doing something in Writer which is not available in .doc format; or because your code is creating something which odt is happy with, or ignoring, but which throws doc.

Try

1 unzip the doc file and the odt file and see if you can find what is causing the problem.

2 Keep on stripping stuff out of the odt before converting it to doc until it works. Now start putting stuff back until you find what is causing the problem.

3 Create what you want to do manually (without using your Java). Does that convert to doc OK? If it does, your Java is probably writing something wrong in the odt file. Compare the odt file written by Java with the one you did manually.

4 Check out Apache OpenOffice Developer's Guide. There is also a Validator - I think it is at http://www.openoffice.org/api/docs/comm ... dator.html.

This is the wrong forum to ask coding questions - you want the Macros and UNO API forum.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
sandyks
Posts: 11
Joined: Wed Jan 23, 2013 8:06 am

Re: Header misaligned when saving file as a .doc file

Post by sandyks »

Can you please let me know which is the right forum to post this question?
OpenOffice 3.3, Windows 7, Linux.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Header misaligned when saving file as a .doc file

Post by John_Ha »

sandyks wrote:Can you please let me know which is the right forum to post this question?
See my earlier post.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Header misaligned when saving file as a .doc file

Post by John_Ha »

Another thought.

1 Create the odt file using AOO 2
2 Create the odt file using AOO 3
3 Unzip the two odt files and compare them - what is different?

If they are the same

4 Create the doc file using AOO 2 and the AOO 2 odt file
5 Create the doc file using AOO 3 and the AOO 3 odt file
6 Unzip the two doc files and compare them - what is different?
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Header misaligned when saving file as a .doc file

Post by John_Ha »

sandyks wrote:I get the following error "Word cannot start the converter mswrd632.wpc"
If you google mswrd632.wpc you get lots of hits discussing it. It is apparently to do with MS Word and is saying that MS Word cannot start the MS converter mswrd632.wpc. eg see http://helpdeskgeek.com/office-tips/wor ... rd632-wpc/

How does the doc file look in the MS Word Viewer? In MS WordPad? In MS Works Word Processor?

From your images, the rectangle has been resized as well as the heading moving.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
sandyks
Posts: 11
Joined: Wed Jan 23, 2013 8:06 am

Re: Header misaligned when saving file as a .doc file

Post by sandyks »

John_Ha wrote:
3.Unzip the two odt files and compare them - what is different?

6 Unzip the two doc files and compare them - what is different?
What do you mean by unzipping the odt and doc files. I use securezip and am I am unable to open them using secureZip.

Regarding the registry entry removal, We have lot many wondows based applications on that machine and do not know the effects of removal of the entry, hence this is again a complete no-no.

Meanwhile as you mentioned I have posted the question in the forum you mentioned and is availabe under the following link.

viewtopic.php?f=25&t=70660
OpenOffice 3.3, Windows 7, Linux.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Header misaligned when saving file as a .doc file

Post by John_Ha »

Download PKZip for Windows or 7_zip - both are free. Although odt and doc files don't use zip as the qualifier, they are actually ZIP files (and you can rename them to zip if you want).

See these posts for what an odt file looks like when opened with 7-Zip - just drag contents.xml onto the desktop. Re: [Hint] How did I fix my ODT file and Re: [Hint] How did I fix my ODT file

I suggest you read the whole topic - it deals extensively with opening odt files and what you will find inside them.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Post Reply