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.
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 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 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).
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?
I'm trying to create a simple XAMLfile with a Page that contains a Canvas that contains a Rectangle.
I have a template draw-canvas that makes the canvas. In this canvas I want to put a Rectangle, for which I have a template draw-rectangle.
My main currently looks like this:
<xsl:template match="/">
<xsl:element name="Page">
<xsl:call-template name="draw-canvas">
<xsl:with-param name="start-color">red</xsl:with-param>
<xsl:with-param name="end-color">ivory</xsl:with-param>
</xsl:call-template>
</xsl:element>
</xsl:template>
To get the Rectangle in the canvas I call the draw-rectangle method in the draw-canvas template. Is this the only way to do this? I feel like this doesn't really allow for flexibility.