Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Open XML SDK #1700

Open
cjalex1313 opened this issue Mar 26, 2024 · 2 comments
Open

Bug with Open XML SDK #1700

cjalex1313 opened this issue Mar 26, 2024 · 2 comments

Comments

@cjalex1313
Copy link

cjalex1313 commented Mar 26, 2024

Describe the bug
Docx file generated with OpenXML isn't able to be exported by soffice in linux (has something to do with the content)

To Reproduce

            using (MemoryStream memoryStream = new MemoryStream())
			{
                using (var doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Create(memoryStream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true))
				{
                    MainDocumentPart mainPart = doc.AddMainDocumentPart();
                    mainPart.Document = new Document();
                    Body body = mainPart.Document.AppendChild(new Body());
var table = new Table();
TableProperties tableProperties = new TableProperties();
tableProperties.TableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };
table.AppendChild(tableProperties);
TableGrid tableGrid = new TableGrid(
  new GridColumn(),
  new GridColumn()
);
table.AppendChild(tableGrid);
TableRow tableRow = new TableRow();
TableCell tc1 = new TableCell(
				new TableCellProperties(new TableCellWidth() { Width = "2500", Type = TableWidthUnitValues.Pct }),
				new Paragraph(new Run(
						new RunProperties(new FontSize() { Val = "56" }, new RunFonts() { Ascii = "Times New Roman" }),
						new Text("Patient Hours Detail")
					)
				)
);
TableCell tc2 = new TableCell(
				new TableCellProperties(new TableCellWidth() { Width = "2500", Type = TableWidthUnitValues.Pct }),
				new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new RunProperties(new FontSize() { Val = "34" }, new RunFonts() { Ascii = "Times New Roman" }), new Text(model.CaseName))),
				new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new RunProperties(new FontSize() { Val = "26" }, new RunFonts() { Ascii = "Times New Roman" }), new Text($"{model.StartDate.ToString("MM/dd/yyyy")} through {model.EndDate.ToString("MM/dd/yyyy")}")))
);
tableRow.Append(tc1);
tableRow.Append(tc2);
table.AppendChild(tableRow);
body.Append(table);
doc.Save();
memoryStream.Position = 0;
var byteArray = memoryStream.ToArray();
return byteArray;

then save the byteArray as "sdfomsef.docx" locally

then soffice --headless --convert-to pdf sdfomsef.docx

Error: source file could not be loaded

Expected behavior
If I try remove the 2nd table cell this works (this line tableRow.Append(tc2);)

Desktop (please complete the following information):

  • OS: Docker mcr.microsoft.com/dotnet/aspnet:6.0
  • Office version [e.g. 16.0.15427.20178]
  • .NET Target: .net6
  • DocumentFormat.OpenXml Version: 3.0.1
@twsouthwick
Copy link
Member

I'm not sure what soffice is. Does it open in word?

@mikeebowen
Copy link
Collaborator

Hi @cjalex1313, I'm able to recreate the issue and error you see with soffice, but removing the 2nd table cell doesn't fix it for me. I even created a .docx with no table using Word and tried to convert it to a PDF with soffice, but it also got the same error. I'm using Ubuntu SSL on Windows, so it's not the same environment. Are you able to use soffice to convert any docx to pdf?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants