Footer not rendering when converting HTML to PDF - c#

I'm using TuesPechkin to convert HTML to PDF and I'm specifying the URL of an HTML file that should appear as the footer on each page, however it doesn't render the footer. As a test, I even tried setting the LeftText to something and that doesn't render either.
My code is as below:
Dim FooterURL As String = "http://localhost:60699/testfooter.html"
Dim globalSettings As New TuesPechkin.GlobalSettings With {.PaperSize = PaperKind.A4,
.DocumentTitle = DocTitle,
.Margins = New TuesPechkin.MarginSettings With {.Unit = TuesPechkin.Unit.Millimeters, .Bottom = 20, .Left = 20, .Right = 20, .Top = 20},
.Copies = 1,
.ImageQuality = 100,
.ImageDPI = 300,
.ProduceOutline = True,
.PageOffset = 0,
.DPI = 1200,
.Orientation = TuesPechkin.GlobalSettings.PaperOrientation.Portrait}
Dim pdfdoc As New TuesPechkin.HtmlToPdfDocument
pdfdoc.Objects.Add(New TuesPechkin.ObjectSettings With {.HtmlText = strHTML,
.FooterSettings = New TuesPechkin.FooterSettings With {.HtmlUrl = FooterURL, .LeftText = "blah blah blah"},
.WebSettings = New TuesPechkin.WebSettings With {.LoadImages = True,
.PrintBackground = True,
.EnableJavascript = False}
})
Dim convertor As TuesPechkin.IPechkin = TuesPechkin.Factory.Create
Dim buf As Byte() = convertor.Convert(strHTML)
Return buf

This problem has been fixed in version 1.1.0, which has not been released yet.
See https://github.com/tuespetre/TuesPechkin/issues/46
You can pull the source from GitHub and build the current code yourself to fix your issue.
Edit: Should be fixed now, as of version 2.0.0.
https://github.com/tuespetre/TuesPechkin/releases

Related

c# DinkToPdf - wkhtmltopdf generate incorrect layout from html

I try convert html to PDF by following code but output PDF is not correct layout as HTML page:
var pdf = new HtmlToPdfDocument()
{
GlobalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 12, Left = 12, Right = 12, Bottom = 12 },
DocumentTitle = "",
Out = filenames
},
Objects = { new ObjectSettings
{
PagesCount = true,
HtmlContent = html,
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { FontName = "Arial", FontSize = 8, Left = $"PTT Group Ship Vetting - {id}", Right = "Page [page] of [toPage]", Line = false },
} }
};
var converter = new SynchronizedConverter(new PdfTools());
byte[] pdfByte = converter.Convert(pdf);
this is HTML input
This is PDF output

NoTextEdit ShapeLock is not working - OpenXML SDK

I am trying to make a TextBox locked by using OpenXML SDK. I've tried this method but the TextBox NoTextEdit is not working.
public DocumentFormat.OpenXml.Presentation.Shape GenerateShape(string StrText)
{
DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape();
DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "ID",Hidden=true ,Description="Do not Remove" ,MCAttributes=null };
DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
Drawing.ShapeLocks shapeLocks1 = new Drawing.ShapeLocks() { NoTextEdit = true, NoGrouping = true,NoMove=true,NoSelection=true,NoEditPoints=true ,NoAdjustHandles=true ,NoRotation=true,NoChangeArrowheads=true,NoChangeAspect=true,NoChangeShapeType=true,NoResize=true};
nonVisualShapeDrawingProperties1.Append(shapeLocks1);
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.SubTitle, Index = (UInt32Value)1U };
applicationNonVisualDrawingProperties1.Append(placeholderShape1);
nonVisualShapeProperties1.Append(nonVisualDrawingProperties1);
nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1);
nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1);
DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody();
Drawing.BodyProperties bodyProperties1 = new Drawing.BodyProperties();
Drawing.ListStyle listStyle1 = new Drawing.ListStyle();
Drawing.TextShape shp = new Drawing.TextShape();
Drawing.Paragraph paragraph1 = new Drawing.Paragraph();
Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new Drawing.EndParagraphRunProperties() { Language = "en-US" ,Dirty=false };
paragraph1.Append(GenerateRun(StrText));
paragraph1.Append(endParagraphRunProperties1);
textBody1.Append(bodyProperties1);
textBody1.Append(listStyle1);
textBody1.Append(paragraph1);
shape1.Append(nonVisualShapeProperties1);
shape1.Append(shapeProperties1);
shape1.Append(textBody1);
return shape1;
}
public Drawing.Run GenerateRun(string StrText)
{
Drawing.Run run1 = new Drawing.Run();
Drawing.RunProperties runProperties1 = new Drawing.RunProperties() { Language = "en-US", Dirty = false };
runProperties1.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
Drawing.Text text1 = new Drawing.Text();
text1.Text = StrText;
Drawing.SolidFill solidFill2 = new Drawing.SolidFill();
Drawing.SchemeColor schemeColor = new Drawing.SchemeColor();
string y = System.Drawing.Color.Transparent.ToArgb().ToString("X");
Drawing.RgbColorModelHex rgbColorModelHex2 = new Drawing.RgbColorModelHex() { Val = "FFFFFF" };//Set Font-Color to Blue (Hex "0070C0").
solidFill2.Append(rgbColorModelHex2);
runProperties1.Append(solidFill2);
Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
run1.Append(runProperties1);
run1.Append(text1);
return run1;
}
Everything works fine except editing. Still the user can edit the TextBox values by double clicking it. How can I avoid this ?
Is there any permanent solution to prevent editing ? Please help me to find a better solution.
Thanks in advance
By researching and communications with the MVP team I've pointed out that there is no way to Protect the TextBox from editing.
As Cindy Meister mentioned in the comments,
Are you able to do it in the PowerPoint application user interface? If not, then Open XML cannot do it... If yes, you can.
If you do not want to text to be changed , Just change it as image then lock that by using NoSelection=true/1 and NoMove=true/1 properties. If you enable these properties the user can't either delete nor change it's position.
For your ref: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_windows8-mso_2016/shape-lock-is-not-working/c1705b55-d2aa-4adb-b538-574ed2fc8eca?tm=1579265435636&page=1&rtAction=1579495439869

I am trying to insert hyperlink to another website in pdf

In FormField "HH" i am trying to make text as link, but it is readed only as string text, it is not clickable.
I use Aspose.Pdf v.11.6.0.
var doc = new Aspose.Pdf.Document(pdfFileStream);
var pdfForm = new Aspose.Pdf.Facades.Form(doc);
pdfForm.FillField("Name", model.Name.ToUpper());
pdfForm.FillField("ISOS", model.NumberISOS.ToUpper());
pdfForm.FillField("Info", dateInfo);
pdfForm.FillField("HH", "http://www.somewebsite.com");
I use this code:
Page page = (Page)doc.Pages[1];
var text = new TextFragment("index");
text.Position = new Position(200, 300);
Aspose.Pdf.WebHyperlink link = new
WebHyperlink("www.google.com");
text.Hyperlink = link;
page.Paragraphs.Add(text);
but new Position(200, 300); values not responding.
Here is my solution, because position does not work, i move the link with margins. This worked for me.
Page page = (Page)doc.Pages[1];
var text = new TextFragment("LINK");
text.Position = new Position(300, 300);
Aspose.Pdf.WebHyperlink link = new WebHyperlink("www.google.com");
text.Hyperlink = link;
text.Margin.Left = -48;
text.Margin.Top = 687;
text.Margin.Bottom = -150;
text.TextState.Underline = true;
text.TextState.FontSize = 11;
text.TextState.ForegroundColor = Aspose.Pdf.Color.DeepSkyBlue;
text.TextState.BackgroundColor = Aspose.Pdf.Color.White;
page.Paragraphs.Add(text);

Adding picture and comment to cell causes issue

I am using the following code to add a comment :
ws.Cell("A5").Comment.SetVisible().AddText("sample");
ws.PageSetup.SetShowComments(XLShowCommentsValues.AsDisplayed);
When I comment out the following code, which adds an image to the excel document, then the comment works. But with this code uncommented, the below error occurs:
XLPicture pic = new XLPicture
{
NoChangeAspect = true,
NoMove = true,
NoResize = true,
ImageStream = memo,
Name = "Export Image",
PaddingX = 12,
PaddingY = 18
};
XLMarker fMark = new XLMarker { ColumnId = 1, RowId = 1 };
pic.AddMarker(fMark);
workSheet.AddPicture(pic);
Error is :

How to insert new elements into an ssrs rdl object using c# and the rdl object model

