Trouble saving docs with images

Aug 6, 2013 at 10:02 PM
Hi,

I'm really excited to use the new JS APIs, and I've had good luck creating and editing documents without images. However, if I try and simply re-save a document with images, it is way bigger on disk and fails to open in OSX Pages with an "unknown error" error. (I'm running this in Node on v0.8.14 on Mountain Lion.) When trying to open the created file in OSX Word, it displays a 98-page long document consisting of Base64. (Which is possibly the incorrectly-encoded image?)

This is my first experience with OpenXML so maybe I'm missing something obvious. The trick of renaming the file to ".zip" then opening it also fails with the created doc, throwing a "Error 2 - No such file or directory" error.

Thanks!

Below is the CoffeeScript I'm using, you can see that it's really simple.
fs = require 'fs'
vm = require 'vm'
_ = require 'underscore'
argv = (require 'optimist').argv
util = require 'util'

include = (path) ->
  code = fs.readFileSync path, 'utf8'
  vm.runInThisContext code, path

include("linq.js");
include("ltxml.js");
include("ltxml-extensions.js");
include("jszip.js");
include("jszip-load.js");
include("jszip-inflate.js");
include("jszip-deflate.js");
include("openxml.js");

DOMParser = require('xmldom').DOMParser;
Ltxml.DOMParser = DOMParser;

XAttribute = Ltxml.XAttribute;
XCData = Ltxml.XCData;
XComment = Ltxml.XComment;
XContainer = Ltxml.XContainer;
XDeclaration = Ltxml.XDeclaration;
XDocument = Ltxml.XDocument;
XElement = Ltxml.XElement;
XName = Ltxml.XName;
XNamespace = Ltxml.XNamespace;
XNode = Ltxml.XNode;
XObject = Ltxml.XObject;
XProcessingInstruction = Ltxml.XProcessingInstruction;
XText = Ltxml.XText;
XEntity = Ltxml.XEntity;
cast = Ltxml.cast;
castInt = Ltxml.castInt;

W = openXml.W;
NN = openXml.NoNamespace;
wNs = openXml.wNs;

buffer = fs.readFileSync argv.file
b64 = buffer.toString 'base64'

doc = new openXml.OpenXmlPackage b64

content = doc.saveToBase64()
outBuffer = new Buffer content, 'base64'
fs.writeFileSync argv.out, outBuffer
Dec 19, 2013 at 8:13 PM
So you tried this on a document without an image, and it worked, then you tried it on a document with an image, and it did not work?

I am not seeing in this code where your input file is being converted from binary to base64, you will first need to perform that conversion.

Also I think a feature request I have is that a raw binary format is not accepted in the openXml.OpenXmlPackage() function.

I should be able to do something like

$.ajax("/myfile.xlsx").done(function(data){
var doc = new openXml.OpenXmlPackage(data);
});

But that doesn't work since data is binary instead of base64.

So what I did is to use a converter like this: http://www.motobit.com/util/base64-decoder-encoder.asp
that converted the document I wanted to load into base64, I saved that in a text file and used that instead.
Jan 2, 2014 at 10:07 PM
Thanks for the info.