Change the page orientation in middle of doc - docx4j

I need to set landscape to some pages of a document. I tried this code:
SectPr sectionLandscape = objectFactory.createSectPr();
String rsidR = sectionLandscape.getRsidR();
SectPr sectionPortrait = objectFactory.createSectPr();
sectionPortrait.setRsidR(rsidR);
sectionPortrait.setRsidSect(rsidR);
PgSz landscape = new PgSz();
landscape.setOrient(STPageOrientation.LANDSCAPE);
landscape.setH(BigInteger.valueOf(11906));
landscape.setW(BigInteger.valueOf(16383));
sectionLandscape.setPgSz(landscape);
mdp.addObject(sectionLandscape);
It creates this xml code:
<w:sectPr>
<w:pgSz w:w="16383" w:orient="landscape" w:h="11906"/>
</w:sectPr>
And after of the Section tag have the text and the table that i need inside landscape page. With Word 2007/2010 i only see the portrait page and in editing mode of the page I can see the page selected as landscape.
http://i.stack.imgur.com/HHuGB.png

The sectPr should be in a w:p/w:pPr after the content which it is to appear in landscape orientation.
You need sectPr specifying portrait before that content.

Related

Flattening the AcroForm in PDFBox 2 changes font color

I have a pdf with a grey background on which there are few PDFields. I have set the value for these fields using:
PDAcroForm form = catalog.getAcroForm();
if(null != form){
//Field on top of grey background
PDField idField = form.getField("id");
if (null != idField) {
idField.setValue(value);
}
//Other fields outside grey background
}
Everything works as expected. However, the form fields are not visible when opening in ios' default PDF reader. So I'm trying to flatten the pdf.
Now, when I try to flatten the pdf using form.flatten(), the text of the PDFields on top of the grey background become white (it was black before flattening).
And just for experimenting, I tried flattening only the other fields in the PDF (and skip flattening idField) using form.flatten(fieldsToFlatten, false). When I do this, the fields on the grey background completely disappear.
Why is the font color changing when I try to flatten the pdf? Is there anyway to retain the original font color?
Thanks.

Cannot open embedded hyperlink in PDF generated using PDFBox

I have used PDFBox version 2.0 to generated a PDF containing a clickable URL.
// Create a new annotation and make it invisible
PDAnnotationLink txtLink = new PDAnnotationLink();
txtLink.setInvisible(true);
// Add an action
PDActionURI action = new PDActionURI();
action.setURI(url);
txtLink.setAction(action);
// Create a new rectangle that will be the clickable area
PDRectangle position = new PDRectangle();
position.setLowerLeftX(currentXpos);
position.setLowerLeftY(currentYpos - rectangleHeight);
position.setUpperRightX(currentXpos + rectangleWidth);
position.setUpperRightY(currentYpos);
// Write the "Link" string in blue
contentStream.setNonStrokingColor(Color.blue);
contentStream.showText(elm.text());
contentStream.setNonStrokingColor(Color.black);
// Make the rectangle a clickable link and add it to the page
txtLink.setRectangle(position);
page.getAnnotations().add(txtLink);
When I click on the generated PDF in Chrome 45, the document is opened in the Chrome's PDF viewer. The link is clickable, no problem.
If I click on the generated PDF in Firefox (41.0.1) or IE 11, the document is loaded in the Adobe PDF viewer plugin and the link is not clickable. The mouse-over displays the correct URL, but nothing happens when I click the link.
Is this a security issue? Is there anything I can do in the PDFBox code to make the link clickable always?
I was able to hide the border by setting the width to 0:
// Create a new annotation and make it visible
PDAnnotationLink txtLink = new PDAnnotationLink();
txtLink.setInvisible(false);
// Set the border to zero to hide it
PDBorderStyleDictionary border = new PDBorderStyleDictionary();
border.setWidth(0);
txtLink.setBorderStyle(border);

How to disable logo in Windows 8 metro app live tile?

