Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#80 Fix and sample multihtmldoc pdf #222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public static void main(String[] args) throws Exception {
*/
runTestCase("transform");

runTestCase("simplerotate");

runTestCase("quoting");

runTestCase("math-ml");
Expand Down Expand Up @@ -190,7 +192,7 @@ private static void renderPDF(String html, OutputStream outputStream) throws Exc
}
}

private static DefaultObjectDrawerFactory buildObjectDrawerFactory() {
static DefaultObjectDrawerFactory buildObjectDrawerFactory() {
DefaultObjectDrawerFactory objectDrawerFactory = new StandardObjectDrawerFactory();
objectDrawerFactory.registerDrawer("custom/binary-tree", new SampleObjectDrawerBinaryTree());
return objectDrawerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<html xmlns="http://www.w3.org/1999/html">
<head>
<bookmarks>
<bookmark href="#werkstattAnschrift" name="In document Bookmark 1"/>
<bookmark href="#table_to_bookmark" name="table_to_bookmark"/>
<bookmark name="OpenHTMLToPDF">
<bookmark href="https://github.com/danfickle/openhtmltopdf" name="Github Homepage"/>
<bookmark href="https://github.com/danfickle/openhtmltopdf/issues/80" name="An random issue"/>
</bookmark>
</bookmarks>
<!--suppress CssUnknownProperty -->
<style>

Expand Down Expand Up @@ -280,7 +288,7 @@ <h1>Lorum ipsum .... XYZ........ZYX, SOMENUMBERS......</h1>
<br/>


<table class="framed_table framed_cells" cellspacing="0" cellpadding="0">
<table class="framed_table framed_cells" cellspacing="0" cellpadding="0" id="table_to_bookmark">
<tr class="table_repeat_header">
<td colspan="9">XYZABCDEFGZX</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<style>@page {size: 520px 820px;margin: 0px;padding: 0px;}body {margin: 0;}</style>
</head>
<body>
<div style="left:0px;top:0px;width:50px;transform: rotate(50deg);">
asdasdasd
</div>
</body>
</html>
29 changes: 21 additions & 8 deletions openhtmltopdf-examples/src/main/resources/testcases/svg-sizes.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
<html>
<head>
<bookmarks>
<bookmark name="Text" href="#text"></bookmark>
<bookmark name="SVG" href="#svg">
<bookmark name="Width 25%" href="#w25"/>
<bookmark name="Width 10%" href="#w10"/>
<bookmark name="Width 8cm" href="#w8"/>
<bookmark name="Width 4cm" href="#w4"/>
<bookmark name="Height 50%" href="#h50"/>
<bookmark name="Height 4cm" href="#h4"/>
</bookmark>
</bookmarks>
</head>
<body>

<h2>Text</h2>
<h2 id="text">Text</h2>
<div style="width: 25%; border: 1px solid black;">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Donec venenatis velit enim, a placerat lectus viverra non.
Proin varius porta ligula, in fringilla erat suscipit a.</p>
</div>
<h2>SVG</h2>
<h2 id="SVG">SVG</h2>

<h3>width: percentage, max-width: none, calc-width: 25%</h3>
<h3 id="w25">width: percentage, max-width: none, calc-width: 25%</h3>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 20"
style="width: 25%; border: black 1px solid;">
<rect x="1" y="1" rx="5" ry="5" width="28" height="18"
stroke="blue" fill="yellow" stroke-width="2" />
</svg>

<h3>width: percentage, max-width: absolute, calc-width: 8cm</h3>
<h3 id="w8">width: percentage, max-width: absolute, calc-width: 8cm</h3>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 20"
style="width: 80%; max-width: 8cm; border: black 1px solid;">
<rect x="1" y="1" rx="5" ry="5" width="28" height="18"
stroke="blue" fill="yellow" stroke-width="2" />
</svg>

<h3>width: absolute, max-width: percentage, calc-width: 10%</h3>
<h3 id="#w10">width: absolute, max-width: percentage, calc-width: 10%</h3>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 20"
style="width: 500px; max-width: 10%; border: black 1px solid;">
Expand All @@ -34,15 +47,15 @@ <h3>width: absolute, max-width: percentage, calc-width: 10%</h3>
</svg>


<h3>height: absolute, max-height: none, calc-height: 4cm</h3>
<h3 id="w4">height: absolute, max-height: none, calc-height: 4cm</h3>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 20" width="300" height="200"
style="height: 4cm; border: black 1px solid;">
<rect x="1" y="1" rx="5" ry="5" width="28" height="18"
stroke="blue" fill="yellow" stroke-width="2" />
</svg>

<h3>height: absolute, max-height: percentage, calc-height: 2.5cm (50% of containing block)</h3>
<h3 id="h50">height: absolute, max-height: percentage, calc-height: 2.5cm (50% of containing block)</h3>

<div style="height: 5cm; border: 1px solid red;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 20" width="300" height="200"
Expand All @@ -52,7 +65,7 @@ <h3>height: absolute, max-height: percentage, calc-height: 2.5cm (50% of contain
</svg>
</div>

<h3>height: absolute, max-height: absolute, calc-height: 4cm</h3>
<h3 id="h4">height: absolute, max-height: absolute, calc-height: 4cm</h3>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 20" width="300" height="200"
style="height: 45cm; max-height: 4cm; border: black 1px solid;">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.openhtmltopdf.testcases;

import static com.openhtmltopdf.testcases.TestcaseRunner.buildObjectDrawerFactory;

import java.io.File;

import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.Charsets;
import org.junit.Test;

import com.openhtmltopdf.bidi.support.ICUBidiReorderer;
import com.openhtmltopdf.bidi.support.ICUBidiSplitter;
import com.openhtmltopdf.latexsupport.LaTeXDOMMutator;
import com.openhtmltopdf.mathmlsupport.MathMLDrawer;
import com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder;
import com.openhtmltopdf.pdfboxout.PdfBoxRenderer;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
import com.openhtmltopdf.svgsupport.BatikSVGDrawer;

public class ConcateOutputTest {

@Test
public void testConcateOutput() throws Exception {
File targetFile = new File("target/test/concatoutput/concated.pdf");
targetFile.getParentFile().mkdirs();
PDDocument doc = new PDDocument(MemoryUsageSetting.setupMixed(1000000));

for (String testCaseFile : new String[] { "color", "background-color",
"FSPageBreakMinHeightSample", "math-ml", "multi-column-layout", "simplerotate",
"svg-inline", "svg-sizes", "transform", "RepeatedTableSample",
"RepeatedTableTransformSample" }) {
renderPDF(testCaseFile, doc);
}

doc.save(targetFile);
doc.close();

}

private static void renderPDF(String testCaseFile, PDDocument document) throws Exception {
byte[] htmlBytes = IOUtils
.toByteArray(TestcaseRunner.class.getResourceAsStream("/testcases/" + testCaseFile + ".html"));
String html = new String(htmlBytes, Charsets.UTF_8);
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useUnicodeBidiSplitter(new ICUBidiSplitter.ICUBidiSplitterFactory());
builder.useUnicodeBidiReorderer(new ICUBidiReorderer());
builder.defaultTextDirection(BaseRendererBuilder.TextDirection.LTR);
builder.useSVGDrawer(new BatikSVGDrawer());
builder.useMathMLDrawer(new MathMLDrawer());
builder.addDOMMutator(LaTeXDOMMutator.INSTANCE);
builder.useObjectDrawerFactory(buildObjectDrawerFactory());
builder.withHtmlContent(html, TestcaseRunner.class.getResource("/testcases/").toString());
builder.usePDDocument(document);
PdfBoxRenderer pdfBoxRenderer = builder.buildPdfRenderer();
pdfBoxRenderer.createPDFWithoutClosing();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,11 @@ private void writeOutline(RenderingContext c, Box root) {
if (_bookmarks.size() > 0) {
// TODO: .setViewerPreferences(PdfWriter.PageModeUseOutlines);

PDDocumentOutline outline = new PDDocumentOutline();
_writer.getDocumentCatalog().setDocumentOutline( outline );
PDDocumentOutline outline = _writer.getDocumentCatalog().getDocumentOutline();
if (outline == null) {
outline = new PDDocumentOutline();
_writer.getDocumentCatalog().setDocumentOutline(outline);
}

writeBookmarks(c, root, outline, _bookmarks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class PdfBoxRenderer implements Closeable {
_useFastMode = state._useFastRenderer;
_outputDevice = new PdfBoxOutputDevice(DEFAULT_DOTS_PER_POINT, _testMode);
_outputDevice.setWriter(_pdfDoc);
_outputDevice.setStartPageNo(_pdfDoc.getNumberOfPages());

PdfBoxUserAgent userAgent = new PdfBoxUserAgent(_outputDevice);

Expand Down