public void TestPassthroughPptxDocumentEmptyPresentation() { string TEST_PPT = TESTFILE_DIR + "test001.pptx"; try { using (PptxDocumentProcessor pdp = new PptxDocumentProcessor(File.Open(TEST_PPT, FileMode.Open))) { using (pdp.Output = File.Open(TEST_OUTPUT_FILE, FileMode.CreateNew)) { pdp.Process(DocumentProcessingActions.PassThrough); } } Assert.IsTrue(CommonTestUtilities.AreZipFilesEqual(TEST_PPT, TEST_OUTPUT_FILE)); using (OPCPackage package = new OPCPackage(File.Open(TEST_OUTPUT_FILE, FileMode.Open))) { foreach (ContentTypeInfo cti in package.GetContentTypes()) { if (cti.Name == "/docProps/thumbnail.jpeg") Assert.Fail("Ooops, put in overrides of content types for parts that didn't have override info"); } } } finally { File.Delete(TEST_OUTPUT_FILE); } }
void Initialise(Stream inputStream) { m_openXmlFormat = OpenXmlFormatIdentifier.Resolve(inputStream); m_inputStream = inputStream; m_inputPackage = new OPCPackage(m_inputStream); m_outputPackage = null; m_commonNamespaces = new CommonNamespaces(m_openXmlFormat); }
public PartInfo(OPCPackage containingPackage, PartInfo templatePartInfo) { this.Id = templatePartInfo.Id; this.Type = templatePartInfo.Type; this.Target = templatePartInfo.Target; this.External = templatePartInfo.External; this.RelatedTo = templatePartInfo.RelatedTo; this.m_containingPackage = containingPackage; m_relationships = new Relationships(); }
private static PartInfo GetSheetPart(Stream s) { OPCPackage package = new OPCPackage(s); foreach (PartInfo pi in package.GetRelatedObjects()) { if (pi.GetContentType() == "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml") return pi; if (pi.GetContentType() == "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml") return pi; if (pi.GetContentType() == "application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml") return pi; if (pi.GetContentType() == "application/vnd.ms-excel.intlmacrosheet+xml") return pi; if (pi.GetContentType() == "application/vnd.ms-excel.macrosheet+xml") return pi; } return null; }
public PartInfo(OPCPackage containingPackage) { m_containingPackage = containingPackage; m_relationships = new Relationships(); }
public Relationships(OPCPackage containingPackage, Stream strXml, string relationshipRoot) { m_containingPackage = containingPackage; XmlDocument doc = new XmlDocument(); doc.Load(strXml); XmlNodeList nodes = doc.SelectNodes("*/*"); foreach (XmlNode node in nodes) { AddNewRelationship(node, relationshipRoot); } }
static PartInfo GetDocumentPart(Stream s) { OPCPackage package = new OPCPackage(s); foreach (PartInfo pi in package.GetRelatedObjects()) { if (pi.GetContentType() == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml") return pi; if (pi.GetContentType() == "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml") return pi; if (pi.GetContentType() == "application/vnd.ms-word.document.macroEnabled.main+xml") return pi; if (pi.GetContentType() == "application/vnd.ms-word.template.macroEnabledTemplate.main+xml") return pi; } return null; }
public static bool DocumentContainsEmbeddedObjects(string sFileName) { List<string> PartInfoTargets = new List<string>(); // Beware circular relationships!! using (Stream s = new FileStream(sFileName, FileMode.Open)) { OPCPackage package = new OPCPackage(s); foreach (PartInfo pi in package.GetRelatedObjects()) { if (PartInfoContainsEmbeddedObjects(pi, ref PartInfoTargets)) return true; } } return false; }
private static PartInfo GetPresentationPart(Stream s) { OPCPackage package = new OPCPackage(s); foreach (PartInfo pi in package.GetRelatedObjects()) { if (pi.GetContentType() == "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml") return pi; if (pi.GetContentType() == "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml") return pi; } return null; }
private void ProcessExternalPart(PartInfo rel, OPCPackage outputPackage, DocumentProcessingActions action) { if (action == DocumentProcessingActions.Discover) return; outputPackage.AddContent(rel, null, m_openXmlFormat); }
private void ProcessPart(PartInfo rel, OPCPackage inputPackage, OPCPackage outputPackage, DocumentProcessingActions action) { if (rel.External) { ProcessExternalPart(rel, outputPackage, action); return; } if (m_ProcessedParts.ContainsKey(rel.AbsolutePath())) { if (outputPackage != null) outputPackage.AddContent(rel, null, m_openXmlFormat); return; } m_ProcessedParts.Add(rel.AbsolutePath(), true); IPartFilter pf = GetPartFilter(rel, action); Stream inputData = rel.GetContent(); RelatedPartProvider relPartProv = new RelatedPartProvider(inputPackage, rel); Stream modifiedStream = ProcessPartData(pf, inputData, relPartProv, action); if (modifiedStream != null) outputPackage.AddContent(rel, modifiedStream, m_openXmlFormat); if (action != DocumentProcessingActions.PassThrough && pf.IsBlockedFilter) return; foreach (PartInfo subRel in pf.SortRelatedParts(rel.GetRelatedObjects())) { ProcessPart(subRel, m_inputPackage, m_outputPackage, action); } }
private OPCPackage SetupOutput(OPCPackage inputPackager) { if (m_outputStream == null) throw new InvalidOperationException(); return new OPCPackage(m_outputStream, inputPackager.GetDefaultTypes(), m_openXmlFormat); }