I am trying to disable the logo in my metro app live tile so that the last line of text in my tile notification will show. The Windows 8 documentation
says that there is a way to disable this logo in the Package.appxmanifest file. However, it does not specify how. I have set the ShortName in my .appxmanifest and I have also set the "Show name" field to "All Logos"; however, the default logo still appears in the bottom left-hand corner of the live tile and obscures the last line of text in my tile notification. Any ideas?
A live tile can have an image, text, or no branding. The default is the app logo, and you override this when you create a live tile update by specifying branding "none", like this:
var templateContent = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImage);
var imageElement = (XmlElement) templateContent.GetElementsByTagName("image").Item(0);
imageElement.SetAttribute("src", string.Concat(imagePath, "wide_tile.png"));
var bindingElement = (XmlElement) templateContent.GetElementsByTagName("binding").Item(0);
bindingElement.SetAttribute("branding", "none");
var tile = new TileNotification(templateContent);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tile);
You can't have both the last line of text and a short name. It's either logo/shortname or the the last line of text.
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d7ed6580-0528-4a28-a475-731b37f2c89b

How to change pop up background color on IE9

IE9 pop up windows has black background color when showing PNG image. I found a workaround which works on Firefox 10 (and above) that also shows PNG with dark background on pop up window. Here is the code, this doesn't work for IE9:
function openLarge() {
var image = $('main-image').href;
NewWin = window.open(image,"LargeImage","resizable=yes,scrollbars=auto,status=no,width=710,height=510");
NewWin.document.writeln("<body bgcolor='#fff'>");
NewWin.document.writeln("<img src='" + image + "'>");
NewWin.document.writeln("<\/body>");
NewWin.document.close();
}
Any ideas?
The problem here is with the opening address. If you remove the image reference, and open up to a blank document, you'll have your background set.
I suspect this has something to do with the headers upon first loading the resource. With an image, the content type would be set to image/jpeg or something, but then we're attempting to manipulate the document as if it were text/html.
function openLarge() {
var image = $('main-image').href;
NewWin = window.open('',"LargeImage","resizable=yes,scrollbars=auto,status=no,width=710,height=510");
NewWin.document.writeln("<body bgcolor='#fff'>");
NewWin.document.writeln("<img src='" + image + "'>");
NewWin.document.writeln("<\/body>");
NewWin.document.close();
}

iTextSharp Overlay Image

Hi guys I have an instance where I have a logo image as part of some artwork..
If a user uploads a new logo I have a form field which is larger than the default logo.
I then use that form field to position the new image.
The problem is I need to set the background colour of that form field to white so that it covers the old logo in the event that the new image is smaller than the old logo..
what I have done is:
foreach (var imageField in imageReplacements)
{
fields.SetFieldProperty(imageField.Key, "bgcolor", iTextSharp.text.Color.WHITE, null);
fields.RegenerateField(imageField.Key);
PdfContentByte overContent = stamper.GetOverContent(imageField.Value.PageNumber);
float[] logoArea = fields.GetFieldPositions(imageField.Key);
if (logoArea != null)
{
iTextSharp.text.Rectangle logoRect = new iTextSharp.text.Rectangle(logoArea[1], logoArea[2], logoArea[3], logoArea[4]);
var logo = iTextSharp.text.Image.GetInstance(imageField.Value.Location);
if (logo.Width >= logoRect.Width || logo.Height >= logoRect.Height)
{
logo.ScaleToFit(logoRect.Width, logoRect.Height);
}
logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT;
logo.SetAbsolutePosition(logoRect.Left, logoArea[2] + (logoRect.Height - logo.ScaledHeight) / 2);
// left: logoArea[3] - logo.ScaledWidth + (logoRect.Width - logo.ScaledWidth) / 2
overContent.AddImage(logo);
}
}
The problem with this is that the background colour of the field is set to white and the image then doesn't appear.. i remove the SetFieldProperty and RegenerateField commands and the image replacement works fine..
is there a way to set a stacking order on layers?
Annotations (such as form fields) are always on top of page contents. Annotation Z order is just the order of the annotations array on a given page.
Page content Z order is just the order everything appears in the content stream. New drawing operators go on top of proceeding operators.
If you want to cover your old image, draw a white box over it and then draw the new logo over top that. No need to worry about annotations.
Actually, all you really need to do is not set the background color of the imageField. You're already scaling the new logo to match the size of the old one.
However, if you really must draw that white box, it's fairly simple:
overContent.setColorFill(iTextSharp.text.Color.WHITE);
overContent.rectangle( logoRect );
overcontent.fill();