PDF layout in JATSParserPlugin

Dear @Vitaliy and others

I have tried the JATSParserPlugin to generate PDF-files on-the-fly from XML. However, I don’t get how I can modify the layout of the PDF:s
Is it some CSS files somewhere?

Can I have different layouts for different journals in a multijournal insallation of OJS?

Hi @eddoff,

PDFs are created with TCPDF library: Examples · TCPDF
I use here HTML to PDF conversion. It supports several CSS attributes: Examples · TCPDF Although it’s probably not a full list, it gives the view that not much is supported. The easiest way would be to catch parsed HTML before it is sent to TCPDF and inject CSS code there. Unfortunately, it can be done only by PHP: php - How to use external css in tcpdf pdf generation - Stack Overflow. HTML for TCPDF is here: https://github.com/Vitaliy-1/JATSParserPlugin/blob/master/JatsParserPlugin.inc.php#L327. So, you’ll need to add a line as per example starting with: $htmlString .= ...
Actually, it’s a good proposal, I’ll consider it’s implementation.

Also, I think it’s possible to write a direct conversion from PHP objects from JATS Parser to TCPDF entities that will give more possibilities for customization (e.g., 2-column layout, another header) but 1) it requires a lot of effort 2) it requires more support.

Dear @Vitaliy,

I have looked at this and made some small modifications in the oldGregg theme. However, I can not find the way to add the DOI-link and publication date to the pdf-file. Is this information available in variables such as $articleArrays and $templateMgr in OldGreggThemePlugin.inc.php, and how can in find out the content of these arrays?

Best regards,

@eddoff

In the next Old Gregg release JATS Parser library will be decoupled from the theme, thus I suggest to work with JATS Parser plugin directly. Note, in near future all themes would be able to show article’s fulltext on the article landing page through JATS Parser, not only Old Gregg.

The method responsible for PDF creation is here: https://github.com/Vitaliy-1/JATSParserPlugin/blob/master/JatsParserPlugin.inc.php#L364
The body is formed from HTML document, so if you want to add anything there you need to inject it in PHP DOM here and it’s called here. The easiest way would probably be passing PublishedArticle object through that method.

If the idea is to inject DOI into header or footer, the best would be check TCPDF documentation.

The latter is the instance of PKPTemplateManager, which in turn is a child of Smarty and inherits all its methods. The former is the instance of PublishedArticle object, I have no idea why I called it that way :slight_smile: Anyway, there is a correspondent annotation. You can look at available methods in this class and it’s parent (Article) and grandparent (Submisison).

Let me know if you stuck on something specific. In general, I’d like to add methods that can make adding custom code and CSS into the TCPDF easier. I’d be grateful for the contribution.

1 Like

Thank you!

I will look into this and try to insert the DOI.
We have tested oldGregg with images in various sizes. JATSparser scale all images in the PDF:s to paper width if they are large enough. However, if they are smaller it looks nice in the pdf and on the website, but the scaling of the image is incorrect in the HTML version when maximizing the image. see for example the second image in the end of this test article:
https://journal.ep.liu.se/test/index.php/atena/article/view/291
![image|690x197]

Thanks for reporting. Yes, I know this bug and it’s something that I plan to change in the new release.
Just want to add that the new version of Old Gregg theme would be much different. I’m making new design for it but the functionality would be much the same, plus there would be new features. E.g., yesterday I finally added the back-end support for most viewed articles. Although it will take some time but I believe the results will worth it.

If you are planning to make changes in the theme (not the JATS Parser Plugin), e.g., creating a child theme, I suggest to wait until new release.

1 Like

Hi @Vitaliy ,

I’ve seen that your JATSParserPlugin code imports CSS files from resources/styles/jatsParser.css and resources/styles/default/pdfGalley.css to style the PDF galley.

Wouldn’t it possible to provide a CSS upload option (similar to OJS Website > Advanced > Journal Style Sheet upload) in the plugin settings? The uploaded CSS would then overwrite the default CSS provided by the plugin. In addition, this would offer individual galley styling per journal, which is a requirement in a multi-journal hosting.

Another option would be to read a separate CSS file that is located within the theme used by the journal.

Of course this requires a proper documentation of the CSS classes that are used in the TCPDF conversion.

I can discuss with my team if I can offer some support.

Yes, I was considering this. I also was thinking about moving to something like mPDF with better CSS support but haven’t experimented yet. In TCPDF, the support for something more complex than, say, changing the background colour, like 2-column layout, is only on PHP side and is non-trivial task. mPDF looks better, as minimum if looking at the documentation.

I think the easiest way would be to add possibility for uploading a stylesheet through the plugin settings. I’ll take a look

Hello Vitaliy,

We are currently in the process of integrating Texture + JatsParser into our journal. So far, the plugins have been performing well and delivering excellent results. We do, however, have a specific question regarding customizing the PDF output.

In a previous chat, you mentioned the possibility of updating the library that the plugin calls or making modifications to the PHP code to incorporate a CSS. We’re prepared to undertake some programming on our end to achieve this customization. However, we believe that coordinating our efforts with you would be beneficial in order to align with your plans for the plugin’s development.

We appreciate your expertise and guidance on this matter. Thank you in advance for your response.

Best regards,
Sergio Santamarina
Librarian, University of José C. Paz, Argentina

Hi @Sergio_Javier_Santam,

Glad that you’re finding the plugin useful. I can confirm that still believe that among PHP based libraries mPDF is a good fit that should produce quite customisable results but I haven’t worked in that direction. As a start I would try just to replace the content of the main PDF parsing method to use mPDF: https://github.com/Vitaliy-1/JATSParserPlugin/blob/922f217d8f3368cbff102765137786a77dbb0a19/JatsParserPlugin.inc.php#L116. It also supports HTML to PDF conversion.

Have you already looked at the mPDF’s documentation and CSS selectors it supports? I see also the possibility for further output customisation through PHP with this library, e.g., support for 2 column page layout.