Pdf

javascript-pdf
Articles
https://helpx.adobe.com/acrobat/using/optimizing-pdfs-acrobat-pro.html

What software can I use to sign a PDF on Linux Mint?

sudo apt install xournal

How can we edit or apply our signature to a PDF document using Preview on Mac?

See Preview

How can we use Chrome and PDF Viewer to obtain the URL for a link inside a PDF?

  1. Launch Chrome and go to https://chrome.google.com/webstore/detail/pdf-viewer/oemmndcbldboiebfnladdacbdfmadadm/related
  2. Click on the button to install PDF Viewer
  3. After PDF Viewer is installed, we should see a new icon appeared in the Chrome toolbar
  4. Right click on this icon and give this extension appropriate privileges
  5. Open any PDF (for example, http://example.com/example.pdf).
  6. Notice that the URL in the address bar is changed to chrome-extension:…
  7. Notice that an extra toolbar is displayed. It contains the print icon, and the download icon. If this toolbar is not displayed, we may need to click on the icon in the top toolbar, and adjust various privileges and settings, etc.
  8. With PDF Viewer, when we put our mouse over a link inside a PDF, the status bar show the URL. We can also right click on the link and select "Copy link address". We can also inspect the link.

When we use PDF Viewer to copy the link address, we can paste that URL into Chrome, and it will go to the right place. However, this does not work for IE. For IE, we have to replace %3A with colon (:)

If the PDF does not have a table of links at the top, click on the icon on the far left that says "Toggle Sidebar", then click on the second icon (Show Document Outline). We can then right click on the appropriate link, and select "Copy link address". Unfortunately, the copied URL is cryptic, and does not work for IE. We have to click on the link, and then click on the icon that look like a bookmark icon (Current view). This will change the URL in the address bar. Take note of the page number mentioned in the URL in the address bar. Instead of using the hash such as #race, I switch to using #page=486 and it works for IE.

If we have Adobe Reader DC installed (on Windows machine), we can install Adobe Writer (with a temporary license):

  1. Launch Adobe Reader DC
  2. Open any PDF with Adobe Reader DC
  3. Click on the Edit menu (in the top menu) and click on "Edit Text & Images" (this will launch a browser window where we can download and install a free trial for 7 days). Unfortunately, it will ask you for a credit card number.

View -> Show / Hide -> Navigation Panes ->

In the view where we display a list of bookmarks / links, we can click or double-click on the link to edit the tag. Make sure that the right side is at the right location within the PDF, and then we can right click on the tag in the left and select "Set Position".

Maybe we should read the below two links:

Which libraries can we use on the server side to generate PDF files?

  1. Apache FOP
import java.io.ByteArrayOutputStream;
import java.io.StringReader;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.fop.apps.Driver;

public class GeneratePDF {

    public static ByteArrayOutputStream createPDF(String xml, String xslfilename) throws Exception {
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        try {
            Driver driver = new Driver();
            driver.setRenderer(Driver.RENDER_PDF);

            driver.setOutputStream(out);
            TransformerFactory tf = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);
            Transformer transformer = tf.newTransformer(Globals.splusInfo.getResourceAsStreamSource("\\qrrm\\xsl\\" + xslfilename));

            Result result = new SAXResult(driver.getContentHandler());

            Source src = new StreamSource(new StringReader(xml));
            transformer.transform(src, result);

        } catch(Exception e) {
            Globals.debugger.error("GeneratePDF", "createPDF", e);
            throw new Exception(e);
        }
        return out;
    }
}

Example of the XSL file:

<?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">
    <xsl:output method="xml" indent="yes" />
    <xsl:variable name="bgcolor">#FFFFFF</xsl:variable>
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="A4-landscape"
                    page-height="21.0cm" page-width="29.7cm" margin="2cm">
                    <fo:region-body />
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="A4-landscape">
                <fo:flow flow-name="xsl-region-body">
                    <xsl:apply-templates select="report/header" />
                    <xsl:apply-templates select="report/parameters" />                    
                    <xsl:apply-templates select="report/table" />
                    <xsl:apply-templates select="report/footer" />
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template match="report/header">
        <fo:block font-size="17pt" space-after="13pt">
            <xsl:value-of select="name" />
        </fo:block>
    </xsl:template>

    <xsl:template match="report/parameters">
        <xsl:for-each select="*">
            <fo:block space-before="2pt">
                <xsl:value-of select="." />                
            </fo:block>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="report/footer">
        <xsl:for-each select="*">
            <fo:block space-before="2pt">
                <fo:inline font-size="9pt">
                <xsl:value-of select="." />
                </fo:inline>
            </fo:block>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="report/table">
        <fo:table width="100%" border="0.5pt solid black"
            space-before="5pt">

            <xsl:apply-templates select="columns" />

            <fo:table-body>
                <xsl:apply-templates select="rows" />
            </fo:table-body>

        </fo:table>
    </xsl:template>

    <xsl:template match="columns">
            <!--     DE26875: DEV (ACC) (DMR) - Billing ID and MRN cannot show fully in exported PDF file -->
            <fo:table-column column-number="1" column-width="30pt" />
            <fo:table-column column-number="2" column-width="proportional-column-width(1)" />
            <fo:table-column column-number="3" column-width="proportional-column-width(1)" />
            <fo:table-column column-number="4" column-width="proportional-column-width(1)" />
            <fo:table-column column-number="5" column-width="37pt" />
            <fo:table-column column-number="6" column-width="proportional-column-width(1)" />
            <fo:table-column column-number="7" column-width="37pt" />
            <fo:table-column column-number="8" column-width="45pt" />
            <fo:table-column column-number="9" column-width="45pt" />
            <fo:table-column column-number="10" column-width="37pt" />
            <fo:table-column column-number="11" column-width="37pt" />
            <fo:table-column column-number="12" column-width="37pt" />
            <fo:table-column column-number="13" column-width="37pt" />

        <fo:table-header>
            <fo:table-row>
                <xsl:for-each select="column">
                    <fo:table-cell border="0.5pt solid black"
                        background-color="#CCCCCC" width="auto">
                        <fo:block font-weight="bold" margin-left="2pt"
                            margin-right="2pt" space-before="5mm" space-after="5mm">
                            <fo:inline font-size="6pt">
                                <xsl:value-of select="." />
                            </fo:inline>
                        </fo:block>
                    </fo:table-cell>
                </xsl:for-each>
            </fo:table-row>
        </fo:table-header>

    </xsl:template>

    <xsl:template match="rows">
        <xsl:for-each select="row">
            <xsl:variable name="bgcolor">#FFFFFF</xsl:variable>
            <fo:table-row>
                <xsl:for-each select="*">
                    <fo:table-cell border="0.5pt solid black"
                        background-color="{$bgcolor}">
                        <fo:block font-size="6pt" margin-left="2pt"
                            margin-right="2pt">
                            <xsl:value-of select="." />
                        </fo:block>
                    </fo:table-cell>
                </xsl:for-each>
            </fo:table-row>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License