I am using xslfo to generate PDFs for some time now, but I always came across the question, how to call <fo:block break-after="page"/> without generating an empty page? That is, I would like to check if the current page is empty and in that case, not to call <fo:block break-after="page"/>?
anyone having a solution to this?
Thanks in advance
Well, you are probably using Apache FOP. This XSL FO:
<fo:page-sequence master-reference="first">
<fo:flow flow-name="xsl-region-body">
<fo:block>Test</fo:block>
<fo:block break-after="page"/>
<fo:block break-after="page"/>
<fo:block break-after="page"/>
<fo:block break-after="page"/>
<fo:block break-after="page"/>
<fo:block>Test</fo:block>
</fo:flow>
</fo:page-sequence>
Would render 2 pages in a compliant XSL FO rendering engine. Using RenderX XEP = 2 pages. using FOP 6 pages (which is wrong).
Related
I am genereating PDF-files with links and want them to be displayed differently when viewing them in a PDF viewer than when printing them. When viewing them the links are to have a blue border around the link, but when printed there shall be no border.
I am using Antenna House Formatter v6.3 and know that you can use axf:layer-settings and axf:layer to create layers and control the print and view-behavior of those layers. But I have not been successful to achieve the above described behavior (I can only make the entire link disappear in print, not just the border).
Is there any way to use the Antenna House extensions or some other way to make links in PDF generated via XSL-FO and a formatting engine to have different appearances in view and print?
Try this. You may need to adjust the baseline-shift value, depending on your font:
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
axf:layer-settings="'layer4' view off print on,'layer5' view on print off export off">
...
<fo:block space-before="1em">abcd <fo:inline-container alignment-baseline="baseline" baseline-shift="-3pt">
<fo:block-container position="absolute" axf:layer="layer5">
<fo:block>
<fo:basic-link border="thin solid blue" alignment-baseline="baseline" external-destination="http://www.antennahouse.com/">Antenna House</fo:basic-link>
</fo:block>
</fo:block-container>
<fo:block-container axf:layer="layer4">
<fo:block>
<fo:basic-link border="thin solid transparent" external-destination="http://www.antennahouse.com/">Antenna House</fo:basic-link>
</fo:block>
</fo:block-container>
</fo:inline-container> efgh</fo:block>
Requires PDF 1.5 or later. See https://www.antennahouse.com/product/ahf65/ahf-ext.html#pdf-layer
I'm adding an SVG logo to every page of a document and notice that the logo gets "inlined" on every page, rather than appearing only once in the PDF file and then referenced when used on each page.
This means that the PDF file becomes much bigger than it needs to be.
Here's what I do:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:afp="http://xmlgraphics.apache.org/fop/extensions/afp"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm"
margin-top="5mm" margin-bottom="5mm"
margin-left="1.0in" margin-right="1.0in">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="10mm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait"
initial-page-number="1"
force-page-count="no-force">
<!-- header -->
<fo:static-content flow-name="xsl-region-before">
<fo:block text-align="end" >
<fo:external-graphic
src="../mylogo.svg"/>
</fo:block>
</fo:static-content>
<!-- content -->
<fo:flow flow-name="xsl-region-body">
<!-- a simple 2 page document -->
<fo:block page-break-before="always"> X </fo:block>
<fo:block page-break-before="always"> X </fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
As can be seen there's only a single character on each page.
If I from the above generate a 2 page PDF document it will be 13.01 KB and if I generate a 48 page document it will be 206.56 KB. I would have expected the two PDF document to be almost the same size.
How can I achieve that the logo is re-used and referenced instead of inlined ?
Not using vector graphics is not an option for me.
Apache FOP 2.1, Java 8.
Update
I've found this which is somewhat similar. As far as I can tell the problem in that question is that the contents of the header seems to be inlined on every page (thus ballooning the PDF size), somewhat similar to my problem.
One of the requirements of the repository I'm working on is to have an Advanced Search option from the user interface. Since as of DSpace 4, the Discovery faceted/filtered search & browse is enabled by default as mentioned here, I just put a link in the navigation to point that Advanced Search link to http://myrepository.org/discover. Now my goal is to suppress the search results whenever the user clicked the Advanced Search link.
How can I override the search results such that if there's no query string (eg if the user goes directly to /discover page and no facets were selected), it will only show like in the picture below without the search results and the Now showing items ... and the pagination divs.
I am using DSpace version 5.3 Mirage 2 Theme
This is what I have tried:
<xsl:template match="dri:list[#id='aspect.discovery.SimpleSearch.list.search-results-repository']">
<xsl:variable name="query-string" select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[#element='request'][#qualifier='queryString']"/>
<xsl:if test="$query-string!=''">
<xsl:apply-templates />
</xsl:if>
</xsl:template>
The code above always suppressed the search results whether I have query strings or not.
EDIT
I have a problem with the template match that I used in my answer. The styling of the sort options was removed.
Can someone help me improve my code such that it will not remove the styling of the sort options? The default sort options should look like this:
I wonder why using that template match removed the styling of the sort options. If I use <xsl:apply-templates/>, or <xsl:apply-templates select="."/> instead of <xsl:copy-of select="."/>, it is not returning the result I want to achieve.
Any advice would be greatly appreciated. Thanks in advance.
After many tries of template match, I finally achieved what I want to display. This is the template match that I am using to achieve my goal.
<xsl:template match="dri:div[#id='aspect.discovery.SimpleSearch.div.search-results']">
<xsl:if test="contains(#pageURLMask,'query') or contains(#pageURLMask,'filter')">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
I don't know and not sure if this is fool proof. I've tested this when going directly to /discover page, no search results displayed and I also tried clicking the search button without entering any values in the search form.
There is a slight problem with this answer. Please see my updated post above.
This is the code that resolved my problems regarding the styling of the sort options.
<xsl:template match="dri:div[#id='aspect.discovery.SimpleSearch.div.search-results']">
<xsl:choose>
<xsl:when test="contains(#pageURLMask,'query') or contains(#pageURLMask,'filter')">
<xsl:apply-templates select="dri:div[#id='aspect.discovery.SimpleSearch.div.masked-page-control']/node()"/>
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="no-search-results"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="no-search-results" match="dri:div[#id='aspect.discovery.SimpleSearch.div.masked-page-control']"/>
I have an xslfo code to generate pdfs and I'm using Apache FOP to do that. In each block I'm mentioning the formatting objects such as font family and size.
Can I move it to the top fo:block without degrading the performance?
Current Source:
<fo:block widows="2" orphans="2" font-size="10pt" line-height="1.147" white-space-collapse="false">
<fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" font-family="TimesNewRoman" font-size="11pt" text-align="center">
<fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
<fo:leader leader-length="0pt" />Some Title
</fo:inline>
</fo:block>
<fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" font-family="TimesNewRoman" font-size="11pt" text-align="center">
<fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
<fo:leader leader-length="0pt" />Some Other Title
</fo:inline>
</fo:block>
</fo:block>
Want to change to:
<fo:block widows="2" orphans="2" line-height="1.147" white-space-collapse="false" font-family="TimesNewRoman" font-size="11pt">
<fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" text-align="center">
<fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
<fo:leader leader-length="0pt" />Some Title
</fo:inline>
</fo:block>
<fo:block space-after="8pt" space-after.conditionality="retain" line-height="1.2378041666666666" text-align="center">
<fo:inline font-family="TimesNewRoman" font-weight="bold" font-size="14pt">
<fo:leader leader-length="0pt" />Some Other Title
</fo:inline>
</fo:block>
</fo:block>
Sorry for the bad formatting of the code.
I need to give preference to the speed of generation of the document. Which would be better of the two?
As someone who knows of the internals of (one) of the engines, the answer is a "very, very small" yes. Most engines are creating an internal tree of the formatting results that resolves all the inheritance. In this representation, all of what you have specified either as inherited or totally on each and every element is gone.
Now, that said. In the process of creating this, nodes are created and compared and the XML+XSL to XSL FO transformation takes memory and space for all of those nodes.
So, for example, specifying font-family (as the same font-family) on each and every element will likely be resolved internally in the engine to one font switch in the intermediate format of the engine, but of course it takes time and memory to analyze that and do it.
How much?
Minimal. There is much more time spent in deciding kern of letters, bidi direction, what fits on a line, what to do at page end, what to keep together and much, much more.
My guesstimate. 0.5%. The impact would be more from reading XSL FO files that are larger or creating them in memory if you are using XML+XSL. More memory is all. It can impact performance but very small.
Put tables inside of tables inside of tables and use keeps and continued headers = 20+%. Or choose a huge font like Arial Unicode and ask to one character from it like a single bullet.
I am using docbook as a source for HTML and PDF output. In the docbook source, I have a series of links which are relative (pointing to javadoc files), which is fine for the HTML output because the javadoc files are deployed alongside the original document. For the PDF output, I would like to convert these to absolute links by way of prepending a URL prefix. Is this possible? I have added a 'relative' role to these links and have tried adding a fo customization layer:
<xsl:template match="d:link[#role='relative']">
<xsl:copy>
<xsl:attribute name="xlink:href">
<xsl:value-of select="concat('http://prefix/', #xlink:href)"/>
</xsl:attribute>
</xsl:copy>
<xsl:apply-templates select="d:link"/>
</xsl:template>
This seems to half-work in that it does prepend the prefix to the link href, but then it does not convert the link element into FO.
Any ideas, or other ways this could be done?