Hi,
Is it possible to make Aspose.Words recognise @media print CSS commands?
We have HTML that can be displayed on screen, which needs to act differently when viewed via a browser or printed. In particular we have the following HTML to signify a page break, which shows “----Page Break—” on screen, but actually implements a page break when printed…
----Page Break----
The following CSS is used to achieve the screen vs print…
@media screen {
.pageBreakPrint {
display:none;
}
}
@media print {
.pageBreakScreen {
display:none;
}
.pageBreakPrint {
width:100%;
page-break-after:always;
}
}
This thread says that this is not possible with your Aspose.PDF component, so I’m going to assume that Aspose.Words will not be able to handle
@media queries either. Please can you confirm that is the case?
If it is not possible to convert the document using
@media print queries, can you please tell me how I can convert any instance of the above HTML so that a new page is created?
(Oh, and BTW, your Tag selection system on this forum is simply awful!)
Many thanks,
Tom
I’ve managed to figure out how to replace the text with page-breaks, although this is leaving a blank line at the start of the new page, which I’m struggling to remove…
Dim opts As New FindReplaceOptions(FindReplaceDirection.Backward)
opts.ReplacingCallback = New ReplacePageBreak()
htmlDoc.Range.Replace("----Page Break----", “”, opts)
Private Class ReplacePageBreak
Implements IReplacingCallback
Private Function IReplacingCallback_Replacing(ByVal e As ReplacingArgs) As ReplaceAction Implements IReplacingCallback.Replacing
If TypeOf e.MatchNode.ParentNode Is Paragraph Then
Dim oldPara As Paragraph = e.MatchNode.ParentNode
Dim newPara As New Paragraph(e.MatchNode.Document)
newPara.AppendChild(New Run(e.MatchNode.Document, ControlChar.PageBreak))
oldPara.ParentNode.InsertBefore(newPara, oldPara)
oldPara.ParentNode.RemoveChild(oldPara)
Return ReplaceAction.Replace
Else
Return ReplaceAction.Skip
End If
End Function
End Class
Can anybody suggest a way to replace the “----Page Break—” with a page-break that doesn’t result in an empty paragraph at the top of the new page?
I’d still appreciate knowing if @media print queries are likely to be supported at any time in the near future?
Many thanks,
Tom
Hi Tahir,
Brilliant - the highlighted builder insert is exactly what I needed.
The page breaks are now working exactly as required, thank you
Cheers,
Tom
Hi Tom,
Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.