Edit and save a landscape docx as pdf not working in .NET

Original docx file is LANDSCAPE. I load docx file into GroupDocs.Edtor. I then do editor.save using PDF save option. Document is in saved in PORTRAIT mode which cuts off information.

Attached is document.169025_20200106162749_169025_Orthopedic_Applications_of_Stem_Cell_Therapy_Med_Policy_20180601.zip (23.0 KB)

Here is the pdf that GroupDocs produced. 85851436-e810-4292-88da-21c6c1eef03a.pdf.zip (117.9 KB)

Version 20.3.0.0 - Maybe my issue is in the fixContent() function that I had to do because I was trying to work around errors I was getting in GroupDocs.

private void saveFiles(Document document, string newDocxFullPath, string newPDFFullPath, string content)
{
var newContent = fixContent(content);
var oldContent = File.ReadAllBytes(document.fullPath);
MemoryStream inputStream = new MemoryStream(oldContent);
using (Editor editor = new Editor(delegate { return inputStream; }, delegate { return new WordProcessingLoadOptions(); }))
{
EditableDocument readyToSave = EditableDocument.FromMarkup(newContent, null);
if (!string.IsNullOrEmpty(newDocxFullPath))
editor.Save(readyToSave, newDocxFullPath, new WordProcessingSaveOptions(WordProcessingFormats.Docx));
if (!string.IsNullOrEmpty(newPDFFullPath))
editor.Save(readyToSave, newPDFFullPath, new PdfSaveOptions());
readyToSave.Dispose();
editor.Dispose();
}
inputStream.Close();
}

    private string fixContent(string content) // CLF - I do this or I get errors with GroupDocs
    {
        var newContent = content;
        newContent = newContent.Replace(@"<colgroup>", ""); //CLF TODO - getting errors if content contains colgroup report to GroupDocs
        newContent = newContent.Replace(@"</colgroup>", "");
        newContent = newContent.Replace(@"<col />", "");
        newContent = newContent.Replace(@"placeholder", "value");
        return newContent;
    }
1 Like

@CLQcflowers,

Thanks for the details. We are investigating this issue. Your investigation ticket ID is EDITORNET-1586. As there’s any update, you’ll be notified.

1 Like

@atirtahir3 I’ve created a small test project in GitHub - GitHub - cindyflowers/GroupDocs.Editor-for.NET-WebForms: GroupDocs.Editor-for.NET-WebForms

1 Like

@CLQcflowers,

Thanks for the demo application. We’ll investigate it.

@CLQcflowers,

We have investigated the source DOCX document and output PDF file, your description and the source code, and below is our conclusion:

  1. Original source DOCX file has pages in a landscape mode, not a portrait. And when opening it for edit, and then saving to the PDF, this PDF will have portrait mode, and textual content is truncated. This issue is reproduced and is expected behavior. Also, the same behavior will be present when you select DOCX (or any other Word Processing format) too. Output DOCX will also have portrait orientation and truncated content. This is because page orientation is a page-related metadata, which is ignored in float mode. And float mode is enabled by default. In order to preserve page orientation, you should use only paginal mode during forward and backward conversion. Please try to use the below code and observe the resultant DOCX.

     Options.WordProcessingEditOptions editOptions = new WordProcessingEditOptions(true);/* pagination is enabled in forward options */
     Options.WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docx) {EnablePagination = true};/* pagination is enabled in backward options */
    
     using (Editor editor = new Editor("path\to\Orthopedic_Applications_of_Stem_Cell_Therapy_Med_Policy_20180601.docx"))
     {
         using (EditableDocument intermediate = editor.Edit(editOptions))
         {
             //let's imagine there are some edits with EditableDocument's content, and it was obtained from client-side after edits were done
             editor.Save(intermediate, "path\to\output.docx", saveOptions);
         }
     }
    
  2. Open the output DOCX and tell us if you need exactly the same result. If no, tell us/point out where is the issue.

  3. Currently PdfSaveOptions doesn’t support the paginal mode. In other words, you can save edited Word Processing document back to Word Processing format in paginal mode. But when output format is PDF, paginal mode is not supported at the moment, and only float is available. We will add support of paginal mode for PDF output format in version 20.4, corresponding ticket is EDITORNET-1591.

  4. Your code contains a fixContent method with description (getting errors if content contains colgroup report). It was true prior to GroupDocs.Editor for .NET version 20.3. But in 20.3, COLGROUP element is supported. We’d recommend you to use that.

@CLQcflowers,

Your reported issue EDITORNET-1591 is now fixed in API version 20.4. We’ve added a new property in PdfSaveOptions class:

public bool EnablePagination {get; set;}

As far as EDITORNET-1586 is concerned, we need your feedback on this reply.