0

I have this code

Private Sub SaveFixDoc(ByVal fd As FixedDocument, name As String)

    Dim filename As String = My.Settings.Path2Labels & "\" & name & ".xps"

    Try
        Dim xpsd As XpsDocument = New XpsDocument(filename, FileAccess.ReadWrite)
        Dim xpsdw As XpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsd)
        xpsdw.Write(fd) ' Write the FixedDocument as a document.

       ' ** All the way to here the fd.pages.child have my text and my images and they are rendered ok
        Dim sequence As FixedDocumentSequence = xpsd.GetFixedDocumentSequence()

        For pageCount As Integer = 0 To sequence.DocumentPaginator.PageCount - 1

            Dim page As DocumentPage = sequence.DocumentPaginator.GetPage(pageCount)

           '  **but in here the page is only taking the text and completely ignoring the images they just appear as empty paths **
            Dim toBitmap As New RenderTargetBitmap(4 * (CInt(page.Size.Width)), 4 * (CInt(page.Size.Height)), 384, 384, System.Windows.Media.PixelFormats.Pbgra32)
            toBitmap.Render(page.Visual)

            Dim bmpEncoder As JpegBitmapEncoder = New JpegBitmapEncoder()
            bmpEncoder.Frames.Add(BitmapFrame.Create(toBitmap))

            Dim fStream As New FileStream(My.Settings.Path2Labels & "\" & name & ".jpeg", FileMode.Create, FileAccess.Write)
            bmpEncoder.Save(fStream)
            fStream.Close()
        Next

        xpsd.Close()

    Catch ex As Exception

        Dim st As New StackTrace(True)
        st = New StackTrace(ex, True)
        Utilities.WriteToApplicationLog(New LogMessage() With {
                                           .MessageType = "Error",
                                           .MessageDetails = ex.ToString})

        Mediator.NotifyColleagues("MessageBox", New MessageBoxObject() With {
                                     .message =
                                     My.Resources.mbInstrError & " SaveSingleFixedContentDocument " & " " &
                                     st.GetFrame(0).GetFileLineNumber().ToString,
                                     .caption = My.Resources.mbExcelError,
                                     .button = MessageBoxButton.OK,
                                     .image = MessageBoxImage.Error})
    End Try
End Sub

enter image description here

fd.page.child:

fd.page.child

page.visual:

page.visual

I have change the renderer to several formats, made the render async and still the images will not load. How can I fix this?

1
  • The fStream variable should be declared in a Using block. Commented Jan 10, 2023 at 15:21

1 Answer 1

0

ok, it turns out "sequence" was not getting all the data from the fixedDocument so I used the FixedDocument paginator instead

  For pageCount As Integer = 0 To fd.DocumentPaginator.PageCount - 1
                Dim page As DocumentPage = fd.DocumentPaginator.GetPage(pageCount)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.