本文整理汇总了Java中com.itextpdf.text.pdf.PdfGState类的典型用法代码示例。如果您正苦于以下问题:Java PdfGState类的具体用法?Java PdfGState怎么用?Java PdfGState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfGState类属于com.itextpdf.text.pdf包,在下文中一共展示了PdfGState类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSimple
import com.itextpdf.text.pdf.PdfGState; //导入依赖的package包/类
@Test
public void testSimple() throws FileNotFoundException, DocumentException
{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "transparency.pdf")));
writer.setCompressionLevel(0);
document.open();
PdfContentByte content = writer.getDirectContent();
content.setRGBColorStroke(0, 255, 0);
for (int y = 0; y <= 400; y+= 10)
{
content.moveTo(0, y);
content.lineTo(500, y);
}
for (int x = 0; x <= 500; x+= 10)
{
content.moveTo(x, 0);
content.lineTo(x, 400);
}
content.stroke();
content.saveState();
PdfGState state = new PdfGState();
state.setFillOpacity(0.5f);
content.setGState(state);
content.setRGBColorFill(255, 0, 0);
content.moveTo(162, 86);
content.lineTo(162, 286);
content.lineTo(362, 286);
content.lineTo(362, 86);
content.closePath();
//content.fillStroke();
content.fill();
content.restoreState();
document.close();
}
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:41,代码来源:TestTransparency.java
示例2: createPDFFile
import com.itextpdf.text.pdf.PdfGState; //导入依赖的package包/类
private void createPDFFile(String filename) throws FileNotFoundException, DocumentException {
PNEditorComponent editor = getEditor();
PNGraph pnGraph = editor.getGraphComponent().getGraph();
JFrame frm = new JFrame();
PNGraphComponent forPrint = new PNGraphComponent(pnGraph) {
};
mxRectangle size = forPrint.getGraph().getGraphBounds();
double space = 4;
float x = (float) (size.getRectangle().getWidth() + size.getRectangle().getX() + space);
float y = (float) (size.getRectangle().getHeight() + size.getRectangle().getY() + space);
Document document = new Document(new Rectangle(x, y));
PdfWriter writer = null;
writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
// set crop of pdf doc = ll=lowerleft; ur=upper right
float llx = (float) size.getX();
float lly = 0;
float urx = x;
float ury = (float) ((float) size.getRectangle().getHeight() + space*4);
com.itextpdf.text.Rectangle crop = new com.itextpdf.text.Rectangle(llx, lly, urx, ury);
writer.setCropBoxSize(crop);
document.open();
PdfContentByte canvas = writer.getDirectContent();
// make pdf-background transparent
PdfGState gState = new PdfGState();
gState.setFillOpacity(0.0f);
canvas.setGState(gState);
forPrint.setGridVisible(false);
PdfGraphics2D g2 = new PdfGraphics2D(canvas, x, y);
frm.getContentPane().add(forPrint);
frm.pack();
forPrint.paint(g2);
g2.dispose();
document.close();
}
开发者ID:iig-uni-freiburg,项目名称:WOLFGANG,代码行数:44,代码来源:ExportPDFAction.java
示例3: doFancyStuff
import com.itextpdf.text.pdf.PdfGState; //导入依赖的package包/类
@Override
protected void doFancyStuff(ActionEvent e) throws Exception {
setUpGui();
fch.addChoosableFileFilter(new FileFilter() {
public String getDescription() {
return "Portable Network Graphics (*.png)";
}
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
} else {
return f.getName().toLowerCase().endsWith(".png");
}
}
});
fch.setDialogTitle("Save PNG");
int returnVal = fch.showDialog(getEditor().getGraphComponent(), "save PNG");
if (returnVal == JFileChooser.APPROVE_OPTION) {
String filename = fch.getSelectedFile().getAbsolutePath();
if (!filename.toLowerCase().endsWith(".png"))
filename += ".png";
PNEditorComponent editor = getEditor();
PNGraph pnGraph = editor.getGraphComponent().getGraph();
JFrame frm = new JFrame();
PNGraphComponent forPrint = new PNGraphComponent(pnGraph) {
};
mxRectangle size = forPrint.getGraph().getGraphBounds();
double space = 4;
float x = (float) (size.getRectangle().getWidth() + size.getRectangle().getX() + space);
float y = (float) (size.getRectangle().getHeight() + size.getRectangle().getY() + space);
Document document = new Document(new Rectangle(x, y));
PdfWriter writer = null;
writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
// set crop of pdf doc = ll=lowerleft; ur=upper right
float llx = (float) size.getX();
float lly = 0;
float urx = x;
float ury = (float) ((float) size.getRectangle().getHeight() + space);
com.itextpdf.text.Rectangle crop = new com.itextpdf.text.Rectangle(llx, lly, urx, ury);
writer.setCropBoxSize(crop);
document.open();
PdfContentByte canvas = writer.getDirectContent();
// make pdf-background transparent
PdfGState gState = new PdfGState();
gState.setFillOpacity(0.0f);
canvas.setGState(gState);
forPrint.setGridVisible(false);
// PdfGraphics2D g2 = new PdfGraphics2D(canvas, x, y);
BufferedImage b = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB); /* change sizes of course */
Graphics2D g2 = b.createGraphics();
// component.print(g);
frm.getContentPane().add(forPrint);
frm.pack();
forPrint.paint(g2);
ImageIO.write(b,"png",new File(filename));
g2.dispose();
document.close();
}
}
开发者ID:iig-uni-freiburg,项目名称:WOLFGANG,代码行数:75,代码来源:ExportPNGAction.java
示例4: applyWatermarkOnAllPages
import com.itextpdf.text.pdf.PdfGState; //导入依赖的package包/类
public static void applyWatermarkOnAllPages(
PdfReader reader, PdfStamper stamper, String text, BaseColor color, float opacity
) throws DocumentException, IOException {
int numberOfPages = reader.getNumberOfPages();
PdfGState gs = new PdfGState();
gs.setFillOpacity(opacity);
for (int i = 1; i <= numberOfPages; i++) {
Rectangle pageSize = reader.getPageSize(i);
int pageRotation = reader.getPageRotation(i);
boolean isLandscape = false;
if(pageRotation > 0){
isLandscape = true;
}
int pageDiagonalSize = getDiagonalSize(pageSize);
int watermarkAngle = getDiagonalAngle(pageSize, pageDiagonalSize, isLandscape);
LinkedHashSet<Integer> fontSizeSet = new LinkedHashSet<Integer>();
float fontSize = determineFontSize(pageDiagonalSize, a4WatermarkFontSize, fontSizeSet);
fontSize = fontSize - 1;
int cornerPlacement = getCornerPlacementDiagonal(fontSize);
PdfContentByte underContent = stamper.getUnderContent(i);
underContent.setGState(gs);
underContent.setFontAndSize(getWaterkmarkFont(), fontSize);
underContent.setColorFill(color);
underContent.beginText();
underContent.showTextAligned(
Element.ALIGN_BASELINE, text,
cornerPlacement/2,
cornerPlacement/2,
watermarkAngle
);
underContent.endText();
}
}
开发者ID:MatheusArleson,项目名称:PdfUtil,代码行数:42,代码来源:PdfWatermarker.java
示例5: testCreateLinkWithAppearance
import com.itextpdf.text.pdf.PdfGState; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/34734669/define-background-color-and-transparency-of-link-annotation-in-pdf">
* Define background color and transparency of link annotation in PDF
* </a>
* <p>
* This test creates a link annotation with custom appearance. Adobe Reader chooses
* to ignore it but other viewers use it. Interestingly Adobe Acrobat export-as-image
* does use the custom appearance...
* </p>
*/
@Test
public void testCreateLinkWithAppearance() throws IOException, DocumentException
{
Document doc = new Document();
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "custom-link.appearance.pdf")));
writer.setCompressionLevel(0);
doc.open();
BaseFont baseFont = BaseFont.createFont();
int fontSize = 15;
doc.add(new Paragraph("Hello", new Font(baseFont, fontSize)));
PdfContentByte content = writer.getDirectContent();
String text = "Test";
content.setFontAndSize(baseFont, fontSize);
content.beginText();
content.moveText(100, 500);
content.showText(text);
content.endText();
Rectangle linkLocation = new Rectangle(95, 495 + baseFont.getDescentPoint(text, fontSize),
105 + baseFont.getWidthPoint(text, fontSize), 505 + baseFont.getAscentPoint(text, fontSize));
PdfAnnotation linkGreen = PdfAnnotation.createLink(writer, linkLocation, PdfName.HIGHLIGHT, "green" );
PdfTemplate appearance = PdfTemplate.createTemplate(writer, linkLocation.getWidth(), linkLocation.getHeight());
PdfGState state = new PdfGState();
//state.FillOpacity = .3f;
// IMPROVEMENT: Use blend mode Darken instead of transparency; you may also want to try Multiply.
state.setBlendMode(new PdfName("Darken"));
appearance.setGState(state);
appearance.setColorFill(BaseColor.GREEN);
appearance.rectangle(0, 0, linkLocation.getWidth(), linkLocation.getHeight());
appearance.fill();
linkGreen.setAppearance(PdfName.N, appearance);
writer.addAnnotation(linkGreen);
doc.open();
doc.close();
}
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:52,代码来源:CreateLink.java
示例6: testComplex
import com.itextpdf.text.pdf.PdfGState; //导入依赖的package包/类
@Test
public void testComplex() throws FileNotFoundException, DocumentException
{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "transparencyComplex.pdf")));
writer.setCompressionLevel(0);
document.open();
PdfContentByte content = writer.getDirectContent();
content.setRGBColorStroke(0, 255, 0);
for (int y = 0; y <= 400; y+= 10)
{
content.moveTo(0, y);
content.lineTo(500, y);
}
for (int x = 0; x <= 500; x+= 10)
{
content.moveTo(x, 0);
content.lineTo(x, 400);
}
content.stroke();
PdfTemplate template = content.createTemplate(500, 400);
PdfTransparencyGroup group = new PdfTransparencyGroup();
group.put(PdfName.CS, PdfName.DEVICEGRAY);
group.setIsolated(false);
group.setKnockout(false);
template.setGroup(group);
PdfShading radial = PdfShading.simpleRadial(writer, 262, 186, 10, 262, 186, 190, BaseColor.WHITE, BaseColor.BLACK, true, true);
template.paintShading(radial);
PdfDictionary mask = new PdfDictionary();
mask.put(PdfName.TYPE, PdfName.MASK);
mask.put(PdfName.S, new PdfName("Luminosity"));
mask.put(new PdfName("G"), template.getIndirectReference());
content.saveState();
PdfGState state = new PdfGState();
state.put(PdfName.SMASK, mask);
content.setGState(state);
content.setRGBColorFill(255, 0, 0);
content.moveTo(162, 86);
content.lineTo(162, 286);
content.lineTo(362, 286);
content.lineTo(362, 86);
content.closePath();
//content.fillStroke();
content.fill();
content.restoreState();
document.close();
}
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:54,代码来源:TestTransparency.java
注:本文中的com.itextpdf.text.pdf.PdfGState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论