<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I can reference a PDF but not choose its page in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8071585#M25577</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Apologies in advance if I'm misinterpreting the way PDF references work. I have the following code which creates a PDF definition and reference, but I also want to choose which page to display in the same vein as -PDFATTACH. I haven't been able to find any relevant variables in the PdfDefinition and PdfReference objects. This is the code I have:&lt;BR /&gt;(TinyAcad is a helper class I wrote to shorten/simplify certain common tasks)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        private static int PdfNamingCounter = 0;
        private static string NextPdfName = "AttachedPDF_" + PdfNamingCounter;

        ///&amp;lt;summary&amp;gt; Creates PDF definition and reference at the origin. &amp;lt;/summary&amp;gt;
        public static ObjectId InsertPDF(string pdfPath, int pdfPage = 1)
        {
            Database db = TinyAcad.WorkingDatabase;

            using (Transaction tr = TinyAcad.NewWorkingDocTransaction)
            {
                DBDictionary nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
                string defDictKey = UnderlayDefinition.GetDictionaryKey(typeof(PdfDefinition));

                if (!nod.Contains(defDictKey))
                {
                    using (DBDictionary dict = new DBDictionary())
                    {
                        nod.SetAt(defDictKey, dict);
                        tr.AddNewlyCreatedDBObject(dict, true);
                    }
                }

                ObjectId pdfDefID;
                DBDictionary pdfDict = (DBDictionary)tr.GetObject(nod.GetAt(defDictKey), OpenMode.ForWrite);

                using (PdfDefinition pdfDef = new PdfDefinition())
                {
                    pdfDef.SourceFileName = pdfPath;
                    while (pdfDict.Contains(NextPdfName)) PdfNamingCounter++;
                    pdfDefID = pdfDict.SetAt(NextPdfName, pdfDef);
                    tr.AddNewlyCreatedDBObject(pdfDef, true);
                }

                ObjectId pdfRefID;
                using (PdfReference pdfRef = new PdfReference())
                {
                    pdfRef.DefinitionId = pdfDefID;
                    pdfRef.Position = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0);

                    TinyAcad.AppendToModelSpace(tr, pdfRef);
                    tr.AddNewlyCreatedDBObject(pdfRef, true);
                    pdfRefID = pdfRef.ObjectId;
                }
                tr.Commit();
                return pdfRefID;
            }
        }&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Jun 2018 17:30:24 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-06-15T17:30:24Z</dc:date>
    <item>
      <title>I can reference a PDF but not choose its page</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8071585#M25577</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Apologies in advance if I'm misinterpreting the way PDF references work. I have the following code which creates a PDF definition and reference, but I also want to choose which page to display in the same vein as -PDFATTACH. I haven't been able to find any relevant variables in the PdfDefinition and PdfReference objects. This is the code I have:&lt;BR /&gt;(TinyAcad is a helper class I wrote to shorten/simplify certain common tasks)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        private static int PdfNamingCounter = 0;
        private static string NextPdfName = "AttachedPDF_" + PdfNamingCounter;

        ///&amp;lt;summary&amp;gt; Creates PDF definition and reference at the origin. &amp;lt;/summary&amp;gt;
        public static ObjectId InsertPDF(string pdfPath, int pdfPage = 1)
        {
            Database db = TinyAcad.WorkingDatabase;

            using (Transaction tr = TinyAcad.NewWorkingDocTransaction)
            {
                DBDictionary nod = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
                string defDictKey = UnderlayDefinition.GetDictionaryKey(typeof(PdfDefinition));

                if (!nod.Contains(defDictKey))
                {
                    using (DBDictionary dict = new DBDictionary())
                    {
                        nod.SetAt(defDictKey, dict);
                        tr.AddNewlyCreatedDBObject(dict, true);
                    }
                }

                ObjectId pdfDefID;
                DBDictionary pdfDict = (DBDictionary)tr.GetObject(nod.GetAt(defDictKey), OpenMode.ForWrite);

                using (PdfDefinition pdfDef = new PdfDefinition())
                {
                    pdfDef.SourceFileName = pdfPath;
                    while (pdfDict.Contains(NextPdfName)) PdfNamingCounter++;
                    pdfDefID = pdfDict.SetAt(NextPdfName, pdfDef);
                    tr.AddNewlyCreatedDBObject(pdfDef, true);
                }

                ObjectId pdfRefID;
                using (PdfReference pdfRef = new PdfReference())
                {
                    pdfRef.DefinitionId = pdfDefID;
                    pdfRef.Position = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0);

                    TinyAcad.AppendToModelSpace(tr, pdfRef);
                    tr.AddNewlyCreatedDBObject(pdfRef, true);
                    pdfRefID = pdfRef.ObjectId;
                }
                tr.Commit();
                return pdfRefID;
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jun 2018 17:30:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8071585#M25577</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-15T17:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: I can reference a PDF but not choose its page</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8769762#M25578</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for the same, did you get any hint?&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2019 15:23:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8769762#M25578</guid>
      <dc:creator>rtejada</dc:creator>
      <dc:date>2019-05-03T15:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: I can reference a PDF but not choose its page</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8880182#M25579</link>
      <description>&lt;P&gt;I have just posted an article on this topic - attaching PDF underlay from PDF file with multiple pages in it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://drive-cad-with-code.blogspot.com/2019/06/attach-pdf-underlay-how-to-handle.html" target="_blank" rel="noopener"&gt;https://drive-cad-with-code.blogspot.com/2019/06/attach-pdf-underlay-how-to-handle.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jun 2019 19:56:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-can-reference-a-pdf-but-not-choose-its-page/m-p/8880182#M25579</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2019-06-28T19:56:11Z</dc:date>
    </item>
  </channel>
</rss>

