SetRemoteGoto() публичный Метод

Sets a goto for a remote destination for this Chunk.
public SetRemoteGoto ( string filename, int page ) : Chunk
filename string the file name of the destination document
page int the page of the destination to go to. First page is 1
Результат Chunk
Пример #1
0
 public static Chunk GetChunk(Properties attributes) {
     Chunk chunk = new Chunk();
     
     chunk.Font = FontFactory.GetFont(attributes);
     String value;
     
     value = attributes[ElementTags.ITEXT];
     if (value != null) {
         chunk.Append(value);
     }
     value = attributes[ElementTags.LOCALGOTO];
     if (value != null) {
         chunk.SetLocalGoto(value);
     }
     value = attributes[ElementTags.REMOTEGOTO];
     if (value != null) {
         String page = attributes[ElementTags.PAGE];
         if (page != null) {
             chunk.SetRemoteGoto(value, int.Parse(page));
         }
         else {
             String destination = attributes[ElementTags.DESTINATION];
             if (destination != null) {
                 chunk.SetRemoteGoto(value, destination);
             }
         }
     }
     value = attributes[ElementTags.LOCALDESTINATION];
     if (value != null) {
         chunk.SetLocalDestination(value);
     }
     value = attributes[ElementTags.SUBSUPSCRIPT];
     if (value != null) {
         chunk.SetTextRise(float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo));
     }
     value = attributes[Markup.CSS_KEY_VERTICALALIGN];
     if (value != null && value.EndsWith("%")) {
         float p = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo) / 100f;
         chunk.SetTextRise(p * chunk.Font.Size);
     }
     value = attributes[ElementTags.GENERICTAG];
     if (value != null) {
         chunk.SetGenericTag(value);
     }
     value = attributes[ElementTags.BACKGROUNDCOLOR];
     if (value != null) {
         chunk.SetBackground(Markup.DecodeColor(value));
     }
     return chunk;
 }
Пример #2
0
// ===========================================================================
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        // Create a local destination at the top of the page
        Paragraph p = new Paragraph();
        Chunk top = new Chunk("Country List", FilmFonts.BOLD);
        top.SetLocalDestination("top");
        p.Add(top);
        document.Add(p);
        // create an external link
        Chunk imdb = new Chunk("Internet Movie Database", FilmFonts.ITALIC);
        imdb.SetAnchor(new Uri("http://www.imdb.com/"));
        p = new Paragraph(
          "Click on a country, and you'll get a list of movies, containing links to the "
        );
        p.Add(imdb);
        p.Add(".");
        document.Add(p);
        // Create a remote goto
        p = new Paragraph("This list can be found in a ");
        Chunk page1 = new Chunk("separate document");
        page1.SetRemoteGoto("movie_links_1.pdf", 1);
        p.Add(page1);
        p.Add(".");
        document.Add(p);
        document.Add(Chunk.NEWLINE);
        
        var SQL =
@"SELECT DISTINCT mc.country_id, c.country, count(*) AS c 
FROM film_country c, film_movie_country mc
WHERE c.id = mc.country_id 
GROUP BY mc.country_id, country ORDER BY c DESC";        
        // Create a database connection and statement
        using (var c =  AdoDB.Provider.CreateConnection()) {
          c.ConnectionString = AdoDB.CS;
          using (DbCommand cmd = c.CreateCommand()) {
            cmd.CommandText = SQL;        
            c.Open();            
            using (var r = cmd.ExecuteReader()) {
              while (r.Read()) {
              // add country with remote goto
                Paragraph country = new Paragraph(r["country"].ToString());
                country.Add(": ");
                Chunk link = new Chunk(string.Format(
                  "{0} movies", Convert.ToInt32(r["c"])
                ));
                link.SetRemoteGoto(
                  "movie_links_1.pdf", r["country_id"].ToString()
                );
                country.Add(link);
                document.Add(country);
              }
            }
          }
        }      
        document.Add(Chunk.NEWLINE);
        // Create local goto to top
        p = new Paragraph("Go to ");
        top = new Chunk("top");
        top.SetLocalGoto("top");
        p.Add(top);
        p.Add(".");
        document.Add(p);        
      }
    }
Пример #3
0
        public void MergeNamedDestinationsTest()  {
            string outputFolder = "PdfCopyTest/";
            string outputFile = "namedDestinations.pdf";
            Directory.CreateDirectory(outputFolder);

            // Create simple document
            MemoryStream main = new MemoryStream();
            Document doc = new Document(new Rectangle(612f,792f),54f,54f,36f,36f);
            PdfWriter pdfwrite = PdfWriter.GetInstance(doc, main);
            doc.Open();
            doc.Add(new Paragraph("Testing Page"));
            doc.Close();

            // Create TOC document
            MemoryStream two = new MemoryStream();
            Document doc2 = new Document(new Rectangle(612f,792f),54f,54f,36f,36f);
            PdfWriter pdfwrite2 = PdfWriter.GetInstance(doc2, two);
            doc2.Open();
            Chunk chn = new Chunk("<<-- Link To Testing Page -->>");
            chn.SetRemoteGoto("DUMMY.PDF","page-num-1");
            doc2.Add(new Paragraph(chn));
            doc2.Close();

            // Merge documents
            MemoryStream three = new MemoryStream();
            PdfReader reader1 = new PdfReader(main.ToArray());
            PdfReader reader2 = new PdfReader(two.ToArray());
            Document doc3 = new Document();
            PdfCopy DocCopy = new PdfCopy(doc3,three);
            doc3.Open();
            DocCopy.AddPage(DocCopy.GetImportedPage(reader2,1));
            DocCopy.AddPage(DocCopy.GetImportedPage(reader1,1));
            DocCopy.AddNamedDestination("page-num-1",2,new PdfDestination(PdfDestination.FIT));
            doc3.Close();

            // Fix references and write to file
            PdfReader finalReader = new PdfReader(three.ToArray());
            finalReader.MakeRemoteNamedDestinationsLocal();
            PdfStamper stamper = new PdfStamper(finalReader,new  FileStream(outputFolder + outputFile, FileMode.Create));
            stamper.Close();

           
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent(outputFolder + outputFile, RESOURCES + "cmp_" + outputFile, outputFolder, "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }