Link between different Sections in same PDF - java

We are creating a PDF document consisting of different sections generated separately and then added in single document. Now we need to provide a hyperlink to navigate the user to a point in different section.
We are using iText 7.0.5 and have tried using Link and Link Annotations, but no use. The mapping works for the same section but not between different sections.

Your use case: Merge pdfs and provide a mean of navigating in the resultant document.
How to do it?: Please look at the next iText sample: https://github.com/itext/i7js-examples/blob/develop/src/test/java/com/itextpdf/samples/sandbox/merge/MergeWithToc.java
In that sample some pdfs are merged and then a table of contents is created, so that one can click on its items and be navigated to the appropriate page.
In order to do so, it's suggested to set a named destination on some of elements of your "sections:
// Put the destination at the very first page of each merged document
if (i == 1) {
text.setDestination("p" + pageNo);
}
doc.add(new Paragraph(text).setFixedPosition(pageNo, 549, 810, 40).setMargin(0).setMultipliedLeading(1));
and then to set an action on an appropriate TOC element:
p.setAction(PdfAction.createGoTo("p" + entry.getKey()));
Perhaphs the same logic can be applied in your case as well.

Related

Different headers when printing

I need to export multiple HTML files into a single PDF one.
I'm using #page rules to apply a header.
I need to :
Display the pagecount ( page n out of total)
Display a different title in the header for each original HTML document
What I tried :
Exporting each HTML separately:
I get the good title but the pagecount is relative to the current HTML, not the global total.
Using jsoup to gather every HTML in one document before exporting:
I get the good pagecount but can't select which title to apply in the print header
I know about #page:first and #page:last but would like to be able to apply different styles for every page in between.
I found a solution !
You can specify some content to be on a named page :
#page A { #top-left { content:"..." } }
div-A { page: A; }
<div-A>
Content that has a specific header
</div-A>
Don't forget to apply some rules like "page-break-after: always"

How to add non title element to the asciidoctor's table of content

I have a java/gradle project documented with Asciidoctor that generates a table of context based on the title sections of your document. For example:
== Get started
Will be added on the table of content perfectly but a regular text won't, for example:
== Get started
Introduction
Will generate a TOC with only "get started" and I'd like a TOC like this one:
get started
-Introduction
How can I add a regular text to the table of content?
If you are using the built-in TOC generation, i.e. you are using :toc: in the document (or -a toc on the command line), only section titles are included in the TOC. For more details, see: https://asciidoctor.org/docs/user-manual/#user-toc
So, to include "plain text" in to the TOC, you would have to make the plain text into a section title.
If you are not using the built-in TOC generation, you can compose a list with any content you like. If you need your hand-assembled TOC to look just like the built-in TOC, you would need to add some CSS styles to do so, which requires a "docinfo" that lets you customize the generated HTML. See https://asciidoctor.org/docs/user-manual/#docinfo-file.

How to select items from drop down menu using Selenium?

I have been trying to automate a search using Selenium. I simply want to search terms (say Pink Floyd) but the file type should be pdf. Here is what I have done so far:
//Query term
WebElement element = driver.findElement(By.name("as_q"));
String finalQuery = "pink floyd";
element.sendKeys(finalQuery);
//File type selection
WebElement elem = driver.findElement(By.id("as_filetype_button"));
elem.sendKeys("Adobe Acrobat pdf (.pdf)");
driver.findElement(By.xpath("/html/body/div[1]/div[4]/form/div[5]/div[9]/div[2]/input[#type='submit']")).click();
This puts the term in the appropriate place and the drop down for file types are expanded but pdf option is not selected. Any help?
I am using Selenium 2.53.0.
EDIT
The following code segment perfectly worked as per the accepted answer for this question. However, all on a sudden the code segment is not working. I am a bit surprised to find this out. Previously, I was able to select PDF automatically with the following code segment but now, nothing gets selected.
WebElement element = driver.findElement(By.name("as_q"));
String finalQuery = "pink floyd";
element.sendKeys(finalQuery);
driver.findElement(By.id("as_filetype_button")).click();
driver.findElement(By.xpath("//li[#class=class-name][#value='pdf']")).click();
This is how i do it, find the li that matches the class='goog-menuitem' and value='pdf', i inspected the element. You can go directly with value='pdf' but just to make sure we are looking at the file type dropdown we added the class.
driver.findElement(By.id("as_filetype_button")).click();
driver.findElement(By.xpath("//li[#class='goog-menuitem'][#value='pdf']")).click();
You can still declare it with WebElement, i just prefer it shorthand. Hope this helps.

Page orientation in Aspose

I am using aspose-words-15.6.0 api for java. I want to change the page orientation to portrait or landscape based on the page number.
Scenario:
I've a doc having 3 pages in it, I want page orientation as follow:
1st Page : Portrait.
2nd Page : Landscape.
3rd Page : Portrait.
EDIT:
I have tried with DocumentBuilder, there is a way to achieve this but I am missing something, please refer the screenshot I've attached with this question.
Any help would be greatly appreciated.
There is no concept of Page in MS Word documents. Pages are created by Microsoft Word on the fly and unfortunately there is no straight forward way that you can use to set orientation per Page. However, you can specify orientation settings for a whole Section using Section.PageSetup.Orientation property and a Section may contain more than just one Page.
Alternatively, you may be able create a separate Section for each page in word document using Aspose.Words and then specify page orientation for each Section corresponding to a particular page. Please report this requirement in Aspose.Words forum, we will then develop code for this requirement and provide you more information.
EDIT:
If you want to build document from scratch, please use the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Content on first page");
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.writeln("Content on second page");
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.writeln("Content on third page");
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
doc.save(getMyDir() + "15.10.0.docx");
I work with Aspose as Developer Evangelist.

How to jump to specific page number using display tag in Spring framework

I want to jump to a specific page number using display tag with a textbox and a "go" button.
On the click of GO button calls a javascript in which it should go to that specific page through that .htm which is not happening.
please suggest an argument for this particular way of getting a specific page or else alternate suggestions are always welcome
Below are the arguments in displaytag.properties which i know so far
enter code here
{0}: numbered pages list
{1}: link to the first page
{2}: link to the previous page
{3}: link to the next page
{4}: link to the last page
{5}: current page
{6}: total number of pages
Below is the javascript function which is being called on click of GO button
function selectPage(){
alert("pageNo:" +document.portalDisplayform.selPageNo[0].value);
alert("pageNo:" +document.portalDisplayform.selPageNo[1].value);
var pageNo = document.portalDisplayform.selPageNo[0].value;
var pageNo = document.portalDisplayform.selPageNo[1].value;
document.portalDisplayform.action = '<%=request.getContextPath()% >'+"/portalAccessdisplay.htm?tokenId="+'<%=cachetoken%>'+pageNo;
document.portalDisplayform.submit();
}
It's not so easy, because the displaytag encodes parameters (to avoid naming conflicts with functional parameters), and uses a unique ID per table, in case several tables are on the same page. I suggest you download the source code of displaytag, have a look at the ParamEncoder and Pagination classes (and their callers) to discover how a link to a specific page is constructed by the displaytag. You'll have to use similar code to generate the URL, and you'll have to modify the value of the appropriate (encoded) parameter in your JavaScript code.
The very easiest way, you can modify the TableTag.java which is in the display-tag jar file. In this file modify the initParameters() method. Inside the method
place the below 4 line code.
After this line which is in initParameters() method.
this.pageNumber = (pageNumberParameter == null) ? 1 : pageNumberParameter.intValue();
Place the below code
if((request.getParameter("pageno") != null) && (request.getParameter("pageno") != ""))
{
this.pageNumber=Integer.parseInt(request.getParameter("pageno"))
}
And use a TextBox with the name pageno in your DisplayTag page. Also include the name in your DisplayTag property excludedparam.

Categories