itextsharp 5 writer.DirectContent creates 50% smaller file than PDFStamper - c#

I would really like to use the newer approach of using PDFStamper instead of using the older approach of (PdfWriter.GetInstance... writer.DirectContent) but the PDF file created using the older method is 1/2 the size then using the newer approach. Is there something I am missing between the two approaches?
//Old way using PdfWriter.GetInstance... writer.DirectContent
public static void AddHeaderTextLayer()
{
string HdrLeft = string.Empty;
string HdrRight = string.Empty;
string PageHdrName = "XHdr";
string NoOfPagesPadded = string.Empty;
string PageNoPadded = string.Empty;
int xLeft = 30;
int xRight = 100;
int xTop = 15;
string filename = "4_20140909.pdf";
PdfReader reader = new PdfReader(#"C:\!stuff\Junk\ChemWatchPDF\" + filename); // input file
using (var fileStream = new FileStream(#"C:\!stuff\Junk\ChemWatchPDF\" + filename.Replace(".pdf", "") + "_withHdrLTp.pdf", FileMode.Create, FileAccess.Write))
{
var document = new Document(reader.GetPageSizeWithRotation(1));
var writer = PdfWriter.GetInstance(document, fileStream);
document.Open();
for (var i = 1; i <= reader.NumberOfPages; i++)
{
Rectangle pageRect = reader.GetPageSize(i);
document.NewPage();
var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
var importedPage = writer.GetImportedPage(reader, i);
var contentByte = writer.DirectContent;
contentByte.AddTemplate(importedPage, 0, 0);
string SDSNo = "12345678";
HdrLeft = $"Company MSDS# {SDSNo}";
NoOfPagesPadded = (reader.NumberOfPages.ToString());
PageNoPadded = i.ToString();
HdrRight = $" Page {PageNoPadded} of {NoOfPagesPadded}";
contentByte.BeginLayer(new PdfLayer(PageHdrName + i.ToString(), writer));
contentByte.BeginText();
contentByte.SetFontAndSize(baseFont, 10);
contentByte.SetColorFill(LabColor.RED);
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, HdrLeft, pageRect.Left + xLeft, pageRect.Top - xTop, 0);
contentByte.EndText();
contentByte.BeginText();
contentByte.SetFontAndSize(baseFont, 10);
contentByte.SetColorFill(LabColor.RED);
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, HdrRight, pageRect.Right - xRight, pageRect.Top - xTop, 0);
contentByte.EndText();
contentByte.EndLayer();
}
document.Close();
writer.Close();
}
}
// New way using PDFStamper
public void Add()
{
BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, false);
string outPutFile = string.Empty;
var SingleLine = string.Empty;
string HdrLeft = string.Empty;
string HdrRight = string.Empty;
string PageHdrName = "xHdr";
string NoOfPagesPadded = string.Empty;
string PageNoPadded = string.Empty;
int xLeft = 30;
int xRight = 100;
int xTop = 15;
string filename = "4_20140909.pdf";
outPutFile = #"C:\!stuff\Junk\ChemWatchPDF\" + filename.Replace(".pdf", "") + "_withHdrLTStamp.pdf";
using (var newPDF = new FileStream(outPutFile, FileMode.Create, FileAccess.ReadWrite))
{
PdfReader reader = new PdfReader(#"C:\!stuff\Junk\ChemWatchPDF\" + filename); // input file
PdfStamper pdfStamper = new PdfStamper(reader, newPDF);
PdfLayer wmLayer = new PdfLayer(PageHdrName, pdfStamper.Writer);
for (int page = 1; page <= reader.NumberOfPages; page++)
{
PdfContentByte pdfContent = pdfStamper.GetOverContent(page);
Rectangle pageRect = reader.GetPageSize(page);
string SDSNo = "12345678";
HdrLeft = $"Company MSDS# {SDSNo}";
NoOfPagesPadded = (reader.NumberOfPages.ToString());
PageNoPadded = page.ToString();
HdrRight = $"Page {PageNoPadded} of {NoOfPagesPadded}";
pdfContent.BeginLayer(wmLayer);
pdfContent.BeginText();
pdfContent.SetFontAndSize(baseFont, 10);
pdfContent.SetColorFill(LabColor.RED);
pdfContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, HdrLeft, pageRect.Left + xLeft, pageRect.Top - xTop, 0);
pdfContent.EndText();
pdfContent.BeginText();
pdfContent.SetFontAndSize(baseFont, 10);
pdfContent.SetColorFill(LabColor.RED);
pdfContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, HdrRight, pageRect.Right - xRight, pageRect.Top - xTop, 0);
pdfContent.EndText();
pdfContent.EndLayer();
}
pdfStamper.Close();
}
}
}
}

Your stamped copy (the output of the "newer approach") contains a structure tree which I assume to come from the original document. It is lost in the output of the "old approach".
The structure tree describes the logical structure of the document. It increases the accessibility of the document and its presence becomes a legal requirement in more and more countries and contexts. Thus, throwing away the structure tree in general is a bad idea.
The structure tree itself consists of very many small indirect objects, in case of your PDF there are more than 1000 indirect objects approximately 90KB in size altogether. Furthermore, each indirect object requires a 20 byte cross reference entry which sums up to nearly 20KB in your case. This explains nearly all of the 111KB difference in size between the two outputs.
If you make use of object streams and cross reference streams, the structure tree can usually be fairly well compressed. Thus, I would propose you activate full compression in iText which makes it use object streams and cross reference streams:
PdfStamper pdfStamper = new PdfStamper(reader, newPDF);
pdfStamper.SetFullCompression();
pdfStamper.Writer.CompressionLevel = 9;
By simply processing your large PDF by a PdfReader/PdfStamper couple with these settings without any other manipulations, I reduced the size of your file from 234KB down to 133KB.
By the way, you call the approach with the PdfWriter and page imports the "old way" and the approach with the PdfStamper the "new way". Actually the PdfStamper class exists in iText at least since 2003! So it's not really old vs. new...

Related

Performance issue when using old iText for .NET version when splitting a huge PDF

My goal here is to split a huge PDF (over 1000 pages).
I tried the example below :
public void ExtractPages(string sourcePdfPath, string outputPdfPath,
int startPage, int endPage)
{
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage = null;
try
{
// Intialize a new PdfReader instance with the contents of the source Pdf file:
reader = new PdfReader(sourcePdfPath);
// For simplicity, I am assuming all the pages share the same size
// and rotation as the first page:
sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage));
// Initialize an instance of the PdfCopyClass with the source
// document and an output file stream:
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
sourceDocument.Open();
// Walk the specified range and add the page copies to the output file:
for (int i = startPage; i <= endPage; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
sourceDocument.Close();
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
It works but it takes more than 10 min.
My question here is there any way to skip the for loop and getting all the pages quickly ??

The process cannot access the file '...' because it is being used by another process

I have a code to delete file in my folder, but in my line code, I want to delete two file together with different folder. But I always get an error "the process cannot access.... another process". May be you can correct my code and give me a solution. Thanks
1) I have a code to generate watermark when save file(.pdf):
public bool InsertWaterMark(string path)
{
bool valid = true;
string FileDestination = AppDomain.CurrentDomain.BaseDirectory + "Content/" + path;
string FileOriginal = AppDomain.CurrentDomain.BaseDirectory + "Content/" + path.Replace("FileTemporary", "FileOriginal");
System.IO.File.Copy(FileDestination, FileOriginal);
string watermarkText = "Controlled Copy";
#region process
PdfReader reader1 = new PdfReader(FileOriginal);//startFile
using (FileStream fs = new FileStream(FileDestination, FileMode.Create, FileAccess.Write, FileShare.None))//watermarkedFile
{
using (PdfStamper stamper = new PdfStamper(reader1, fs))
{
int pageCount1 = reader1.NumberOfPages;
PdfLayer layer = new PdfLayer("WatermarkLayer", stamper.Writer);
for (int i = 1; i <= pageCount1; i++)
{
iTextSharp.text.Rectangle rect = reader1.GetPageSize(i);
PdfContentByte cb = stamper.GetUnderContent(i);
cb.BeginLayer(layer);
cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 80);
PdfGState gState = new PdfGState();
gState.FillOpacity = 0.15f;
cb.SetGState(gState);
cb.SetColorFill(BaseColor.GRAY);
cb.BeginText();
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, watermarkText, rect.Width / 2, rect.Height / 2, 45f);
cb.EndText();
PdfContentByte canvas = stamper.GetUnderContent(i);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
canvas.SetColorFill(BaseColor.RED);
PdfGState gStateFooter = new PdfGState();
gStateFooter.FillOpacity = 1f;
canvas.SetGState(gStateFooter);
canvas.BeginText();
canvas.SetFontAndSize(bf, 12);
canvas.ShowTextAligned(PdfContentByte.ALIGN_CENTER, '"' + "When printed, this documents are considered uncontrolled" + '"', 300.7f, 10.7f, 0);
canvas.EndText();
cb.EndLayer();
}
}
}
#endregion
return valid;
}
2) And this code i call when delete detail data from one page together.
public ActionResult Delete(string parm)
{
TableEDIS data = db.TableEDISs.FirstOrDefault(e => e.detail_guid_edis == new Guid(parm));
string fisikFile = data.upload_document;
string fisikFileFormulir = data.upload_document_formulir;
if (!string.IsNullOrEmpty(fisikFile))
{
var relativePath = "~/Content/" + fisikFile;
var absolutePath = HttpContext.Server.MapPath(relativePath);
var absolutePathOriginal = HttpContext.Server.MapPath(relativePath.Replace("Temporary", "Original"));
if (Directory.Exists(Path.GetDirectoryName(absolutePath)))
{
System.IO.File.Delete(absolutePath);
}
if (Directory.Exists(Path.GetDirectoryName(absolutePathOriginal)))
{
System.IO.File.Delete(absolutePathOriginal);
}
}
}
I hope you understand what I mean.
Thanks in advance.
My spidey senses tells me you need to call
reader1.Close();

How to import a 3D object from one PDF to another using iTextSharp

I'm using iTextSharp 5.5 to construct PDF documents. The documents start with text information and end with imported JPEG images and multi-page PDF files. Some of the PDFs contain annotations, specifically 3D models.
Edit (3/21/2014): Here is a complete, simplified example that illustrates what I'm trying to accomplish, and where the error occurs in AddPdf().
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace PdfTest
{
class Program
{
private const string path = "w:\\tmp\\pdf";
static void Main(string[] args)
{
using (var ms = new MemoryStream())
{
var document = new Document(PageSize.LETTER, 40, 40, 30, 30);
var writer = PdfWriter.GetInstance(document, ms); // Without this, I get a zero-length file
document.Open();
AddText(document, "TEST");
AddImage(document, Path.Combine(path, "import1.jpg"));
AddPdf(document, ms, Path.Combine(path, "import2.pdf"));
document.Close();
File.WriteAllBytes(Path.Combine(path, "test.pdf"), ms.ToArray());
}
}
private static void AddText(Document document, string text)
{
document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12f)));
}
private static void AddImage(Document document, string sourcePath)
{
var pic = Image.GetInstance(sourcePath);
var maxWidth = document.PageSize.Width - 72f;
var maxHeight = document.PageSize.Height - 150f;
if (pic.Width > maxWidth || pic.Height > maxHeight)
{
pic.ScaleToFit(maxWidth, maxHeight);
}
document.NewPage();
document.Add(pic);
}
private static void AddPdf(Document document, Stream stream, string sourcePath)
{
var copy = new PdfCopy(document, stream);
// Read the source PDF
var reader = new PdfReader(sourcePath);
var pageCount = reader.NumberOfPages;
// Import each page
for (var i = 0; i < pageCount; i++)
{
var pageNum = i + 1;
document.SetPageSize(reader.GetPageSizeWithRotation(pageNum));
document.NewPage(); // <--- "Document is not open" error here
var page = copy.GetImportedPage(reader, pageNum);
copy.AddPage(page);
}
}
}
}
What is the correct way to construct a document by adding elements and imported pages?

search PDF text, highlight found words by drawing rectangle after getting their coordinates save PDF with text highlighted

Anyone can help with how to get a text coordinates? can this be possible? because I just wanted a windows form app where the user types a word in a text box, and the app reads existing PDF using iTextSharp, highlights the matched words if found, and saves the PDF with highlighted text. so far i have almost everything done, including the drawing of a yellow rectangle, but what is lacking is how to get the text coordinates of the matched patterns to highlight them, thanks in advance: (by the way: sb is the search text box, tb is a rich text box where the PDF text is exhibited)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iTextSharp.text;
using System.Text.RegularExpressions;
namespace manipulatePDF
{
public partial class Form1 : Form
{
string oldFile;
Document document = new Document();
StringBuilder text = new StringBuilder();
public Form1()
{
InitializeComponent();
}
private void open_Click(object sender, EventArgs e)
{
reset_Click(sender, e);
openFileDialog1.Filter = "PDF Files (.pdf)|*.pdf";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
label1.Text = "File Location: " + openFileDialog1.FileName;
oldFile = openFileDialog1.FileName;
// open the reader
PdfReader reader = new PdfReader(oldFile);
iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(1);
document.SetPageSize(size);
for (int cPage = 1; cPage <= reader.NumberOfPages; cPage++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(reader, cPage, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
text.Append(currentText);
reader.Close();
}
tb.Text = text.ToString();
}
}
private void save_Click(object sender, EventArgs e)
{
saveFileDialog1.InitialDirectory = "C: ";
saveFileDialog1.Title = "Save the PDF File";
saveFileDialog1.Filter = "PDF files (*.pdf)|*.pdf";
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
PdfReader reader = new PdfReader(oldFile);
string newFile = saveFileDialog1.FileName;
// open the writer
FileStream fs = new FileStream(newFile, FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
// the pdf content
PdfContentByte cb = writer.DirectContent;
// select the font properties
PdfGState graphicsState = new PdfGState();
graphicsState.FillOpacity = 10;
cb.SetGState(graphicsState);
int index = 0;
while (index < text.ToString().LastIndexOf(sb.Text))
{
if (contain.Checked == true)
{
tb.Find(sb.Text, index, tb.TextLength, RichTextBoxFinds.MatchCase);
tb.SelectionBackColor = Color.Gold;
index = tb.Text.IndexOf(sb.Text, index) + 1;
}
else if (exact.Checked == true)
{
tb.Find(sb.Text, index, tb.TextLength, RichTextBoxFinds.WholeWord);
tb.SelectionBackColor = Color.Gold;
index = tb.Text.IndexOf(sb.Text, index) + 1;
}
}
int count = 0; //counts the pattern occurance
for (int cPage = 1; cPage <= reader.NumberOfPages; cPage++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(reader, cPage, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
string textToSearch = sb.Text;
int lastStartIndex = currentText.IndexOf(textToSearch, 0, StringComparison.CurrentCulture);
while (lastStartIndex != -1)//if the pattern was found
{
count++;
lastStartIndex = currentText.IndexOf(textToSearch, lastStartIndex + 1, StringComparison.CurrentCulture);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetFontAndSize(bf, 10);
cb.SetColorFill(new CMYKColor(0f, 0f, 1f, 0f));
cb.Rectangle(document.PageSize.Width - 500f, 600f, 100f, 100f);
cb.Fill();
}
if (count != 0)
{
if (contain.Checked == true)
{
label2.Text = "Number of pages: " + cPage + " - " + textToSearch + " found " + count + " times. \n";
}
else if (exact.Checked == true)
{
//finds the words that are bounded by a space or a dot and store in cCount
//returns the count of matched pattern = count - cCount
}
}
text.Append(currentText);
// create the new page and add it to the pdf
PdfImportedPage page = writer.GetImportedPage(reader, cPage);
cb.AddTemplate(page, 0, 0);
document.NewPage();
//PdfStamper stamper = new PdfStamper(reader, fs);
////Create a rectangle for the highlight. NOTE: Technically this isn't used but it helps with the quadpoint calculation
//iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(60.6755f, 749.172f, 94.0195f, 735.3f);
////Create an array of quad points based on that rectangle. NOTE: The order below doesn't appear to match the actual spec but is what Acrobat produces
//float[] quad = { rect.Left, rect.Bottom, rect.Right, rect.Bottom, rect.Left, rect.Top, rect.Right, rect.Top };
////Create our hightlight
//PdfAnnotation highlight = PdfAnnotation.CreateMarkup(stamper.Writer, rect, null, PdfAnnotation.MARKUP_HIGHLIGHT, quad);
////Set the color
//highlight.Color = BaseColor.YELLOW;
////Add the annotation
//stamper.AddAnnotation(highlight, 1);
}
// close the streams
document.Close();
fs.Close();
writer.Close();
reader.Close();
}
}
private void reset_Click(object sender, EventArgs e)
{
tb.Text = "";
}
}
Well, i had added a downloable example made using Vb.NET 2010 that does exactly what you need, and it's available in another post in the same thread Chris referenced. That code will work for every font type, font size and will return all matches for the word/sentence you search for, returning each match as a rectangle with x/y locations to the UI, and finally hightlighting them all and saving to a new PDF, you just need to give some initial parameters like, search term, comparison type by culture, source PDF path and destination PDF Path. The only thing not implemented is that particular case when the search word/sentence falls into multiple lines, but it should be an easy change in code since you can use SameLine() method in TextChunk Class.

Images are not coming after creating word Document through Open XML

I am Creating a word document through the c# with the use of OpenXMl sdk.
I am converting all my html page to word document but while converting i am giving a absolute address for my images and after converting it is coming perfectly in my system but when i am trying to take this document to other system the Images are Not Coming there.
I checked the media Directory all images are there but with different Name.
my document is converted but I am Using this mathod.
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(documentPath, true))
{
XNamespace w =
"http://schemas.openxmlformats.org/wordprocessingml/2006/main";
XNamespace r =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships";
string altChunkId = "AltChunkId1";
MainDocumentPart mainPart = myDoc.MainDocumentPart;
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart("application/xhtml+xml", altChunkId);
using (Stream chunkStream = chunk.GetStream(FileMode.Create, FileAccess.Write))
using (StreamWriter stringStream = new StreamWriter(chunkStream))
stringStream.Write(html);
XElement altChunk = new XElement(w + "altChunk",
new XAttribute(r + "id", altChunkId)
);
XDocument mainDocumentXDoc = GetXDocument(myDoc);
mainDocumentXDoc.Root
.Element(w + "body")
.Elements(w + "p")
.Last()
.AddAfterSelf(altChunk);
SaveXDocument(myDoc, mainDocumentXDoc);
}
private static XDocument GetXDocument(WordprocessingDocument myDoc)
{
// Load the main document part into an XDocument
XDocument mainDocumentXDoc;
using (Stream str = myDoc.MainDocumentPart.GetStream())
using (XmlReader xr = XmlReader.Create(str))
mainDocumentXDoc = XDocument.Load(xr);
return mainDocumentXDoc;
}
private static void SaveXDocument(WordprocessingDocument myDoc,
XDocument mainDocumentXDoc)
{
// Serialize the XDocument back into the part
using (Stream str = myDoc.MainDocumentPart.GetStream(
FileMode.Create, FileAccess.Write))
using (XmlWriter xw = XmlWriter.Create(str))
mainDocumentXDoc.Save(xw);
}
and this will generate a afchunk.dat file which is showing in the content and the Absolute path.
Basically i doesn't want to create a file through all coding i just want to convert the .html to .docx file .
so can any one tell me how can i convert without getting error in html.
Is there a reason you aren't embedding the images? Here's a link with sample code to show you how.
http://msdn.microsoft.com/en-us/library/bb497430.aspx
Try to create a DocumentResource (Item->Add new) and associate the images there.
Call the Document
using (Stream imgStream = ip.GetStream())
{
System.Drawing.Bitmap logo = DocumentResources._default;
logo.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Drawing drawing = BuildImage(imageRelationshipID, "_default.jpg", 200, 30);
And create the method to build image in the header or footer;
private static Drawing BuildImage(string imageRelationshipID, string imageName, int pixelWidth, int pixelHeight)
{
int emuWidth = (int)(pixelWidth * EMU_PER_PIXEL);
int emuHeight = (int)(pixelHeight * EMU_PER_PIXEL);
Drawing drawing = new Drawing();
d.Wordprocessing.Inline inline = new d.Wordprocessing.Inline { DistanceFromTop = 0, DistanceFromBottom = 0, DistanceFromLeft = 0, DistanceFromRight = 0 };
d.Wordprocessing.Anchor anchor = new d.Wordprocessing.Anchor();
d.Wordprocessing.SimplePosition simplePos = new d.Wordprocessing.SimplePosition { X = 0, Y = 0 };
d.Wordprocessing.Extent extent = new d.Wordprocessing.Extent { Cx = emuWidth, Cy = emuHeight };
d.Wordprocessing.DocProperties docPr = new d.Wordprocessing.DocProperties { Id = 1, Name = imageName };
d.Graphic graphic = new d.Graphic();
d.GraphicData graphicData = new d.GraphicData { Uri = GRAPHIC_DATA_URI };
d.Pictures.Picture pic = new d.Pictures.Picture();
d.Pictures.NonVisualPictureProperties nvPicPr = new d.Pictures.NonVisualPictureProperties();
d.Pictures.NonVisualDrawingProperties cNvPr = new d.Pictures.NonVisualDrawingProperties { Id = 2, Name = imageName };
d.Pictures.NonVisualPictureDrawingProperties cNvPicPr = new d.Pictures.NonVisualPictureDrawingProperties();
d.Pictures.BlipFill blipFill = new d.Pictures.BlipFill();
d.Blip blip = new d.Blip { Embed = imageRelationshipID };
d.Stretch stretch = new d.Stretch();
d.FillRectangle fillRect = new d.FillRectangle();
d.Pictures.ShapeProperties spPr = new d.Pictures.ShapeProperties();
d.Transform2D xfrm = new d.Transform2D();
d.Offset off = new d.Offset { X = 0, Y = 0 };
d.Extents ext = new d.Extents { Cx = emuWidth, Cy = emuHeight };
d.PresetGeometry prstGeom = new d.PresetGeometry { Preset = d.ShapeTypeValues.Rectangle };
d.AdjustValueList avLst = new d.AdjustValueList();
xfrm.Append(off);
xfrm.Append(ext);
prstGeom.Append(avLst);
stretch.Append(fillRect);
spPr.Append(xfrm);
spPr.Append(prstGeom);
blipFill.Append(blip);
blipFill.Append(stretch);
nvPicPr.Append(cNvPr);
nvPicPr.Append(cNvPicPr);
pic.Append(nvPicPr);
pic.Append(blipFill);
pic.Append(spPr);
graphicData.Append(pic);
graphic.Append(graphicData);
inline.Append(extent);
inline.Append(docPr);
inline.Append(graphic);
drawing.Append(inline);
return drawing;
}

Categories