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
Related
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.
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 have a large PDF and I need to show it 50% reduced in size inside a div tag that is 600px 600px in size. I also need to offer the client a zoom function.
Should I use the "object" tag? But can I reduce the pdf size inside an "object"?
Is there a jquery example or anything out there?
Need help.
<div>
<object data="febrero2012.pdf" type="application/pdf" width="600px" height="600px">
alt : febrero2012.pdf
</object>
</div >
I coudn't find the way to set a default zoom level yet. If you find a way, please let me know.
No. PDFs cannot be displayed in a DIV, as they're not html or an image. You can convert the PDF to html/images on the server and display that, just like google's "quick view" function does. But in general, PDF rendering in-browser is dependent on the presence of a plugin (e.g. Adobe Reader, Chrome's built-in rendering engine notwithstanding). Plugins can't be displayed in divs, just embed/object/iframe sections.
I'm creating PDFs on-demand with ColdFusion's CFDocument tag, like so:
<cfdocument format="PDF" filename="#attributes.fileName#" overwrite="true">
<cfdocumentitem type="footer">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left"><font face="Tahoma" color="black"><strong>My Client's Corporation</strong><br/>Street address<br/>City, ST 55555</font></td>
<td align="right"><font face="Tahoma" color="black">Phone: 555.555.5555<br/>Fax: 555.555.5555<br/>Email: info#domain.com</font></td>
</tr>
</table>
</cfdocumentitem>
<html>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<!--- some content here ... --->
</table>
</body>
</html>
</cfdocument>
The problem I'm having is that sometimes (actually, most of the time, but not always) some of the footer text is there, but invisible. I can highlight it and copy/paste it into notepad, where I can see it all -- but in the generated PDF only the first line of the left column of the footer is visible, the rest is invisible. Hence why I added the font color of black in the code.
Any ideas on how to correct this?
A PDF is what I'm after, so I'm not sure how outputting another format would help.
As it turns out, the footer space just wasn't enough to fit all of this text; verified by the fact that changing the font size to 4pt would fit it all in without a problem.
I spent some time attempting to rewrite the footer code using DDX as outlined here and the CFPDF tag to implement it; but even after several hours of hacking away and finally getting a valid DDX as reported by the new isDDX function, the CFPDF tag reported that it was invalid DDX for some reason.
At this point I decided I had wasted enough of the client's time/money and just reformatted the footer to be 2 lines of centered text, which was good enough.
Usually when PDF shows blank text, it's because the font metrics are embedded in the document, but the glyphs are not. I know nothing about ColdFusion, but you might try the following:
Try a font other than Tahoma as a test. All PDF readers must support 14 basic fonts, including 4 Helvetica variants, 4 Times variants, 4 Courier variants, Symbol and ZapfDingbats, so those are always safe choices
See if ColdFusion offers any control over font embedding
Try a list of alternatives in your font declaration, like "Tahoma,Helvetica,sans-serif"