Here I want to set the already exist PDF document properties under Initial View tab in acrobat.
Document Options:
Show = Bookmarks Panel and Page
Page Layout = Continuous
Magnification = Fit Width
Open to Page number = 1
Window Options:
Show = Document Title
As show in below screen shot:
I am tried following code:
PdfStamper stamper = new PdfStamper(reader, new FileStream(dPDFFile, FileMode.Create));
stamper.AddViewerPreference(PdfName.DISPLAYDOCTITLE, new PdfBoolean(true));
the above code is used to set the document title show.
But following code are not working
For Page Layout:
stamper.AddViewerPreference(PdfName.PAGELAYOUT, new PdfName("OneColumn"));
For Bookmarks Panel and Page:
stamper.AddViewerPreference(PdfName. PageMode, new PdfName("UseOutlines"));
So please give guide me what is the correct way to meet my requirement.
I'm adding an extra answer in answer to the extra question in the comments of the previous answer:
When you have a PdfWriter instance named writer, you can set the Viewer preferences like this:
writer.ViewerPreferences = viewerpreference;
In this case, the viewerpreference is a value that can have one of the following values:
PdfWriter.PageLayoutSinglePage
PdfWriter.PageLayoutOneColumn
PdfWriter.PageLayoutTwoColumnLeft
PdfWriter.PageLayoutTwoColumnRight
PdfWriter.PageLayoutTwoPageLeft
PdfWriter.PageLayoutTwoPageRight
See the PageLayoutExample for more info.
You can also change the page mode as is shown in the ViewerPreferencesExample. In which case the different values are "OR"-ed:
PdfWriter.PageModeFullScreen
PdfWriter.PageModeUseThumbs
PdfWriter.PageLayoutTwoColumnRight | PdfWriter.PageModeUseThumbs
PdfWriter.PageModeFullScreen | PdfWriter.NonFullScreenPageModeUseOutlines
PdfWriter.FitWindow | PdfWriter.HideToolbar
PdfWriter.HideWindowUI
Currently, you've only used the PrintPreferences example from the official documentation:
writer.AddViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
writer.AddViewerPreference(PdfName.NUMCOPIES, new PdfNumber(3));
writer.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfBoolean.PDFTRUE);
But in some cases, it's just easier to use:
writer.ViewerPreferences = viewerpreference;
Note that the official documentation is the book "iText in Action - Second Edition." The examples are written in Java, but you can find the C# version here. There is a new book in the works called "The ABC of PDF", but so far only 4 chapters were written. You'll find more info here: http://itextpdf.com/learn
The part about the different options to create a PdfDestination is already present in "The ABC of PDF".
As for setting the language, this is done like this:
stamper.Writer.ExtraCatalog.Put(PdfName.LANG, new PdfString("EN"));
The result is shown in the following screen shot:
As you can see, there is now a Lang entry with value EN added to the catalog.
The two items Show = Bookmarks Panel and Page and Page Layout = Continuous are controlled one layer up from the ViewerPreferences in the document's /Catalog. You can get to this via:
stamper.Writer.ExtraCatalog
In your case you're looking for:
// Acrobat's Single Page
stamper.Writer.ExtraCatalog.Put(PdfName.PAGELAYOUT, PdfName.ONECOLUMN);
// Show bookmarks
stamper.Writer.ExtraCatalog.Put(PdfName.PAGEMODE, PdfName.USEOUTLINES);
The items Magnification = Fit Width and Open to Page number = 1 are also part of the /Catalog but in a special key called /OpenAction. You can set this using:
stamper.Writer.SetOpenAction();
In your case you're looking for:
//Create a destination that fit's width (fit horizontal)
var D = new PdfDestination(PdfDestination.FITH);
//Create an open action that points to a specific page using this destination
var OA = PdfAction.GotoLocalPage(1, D, stamper.Writer);
//Set the open action on the writer
stamper.Writer.SetOpenAction(OA);
Related
I am fairly new to iTextSharp. I create PDFs by adding variable data (text/barcodes/images) to existing PDF documents/templates (think boiler plate). Most commonly, I have to place various sections of text in specific places. I know how to create an ordered list, but I have come across a situation where the list begins with #1 on the first page and then #2-4 on the top of the second page. I use two different templates for p1 and p2.
I am currently creating the document by creating ColumnTexts, placing SimpleColumns with specific coordinates, and then placing phrases inside. I am not sure if this is the best way or not, so I am open for alternative solutions.
I have checked out several places including http://www.mikesdotnetting.com/article/83/lists-with-itextsharp but I see nothing that describes how to start a list at a number other than '1'. None of the 6 overloads provide a parameter for starting number.
Thanks!
There are two answers to your question. The first one is to point you to the official documentation. There is a method setFirst() that (I quote) sets the number that has to come first in the list.
You are using the C# port of iText, so if you want the list to start counting at 10, you need to do something like:
list.First = 10;
The second answer takes more time, but it is probably the better one.You don't need two List objects, one for the first page and one for the second page. It's better to add the List to a ColumnText object and then distribute the column over two pages.
Take a look at the ListInColumn example. It takes an existing PDF (with the text "Hello World Hello People") and it adds a list using ColumnText: list_in_column.pdf
This is how it's done:
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
List list = new List(List.ORDERED);
for (int i = 0; i < 10; i++) {
list.add("...");
}
ColumnText ct = new ColumnText(stamper.getOverContent(1));
ct.addElement(list);
Rectangle rect = new Rectangle(250, 400, 500, 806);
ct.setSimpleColumn(rect);
int status = ct.go();
if (ColumnText.hasMoreText(status)) {
ct.setCanvas(stamper.getOverContent(2));
ct.setSimpleColumn(rect);
ct.go();
}
stamper.close();
To add the content on the first page, I use:
ColumnText ct = new ColumnText(stamper.getOverContent(1));
You are probably using similar code.
The content is added using the line:
int status = ct.go();
If not all the content was added, I change the canvas to add the rest of the content on the second page:
ct.setCanvas(stamper.getOverContent(2));
The rest of the code is pretty standard.
I think the setCanvas() method is the missing piece in your puzzle, although in your case, you'll need:
ct.Canvas = stamper.GetOverContent(2);
I need to open a modal window or popup from a SharePoint site column, when the user clicks on a link shown by this column.
I have tried to use these types of site columns:
Full HTML content with formatting and constraints for publishing
Hyperlink with formatting and constraints for publishing
but I don't know how exactly to use them. What should I put as content? I have tried this code from C# but that does not work:
private LinkFieldValue linkField = new LinkFieldValue();
linkField.NavigateUrl = "javascript:window.open('Pages/delete.aspx?Id='" + id +",width='300',height ='300', toolbar='no')";
linkField.Text = "Delete";
linkField.UseDefaultIcon = true;
linkField.ToolTip = "Delete";
I'm pretty sure I'm missing something simple, but since I've been breaking my head on this for a while, I'm just going to ask.
I'm using JavaScript to access the iText (Java) library to take a filable PDF and serve it up via a browser. The process has worked for my first one, and now I'm doing one where the original fillable PDF has 2 pages. I've been trying to get the second page for a while now. I'm using the PdfContentByte to get it to the browser, and it works except I can't seem to get the PdfContentByte to have a second page. My relevant code is below. When I add the second template (page2) they way I do, it moves what I'm writing, but I'm still just getting one (US letter) page.
This may not be the most efficient code, but like I said, I've been trying a few things on this. If someone has a pointer, I would be very grateful.
var cb:com.itextpdf.text.pdf.PdfContentByte = writer.getDirectContent();
var cb2:com.itextpdf.text.pdf.PdfContentByte = writer.getDirectContent();
var reader2:com.itextpdf.text.pdf.PdfReader = new com.itextpdf.text.pdf.PdfReader(os.toByteArray());
var page:com.itextpdf.text.pdf.PdfImportedPage = writer.getImportedPage(reader2, 1);
cb.addTemplate(page, 0, 0); //this works as expected
var page2:com.itextpdf.text.pdf.PdfImportedPage = writer.getImportedPage(reader2, 2);
// this will add, and with the 100 do an offset, but the
// "physical size" of the paper is the same
cb2.addTemplate(page2, 0, 100);
Have a look at chapter 6 of iText in Action, 2nd edition, especially at subsection 6.4.1: Concatenating and splitting PDF documents.
Listing 6.22, ConcatenateStamp.java, shows you how you should create a PDF from copies of pages of multiple other PDFs; the sample actually additionally adds a new "Page X of Y" footer which you may keep or remove from the sample.
My news should not contain any text, except for the title. Instead, in the list view the title should directly point to the first attached file (a PDF).
Now I thought the simplest solution for that would be to hide the title, show only the attached files and give them the title of the related news entry via TypoScript.
For the detail view this code works fine:
plugin.tt_news.newsFiles {
labelStdWrap.cObject = TEXT
labelStdWrap.cObject.dataWrap = DB:tt_news:{GPvar:tx_ttnews|tt_news}:title
labelStdWrap.cObject.wrap3 = {|}
labelStdWrap.cObject.insertData = 1
}
...but it uses the GPvar for the currently displayed news, which of course is not present in list view.
So my question is: how do I get the ID of the currently iterated news entry, if possible at all?
I am open to other solutions as well.
You will need to use custom itemMarkerArrayFunc - fastest by copying the sample into your own extension: typo3conf/ext/tt_news/res/example_itemMarkerArrayFunc.php and adding custom marker to $markerArray.
The mentioned sample even demonstrates access to files so I assume that should not be a problem to modify it for your needs.
Note: if you haven't any own ext to copy the func into it, and you don't want to create such, try to copy it somewhere under fileadmin folder, modifying files in original destination is wrong idea, cause you'll lost all changes after next tt_news' update.
Easiest solution I found is using the labelStdWrap:
plugin.tt_news.newsFiles {
labelStdWrap = TEXT
labelStdWrap.field= title
}
More options can be found here: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.0.0/view/5/13/
I want to create a word 2007 document without using object model. So I would prefer to create it using open xml format. So far I have been able to create the document. Now I want to add a content control in it and map it to xml. Can anybody guide me regarding the same???
Anoop,
You said that you are able to creat the document using OpenXmlSdk. With that assumption, you can use the following code to create the content control to add to the Wordprocessing.Body element of your Document.
//praragraph to be added to the rich text content control
Run run = new Run(new Text("Insert any text Here") { Space = StaticTextConstants.Preserve });
Paragraph paragraph = new Paragraph(run);
SdtProperties sdtPr = new SdtProperties(
new Alias { Val = "MyContentCotrol" },
new Tag { Val = "_myContentControl" });
SdtContentBlock sdtCBlock = new SdtContentBlock(paragraph);
SdtBlock sdtBlock = new SdtBlock(sdtPr, sdtCBlock);
//add this content control to the body of the word document
WordprocessingDocument wDoc = WordprocessingDocument.Open(path, true); //path is where your word 2007 file is
Body mBody = wDoc.MainDocumentPart.Document.Body;
mBody.AppendChild(sdtBlock);
wDoc.MainDocumentPart.Document.Save();
wDoc.Dispose();
I hope this answers a part of your question. I did not understand what you ment by "Map it to XML". Did you mean to say you want to create CustomXmlBlock and add the ContentControl to it?
Have a look for the Word Content Control Toolkit on www.codeplex.com.
Here is a very brief explanation on how to do what you are attempting.
You need to have access to the developer tab on the Word ribbon. To get this working click on the Office (Round thingy) in the top left hand corner and Select Word Options at the bottom of the menu. On the first options page there is a checkbox to show the developer toolbar.
Use the developer toolbar to add the Content controls you want on the page. Click the properties button in the Content controls section of the developer bar and set the name and tag properties (I stick to naming the name and tag fields with the same name).
Save and close the word document.
Open the Content control toolkit and then open your document with the toolkit. Use the left hand pain to create some custom xml to link to your controls.
Now use the bind view to drag and drop the mappings between your custom xml and the custom controls that are displayed in the right panel of the toolkit.
You can use the openxml sdk 1.0 or 2.0 (still in ctp) to open your word document in code and access the custom xml file that is contained as part of the word document.
If you want to have a look at how your word document looks as xml. Make a copy of your word document and then rename it to say "a.zip". Double click on the zip file and then navigate the folder structure. The main content of the word document is held under the word folder in a file called "document.xml". The custom xml part of the document is held under the customXml folder and is generally found in the file named "item1.xml".
I hope this brief explanation get you up and running.