Skip to content

Commit

Permalink
Fixed page origin in PDF files (resolves #72).
Browse files Browse the repository at this point in the history
  • Loading branch information
eseifert committed Nov 15, 2019
1 parent 3ffa0a6 commit 5f8b9a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,22 @@ private Stream initPage() {

// Initial content
try {
double scaleH = MM_IN_UNITS;
double scaleV = -MM_IN_UNITS;

PageSize pageSize = getPageSize();
double translateX = -pageSize.getX()*MM_IN_UNITS;
double translateY = (pageSize.getY() + pageSize.getHeight())*MM_IN_UNITS;

FormattingWriter string = new FormattingWriter(contents, CHARSET, EOL);
string.writeln("q");
string.writeln(getOutput(getCurrentState().getColor()));
string.write(MM_IN_UNITS).write(" 0 0 ").write(-MM_IN_UNITS)
.write(" 0 ").write(getPageSize().getHeight()*MM_IN_UNITS)
.writeln(" cm");
string.write(scaleH).write(" ")
.write(0.0).write(" ")
.write(0.0).write(" ")
.write(scaleV).write(" ")
.write(translateX).write(" ")
.write(translateY).writeln(" cm");
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -214,8 +224,8 @@ private PDFObject addPageTree(DefaultPDFObject catalog, List<PDFObject> pages) {
}

private DefaultPDFObject addPage(PDFObject pageTree) {
double x = getPageSize().getX()*MM_IN_UNITS;
double y = getPageSize().getY()*MM_IN_UNITS;
double x = 0.0;
double y = 0.0;
double width = getPageSize().getWidth()*MM_IN_UNITS;
double height = getPageSize().getHeight()*MM_IN_UNITS;
Map<String, Object> dict = DataUtils.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ private String process(Command<?>... commands) throws IOException {
"<<",
"/Type /Page",
"/Parent 2 0 R",
"/MediaBox [0 28.34645669291339 56.69291338582678 85.03937007874016]",
"/MediaBox [0 0 56.69291338582678 85.03937007874016]",
"/Contents 4 0 R",
"/Resources 5 0 R",
">>",
"endobj",
"4 0 obj",
"<<",
"/Length 97",
"/Length 99",
">>",
"stream",
"q",
"1 1 1 rg 1 1 1 RG",
"2.834645669291339 0 0 -2.834645669291339 0 85.03937007874016 cm",
"2.834645669291339 0 0 -2.834645669291339 -0 113.38582677165356 cm",
"/Fnt0 12 Tf",
"Q",
"endstream",
Expand Down

0 comments on commit 5f8b9a1

Please sign in to comment.