简体   繁体   English

DocumentPage 未从固定的 XPS 文档页面获取图像

[英]DocumentPage not getting the images from the fixed XPS document page

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:

fd.page.child

page.visual:页面.视觉:

页面.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?我怎样才能解决这个问题?

ok, it turns out "sequence" was not getting all the data from the fixedDocument so I used the FixedDocument paginator instead好的,事实证明“序列”没有从 fixedDocument 获取所有数据,所以我改用 FixedDocument 分页器

  For pageCount As Integer = 0 To fd.DocumentPaginator.PageCount - 1
                Dim page As DocumentPage = fd.DocumentPaginator.GetPage(pageCount)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM