Exemplo n.º 1
0
 private static void SetHeaderFooterDocuments(PdfDocumentContext documentContext, OpenXmlPart openXmlPart)
 {
     documentContext.RelatedDocuments = openXmlPart.Parts
                                        .Where(pair => pair.OpenXmlPart.RelationshipType == Constants.HeaderPartRelationType ||
                                               pair.OpenXmlPart.RelationshipType == Constants.FooterPartRelationType)
                                        .ToDictionary(pair => pair.RelationshipId, pair => InterpretDocument(pair.OpenXmlPart, documentContext).Document);
 }
Exemplo n.º 2
0
        private static void SetStyles(PdfDocumentContext documentContext, OpenXmlPart openXmlPart)
        {
            var stylesPart = openXmlPart.GetPartsOfType <StylesPart>().First();

            documentContext.Styles = stylesPart.Styles.ChildElements
                                     .OfType <Style>()
                                     .Where(s => s.Type.Value == StyleValues.Paragraph)
                                     .ToDictionary(s => s.StyleId.Value, s => s);
        }
Exemplo n.º 3
0
        private static PdfRendererVisitor InterpretDocument(OpenXmlPart openXmlPart, PdfDocumentContext documentContext,
                                                            object model = null)
        {
            var interpreterContext = new InterpreterContext();
            var visitor            = new PdfRendererVisitor(interpreterContext, documentContext, model);
            var pdfInterpreter     = new PdfRendererInterpreter(interpreterContext, visitor);

            documentContext.Images = GetImages(openXmlPart);
            pdfInterpreter.Interpret(openXmlPart.RootElement);
            return(visitor);
        }
Exemplo n.º 4
0
        public static void Main()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var testModel = new TestModel
            {
                DimaA = "Hello by a",
                DimaB = "Hello _and_ a",
                DimaC = "Hello to YOU"
            };

            using (var inputDocument = WordprocessingDocument.Open("Simplest.docx", false))
            {
                var documentContext = new PdfDocumentContext
                {
                    TopMargin    = 120,
                    BottomMargin = 100
                };
                SetStyles(documentContext, inputDocument.MainDocumentPart);
                SetHeaderFooterDocuments(documentContext, inputDocument.MainDocumentPart);
                var mainVisitor = InterpretDocument(inputDocument.MainDocumentPart, documentContext, testModel);
                File.WriteAllBytes("result.pdf", mainVisitor.ToPdf());
            }
        }
Exemplo n.º 5
0
 public PdfRendererVisitor(InterpreterContext context, PdfDocumentContext documentContext, object model = null)
     : base(context, model)
 {
     _documentContext = documentContext;
     _document        = new PdfDocument();
 }