While upload a doc and convert to html it is not working as expected on 2 layout

image.png (429.8 KB)

the first image when i try to upload docx and after convert to html i am using tool to show as pdf it is showing single layout rather than double side layout

export class ConversionService {
  private readonly tempDir: string;
  private readonly asposeClientId: string | undefined;
  private readonly asposeClientSecret: string | undefined;
  private readonly useAspose: boolean;

  constructor() {
    // Set temp directory for conversions
    this.tempDir = path.join(process.cwd(), 'uploads', 'temp', 'conversions');
    
    // Aspose.Words Cloud API credentials (required)
    this.asposeClientId = process.env.ASPOSE_CLIENT_ID || undefined;
    this.asposeClientSecret = process.env.ASPOSE_CLIENT_SECRET || undefined;
    this.useAspose = process.env.USE_ASPOSE === 'true' && !!this.asposeClientId && !!this.asposeClientSecret;
    
    // Aspose configuration initialized
    
    // Ensure temp directory exists (fire and forget)
    void this.ensureTempDir();
  }

  /**
   * Ensure temp directory exists
   */
  private async ensureTempDir(): Promise<void> {
    try {
      await fs.mkdir(this.tempDir, { recursive: true });
    } catch (error) {
      console.error('[ConversionService] Failed to create temp directory:', error);
    }
  }

  /**
   * Convert DOCX file to HTML using Aspose Words Cloud API only
   */
  async convertDocxToHtml(filePath: string): Promise<string> {
    // Use Aspose only (no fallbacks)
    if (this.useAspose) {
      return await this.convertDocxToHtmlWithAspose(filePath);
    } else {
      throw new Error('Aspose.Words Cloud API not configured. Cannot convert DOCX to HTML.');
    }
  }

  /**
   * Convert DOCX to HTML using Aspose.Words Cloud API
   * This method preserves headers, footers, and page templates better than other methods
   */
  private async convertDocxToHtmlWithAspose(filePath: string): Promise<string> {
    try {
      if (!this.asposeClientId || !this.asposeClientSecret) {
        throw new Error('Aspose credentials not configured');
      }

      // Get access token
      const tokenResponse = await axios.post(
        'https://api.aspose.cloud/connect/token',
        new URLSearchParams({
          grant_type: 'client_credentials',
          client_id: this.asposeClientId,
          client_secret: this.asposeClientSecret,
        }),
        {
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        }
      );

      const accessToken = tokenResponse.data.access_token;

      // Upload file to Aspose Cloud Storage
      const fileName = `temp_${Date.now()}_${path.basename(filePath)}`;
      const fileBuffer = await fs.readFile(filePath);
      
      await axios.put(
        `https://api.aspose.cloud/v4.0/words/storage/file/${fileName}`,
        fileBuffer,
        {
          headers: {
            Authorization: `Bearer ${accessToken}`,
            'Content-Type': 'application/octet-stream',
          },
        }
      );

      // File uploaded, converting to HTML
      const convertResponse = await axios.get(
        `https://api.aspose.cloud/v4.0/words/${fileName}`,
        {
          params: {
            format: 'html',
            // Options to preserve document structure
            exportHeadersFootersMode: 'PerSection', // Export headers/footers for each section
            exportImagesAsBase64: true, // Embed images as base64
          },
          headers: {
            Authorization: `Bearer ${accessToken}`,
            Accept: 'application/json',
          },
          responseType: 'arraybuffer',
        }
      );

      const htmlContent = Buffer.from(convertResponse.data).toString('utf-8');

      // Clean up - delete file from Aspose Cloud Storage
      try {
        await axios.delete(
          `https://api.aspose.cloud/v4.0/words/storage/file/${fileName}`,
          {
            headers: { Authorization: `Bearer ${accessToken}` },
          }
        );
        // Cleaned up Aspose Cloud storage
      } catch (cleanupError) {
        // Silently ignore cleanup errors
      }

      return htmlContent;
    } catch (error) {
      throw error;
    }
  }

image.png (282 KB)
image.jpg (67.1 KB)

Please share your document for the test. By the way, you send get request to https://api.aspose.cloud/v4.0/words/${fileName} url and specify a body for it, which is a bit strange
also we have the SDK for nodejs so it might be easier for you to use our API via SDK
https://www.npmjs.com/package/asposewordscloud

as per our conversation. i attached my document please check it and please respond as possible as soon
CL 01 30 04 24 Amendatory Endorsement Wyoming.docx (49.7 KB)
and please some example how to use sdk.

The same behavior you achieve with your code, you may achieve with one method

So you don’t need to upload a file to storage, execute the operation, and then download the result, with further file deletion. SaveAsOnline receives the file in the body, executes the conversion, and then sends the binary back, without storing the file in storage

if possible can you give complete code. it is half only showing. did you test with above file while converting html it is gvining 2 layout same like as doc
describe(“saveAsOnline test”, () => {
it(“should return response with code 200”, () => {
const wordsApi = BaseTest.initializeWordsApi();
const localName = “test_multi_pages.docx”;
const requestDocument = fs.createReadStream(BaseTest.localBaseTestDataFolder + “Common/” + localName);
const requestSaveOptionsData = new model.PdfSaveOptionsData({
fileName: BaseTest.remoteBaseTestOutFolder + “/TestSaveAs.pdf”
})
const request = new model.SaveAsOnlineRequest({

Just click on the link above the part of code, it is a github repository of our NodeJS SDK

i seen the code. which api i need to trigger to test it. what api i have to add in postman?

i clone the above project but how to test. could you please guide me to check on my local

I reproduced the issue you meant and already asked a team to check how to convert that document with the layout

is any update on this. this is right now for me blocker. please resovle this issue as possible as soon.

@stereio
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSCLOUD-3317

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

This issue is in analysis as soon as it is finished I share the results