I am working on creating an rdl programmatically using the Object model that I have generated from the rdl schema. I start by loading an existing rdl template that contains a header footer and body as well as a datasource and dataset section into a file stream.
string docpath = "RDLTemplates/TemplateLetter.rdl";
Report myReport = null;
using (FileStream fs = new FileStream(docpath, FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(Report));
myReport = (Report)serializer.Deserialize(fs);
}
return myReport;
I then pass this to an InsertTablix() method where I navigate through the stream to locate the body section
public Report InsertTablix(Report report, List<string> fieldnames)
{
int sectionindex = report.ItemsElementName.ToList().IndexOf(ItemsChoiceType118.ReportSections);
if (sectionindex != -1)
{
ReportSectionsType sections = (ReportSectionsType)report.Items[sectionindex];
if (sections.ReportSection.Length > 0)
{
int bodyIndex = sections.ReportSection[0].ItemsElementName.ToList().IndexOf(ItemsChoiceType117.Body);
if (bodyIndex != -1)
{
BodyType body = (BodyType)sections.ReportSection[0].Items[bodyIndex];
int tablixindex = body.Items.ToList().IndexOf(ItemsChoiceType80.Tablix);
if (tablixindex == -1)
{
//Here is where I would like to insert the tablix if it doesn't exist
}
}
}
}
return report;
}
Where I am stuck is how to go about creating/inserting a tablix into this the body using the object model. I realize I can use XML to create report and I have tried this approach but I wanted to try to use the ObjectModel to help adhere and validate against the report schema.
Can anyone provide some insight into how to add an element (tablix, textbox etc) into the body using this approach.
-cheeers
I am using RDLObjectModel to do the same thing and took a little while to figure out. This is my test code (not very pretty and in VB.NET) that worked to get the tablix inserted properly. Maybe you'll find this useful.
'create tablix - manually
Dim tablixRFoo As New RdlObjectModel.Tablix With {.Top = New RdlObjectModel.ReportSize("0.56875in"), .Width = New RdlObjectModel.ReportSize("0.5in")}
tablixRFoo.Name = "tablix1"
tablixRFoo.DataSetName = dsRFoo.Name
'add tablix columns
tablixRFoo.TablixBody.TablixColumns.Add(New RdlObjectModel.TablixColumn With {.Width = New RdlObjectModel.ReportSize(2.0)})
tablixRFoo.TablixBody.TablixColumns.Add(New RdlObjectModel.TablixColumn With {.Width = New RdlObjectModel.ReportSize(2.0)})
tablixRFoo.TablixBody.TablixColumns.Add(New RdlObjectModel.TablixColumn With {.Width = New RdlObjectModel.ReportSize(2.0)})
tablixRFoo.TablixBody.TablixColumns.Add(New RdlObjectModel.TablixColumn With {.Width = New RdlObjectModel.ReportSize(2.0)})
tablixRFoo.TablixBody.TablixColumns.Add(New RdlObjectModel.TablixColumn With {.Width = New RdlObjectModel.ReportSize(2.0)})
...
Dim tColHeirarcy = New RdlObjectModel.TablixHierarchy
Dim tRowHeirarcy = New RdlObjectModel.TablixHierarchy
...
Dim fields() = {"field1", "field2", "field3", "field4", "field5"}
'add tablix header row
Dim tRowHeader = New RdlObjectModel.TablixRow With {.Height = New RdlObjectModel.ReportSize(0.2)}
For i As Integer = 0 To fields.Length - 1
Dim tCell = New RdlObjectModel.TablixCell
Dim tCellContents = New RdlObjectModel.CellContents
Dim tTextBox As New RdlObjectModel.Textbox
tTextBox.Name = tablixRFoo.Name & "Header" & "txt" & fields(i).ToString.Replace(" ", "")
tTextBox.DefaultName = tTextBox.Name
tTextBox.Paragraphs(0).TextRuns(0).Value = fields(i).ToString
tTextBox.Paragraphs(0).TextRuns(0).Style.FontSize = New RdlObjectModel.ReportSize("8pt")
tTextBox.Paragraphs(0).TextRuns(0).Style.TextAlign = RdlObjectModel.TextAlignments.Left
tTextBox.ZIndex = i
tCellContents.ReportItem = tTextBox
tCell.CellContents = tCellContents
tRowHeader.TablixCells.Add(tCell)
tColHeirarcy.TablixMembers.Add(New RdlObjectModel.TablixMember)
Next
tablixRFoo.TablixBody.TablixRows.Add(tRowHeader)
'add tablix data rows
Dim tRow = New RdlObjectModel.TablixRow With {.Height = New RdlObjectModel.ReportSize(0.2)}
For i As Integer = 0 To fields.Length - 1
Dim tCell = New RdlObjectModel.TablixCell
Dim tCellContents = New RdlObjectModel.CellContents
Dim tTextBox As New RdlObjectModel.Textbox
tTextBox.Name = tablixRFoo.Name & "txt" & fields(i).ToString.Replace(" ", "")
tTextBox.DefaultName = tTextBox.Name
tTextBox.Paragraphs(0).TextRuns(0).Value = "=Fields!" & fields(i).ToString & ".Value"
tTextBox.Paragraphs(0).TextRuns(0).Style.FontSize = New RdlObjectModel.ReportSize("8pt")
tTextBox.Paragraphs(0).TextRuns(0).Style.TextAlign = RdlObjectModel.TextAlignments.Left
tTextBox.ZIndex = i
tCellContents.ReportItem = tTextBox
tCell.CellContents = tCellContents
tRow.TablixCells.Add(tCell)
Next
tablixRFoo.TablixBody.TablixRows.Add(tRow)
Dim rMem = New RdlObjectModel.TablixMember With {.KeepTogether = True}
Dim rMem2 = New RdlObjectModel.TablixMember With {.Group = New RdlObjectModel.Group With {.Name = "Details"}}
tRowHeirarcy.TablixMembers.Add(rMem)
tRowHeirarcy.TablixMembers.Add(rMem2)
tablixRFoo.Style = New RdlObjectModel.Style With {.Border = New RdlObjectModel.Border}
'add tablix to report
tablixRFoo.TablixColumnHierarchy = tColHeirarcy
tablixRFoo.TablixRowHierarchy = tRowHeirarcy
rdlRpt.Body.ReportItems.Add(tablixRFoo)

Categories