Save as Word looks good, but Save as PDF does not

I have distilled my issue down to the simplest pieces, and I am using the latest Aspose.Words.Net 23.11.0.

I have an EMF file in a folder that is added to an Aspose.Words document, and then saved as PDF.

  • The Word file looks perfect.
  • The PDF file renders differently, resulting in text layout issues.
  • Generating PDF with the only change being ColorMode = Grayscale, the PDF renders correctly. Unfortunately, color is required so this is not acceptable.

I’m attaching several files to help diagnose this:

  • The original example EMF file being inserted into the document
  • The generated Word docx file
  • The problematic PDF file
  • The grayscale PDF that renders correctly

Note that I have tried playing with every setting I could in PdfSaveOptions, and nothing I tried helped.

Below is the code used to insert the EMF and then save the file.

    Private Sub convertEmfToPdf(pdfFileName As String, tempEmfFilePaths As List(Of String))
        Dim doc As New Aspose.Words.Document()
        Dim builder As New Aspose.Words.DocumentBuilder(doc)

        Dim imageNum As Integer = 1
        For Each tempEmfFilePath As String In tempEmfFilePaths
            If imageNum > 1 Then builder.InsertBreak(Aspose.Words.BreakType.SectionBreakNewPage)

            'Read the image from file, ensure it is disposed.
            Using image As Drawing.Image = Drawing.Image.FromFile(tempEmfFilePath)
                'Find which dimension the frames in this image represent. For example 
                'The frames of a BMP Or TIFF are "page dimension" whereas frames of a GIF image are "time dimension". 
                Dim dimension As New Drawing.Imaging.FrameDimension(image.FrameDimensionsList(0))

                'Get the number of frames in the image.
                Dim framesCount As Integer = image.GetFrameCount(dimension)

                'Loop through all frames.
                For frameIdx As Integer = 0 To framesCount - 1
                    'Insert a section break before each New page, in case of a multi-frame TIFF.
                    If (frameIdx <> 0) Then builder.InsertBreak(Aspose.Words.BreakType.SectionBreakNewPage)

                    'Select active frame.
                    image.SelectActiveFrame(dimension, frameIdx)

                    'We want the size of the page to be the same as the size of the image.
                    'Convert pixels to points to size the page to the actual image size.
                    Dim ps As Aspose.Words.PageSetup = builder.PageSetup

                    ps.PageWidth = Aspose.Words.ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution)
                    ps.PageHeight = Aspose.Words.ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution)

                    'Insert the image into the document And position it at the top left corner of the page.
                    builder.InsertImage(image, Aspose.Words.Drawing.RelativeHorizontalPosition.Page, 0, Aspose.Words.Drawing.RelativeVerticalPosition.Page, 0, ps.PageWidth, ps.PageHeight, Aspose.Words.Drawing.WrapType.None)
                Next
            End Using

            imageNum += 1
        Next

        'PDF options
        Dim pdfSaveOptions As New Aspose.Words.Saving.PdfSaveOptions

        'Used only for grayscale example
        'pdfSaveOptions.ColorMode = Aspose.Words.Saving.ColorMode.Grayscale

        'Save as Word file
        'doc.Save(pdfFileName + ".docx")

        'Save as PDF
        doc.Save(pdfFileName, pdfSaveOptions)
    End Sub

Aspose example - 2023-11-28.zip (128.1 KB)

@chrism.peloton
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): WORDSNET-26287

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.