-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Print page support in Java (#8991)
- Loading branch information
Showing
16 changed files
with
545 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium; | ||
|
||
public class Pdf { | ||
|
||
private final String base64EncodedPdf; | ||
|
||
public Pdf(String base64EncodedPdf) { | ||
this.base64EncodedPdf = base64EncodedPdf; | ||
} | ||
|
||
public String getContent() { | ||
return base64EncodedPdf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
package org.openqa.selenium; | ||
|
||
import org.openqa.selenium.print.PrintOptions; | ||
|
||
public interface PrintsPage { | ||
Pdf print(PrintOptions printOptions) throws WebDriverException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.print; | ||
|
||
import org.openqa.selenium.internal.Require; | ||
|
||
public class PageMargin { | ||
private double top; | ||
private double bottom; | ||
private double left; | ||
private double right; | ||
|
||
public PageMargin() { | ||
this.top = 1.0; | ||
this.bottom = 1.0; | ||
this.left = 1.0; | ||
this.right = 1.0; | ||
} | ||
|
||
public double getTop() { | ||
return top; | ||
} | ||
|
||
public void setTop(double top) { | ||
this.top = Require.positive("top", top); | ||
} | ||
|
||
public double getBottom() { | ||
return bottom; | ||
} | ||
|
||
public void setBottom(double bottom) { | ||
this.bottom = Require.positive("bottom", bottom); | ||
} | ||
|
||
public double getLeft() { | ||
return left; | ||
} | ||
|
||
public void setLeft(double left) { | ||
this.left = Require.positive("left", left); | ||
} | ||
|
||
public double getRight() { | ||
return right; | ||
} | ||
|
||
public void setRight(double right) { | ||
this.right = Require.positive("right", right); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.print; | ||
|
||
|
||
import org.openqa.selenium.internal.Require; | ||
|
||
public class PageSize { | ||
|
||
private double height; | ||
private double width; | ||
|
||
public PageSize() { | ||
// Initialize with defaults. A4 paper size defaults in cms. | ||
this.height = 21.59; | ||
this.width = 27.94; | ||
} | ||
public double getHeight() { | ||
return height; | ||
} | ||
|
||
public double getWidth() { | ||
return width; | ||
} | ||
|
||
public void setHeight(double height) { | ||
this.height = Require.positive("height", height); | ||
} | ||
|
||
public void setWidth(double width) { | ||
this.width = Require.positive("width", width); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
java/client/src/org/openqa/selenium/print/PrintOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.openqa.selenium.print; | ||
|
||
import org.openqa.selenium.internal.Require; | ||
|
||
public class PrintOptions { | ||
|
||
public enum Orientation { | ||
Portrait, | ||
Landscape | ||
} | ||
private Orientation orientation = Orientation.Portrait; | ||
private double scale = 1.0; | ||
private boolean background = false; | ||
private boolean shrinkToFit = true; | ||
private PageSize pageSize = new PageSize(); | ||
private PageMargin pageMargin = new PageMargin(); | ||
private String[] pageRanges; | ||
|
||
public Orientation getOrientation() { | ||
return this.orientation; | ||
} | ||
|
||
public void setOrientation(Orientation orientation) { | ||
this.orientation = Require.nonNull("orientation", orientation); | ||
} | ||
|
||
public String[] getPageRanges() { | ||
return this.pageRanges; | ||
} | ||
|
||
public void setPageRanges(String firstRange, String ... ranges) { | ||
Require.nonNull("pageRanges", firstRange); | ||
this.pageRanges = new String[ranges.length + 1]; // Need to add all ranges and the initial range too. | ||
|
||
this.pageRanges[0] = firstRange; | ||
|
||
for (int i = 1; i < ranges.length; i++) { | ||
this.pageRanges[i] = ranges[i - 1]; | ||
} | ||
} | ||
|
||
public void setBackground(boolean background) { | ||
this.background = Require.nonNull("background", background); | ||
} | ||
|
||
public boolean getBackground() { | ||
return this.background; | ||
} | ||
|
||
public void setScale(double scale) { | ||
if (scale < 0.1 || scale > 2) { | ||
throw new IllegalArgumentException("Scale value should be between 0.1 and 2"); | ||
} | ||
this.scale = scale; | ||
} | ||
|
||
public double getScale() { | ||
return this.scale; | ||
} | ||
|
||
public boolean getShrinkToFit() { | ||
return this.shrinkToFit; | ||
} | ||
|
||
public void setShrinkToFit(boolean value) { | ||
this.shrinkToFit = Require.nonNull("value", value); | ||
} | ||
|
||
public void setPageSize(PageSize pageSize) { | ||
this.pageSize = Require.nonNull("pageSize", pageSize); | ||
} | ||
|
||
public void setPageMargin(PageMargin margin) { | ||
this.pageMargin = Require.nonNull("margin", margin); | ||
} | ||
|
||
public PageSize getPageSize() { | ||
return this.pageSize; | ||
} | ||
|
||
public PageMargin getPageMargin() { | ||
return this.pageMargin; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.